Using CMake build system
-
Hi all,
Have you used CMake instead of qmake in your Qt Widgets projects, please?
For me, it's the first time and want to make use of Docs (https://doc.qt.io/qt-5/cmake-get-started.html) for that, but it's ambiguous as usual (mostly).
I did these:
Created a Qt project called CMTest inheriting QLabel as the base class and without a .ui file and selecting CMake as the build system.
It now looks like this:Then Docs say:
For find_package to be successful, CMake must find the Qt installation in one of the following ways:
Set your CMAKE_PREFIX_PATH environment variable to the Qt 5 installation prefix. This is the recommended way.But I can't find CMAKE_PREFIX_PATH environment variable in the Projects > Build Environment list (Details)!
-
@tomy said in Using CMake build system:
But I can't find CMAKE_PREFIX_PATH environment variable in the Projects > Build Environment list (Details)!
You can always add variables there...
-
I did that this way, if it's correct:
And this is my CMake text file contents:
cmake_minimum_required(VERSION 3.5) project(CMTest LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) # QtCreator supports the following variables for Android, which are identical to qmake Android variables. # Check http://doc.qt.io/qt-5/deployment-android.html for more information. # They need to be set before the find_package(Qt5 ...) call. #if(ANDROID) # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") # if (ANDROID_ABI STREQUAL "armeabi-v7a") # set(ANDROID_EXTRA_LIBS # ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so # ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so) # endif() #endif() find_package(Qt5 COMPONENTS Widgets REQUIRED) if(ANDROID) add_library(CMTest SHARED main.cpp cmtest.cpp cmtest.h ) else() add_executable(CMTest main.cpp cmtest.cpp cmtest.h ) endif() target_link_libraries(CMTest PRIVATE Qt5::Widgets)
When I run CMake, these error emerge:
I'm confused and don't know what to do next! :(
-
@tomy You set wrong path. Take a look at https://stackoverflow.com/questions/22215900/add-the-installation-prefix-of-qt5widgets-to-cmake-prefix-path
Also, as you can see Ninja was not found. If you do not have it then set Make as build tool. -
I've Ninja at: "C:\Qt\Tools\Ninja"
So added the following two linesset(CMAKE_PREFIX_PATH "C:\\Qt\\5.14.2\\mingw73_64\\bin\\") set(CMAKE_MAKE_PROGRAM "C:\\Qt\\Tools\\Ninja\\")
after:
cmake_minimum_required(VERSION 3.5) project(CMTest LANGUAGES CXX)
in CMakeLists.txt file
As well as, changed the CMAKE_PREFIX_PATH on Build Environment to C:\Qt\5.14.2\mingw73_64\bin.
Still the same errors! Why are the stuff that complicated?! :(
-
@tomy said in Using CMake build system:
CMAKE_MAKE_PROGRAM
This needs to point to the executable, not a directory! So, whole path to ninja.exe.
"set(CMAKE_PREFIX_PATH "C:\Qt\5.14.2\mingw73_64\bin\")" - this needs to be
set(CMAKE_PREFIX_PATH "C:\\Qt\\5.14.2\\mingw73_64")
-
Did these both:
set(CMAKE_PREFIX_PATH "C:\\Qt\\5.14.2\\mingw73_64") set(CMAKE_MAKE_PROGRAM "C:\\Qt\\Tools\\Ninja\\ninja.exe")
And:
Still both prior errors exist!
This is my CMakeLists.txt file contents:
cmake_minimum_required(VERSION 3.5) project(CMTest LANGUAGES CXX) set(CMAKE_PREFIX_PATH "C:\\Qt\\5.14.2\\mingw73_64") set(CMAKE_MAKE_PROGRAM "C:\\Qt\\Tools\\Ninja\\ninja.exe") set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) # QtCreator supports the following variables for Android, which are identical to qmake Android variables. # Check http://doc.qt.io/qt-5/deployment-android.html for more information. # They need to be set before the find_package(Qt5 ...) call. #if(ANDROID) # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") # if (ANDROID_ABI STREQUAL "armeabi-v7a") # set(ANDROID_EXTRA_LIBS # ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so # ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so) # endif() #endif() find_package(Qt5 COMPONENTS Widgets REQUIRED) if(ANDROID) add_library(CMTest SHARED main.cpp cmtest.cpp cmtest.h ) else() add_executable(CMTest main.cpp cmtest.cpp cmtest.h ) endif() target_link_libraries(CMTest PRIVATE Qt5::Widgets)