Using CMake build system
-
wrote on 24 May 2020, 20:13 last edited by tomy
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)!
-
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...
-
@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...
wrote on 25 May 2020, 07:28 last edited by tomyI 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! :(
-
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. -
@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.wrote on 25 May 2020, 14:32 last edited by tomyI'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?! :(
-
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")
-
@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")
wrote on 26 May 2020, 07:09 last edited by tomyDid these both:
set(CMAKE_PREFIX_PATH "C:\\Qt\\5.14.2\\mingw73_64") set(CMAKE_MAKE_PROGRAM "C:\\Qt\\Tools\\Ninja\\ninja.exe")
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)
3/7