understanding cmake -part 1-
-
Hi,
I have a very small cmake project for learning Qt. Now I have put my source code (cpp, h, ui) into a subdirectory (prg) of the project.
CMakeList.txt:
cmake_minimum_required(VERSION 3.16) project(FoE VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_PREFIX_PATH "/home/joachim/Qt/6.7.2/gcc_64/lib/cmake/") find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Sql) find_package(QT NAMES Qt6 REQUIRED COMPONENTS Sql) add_subdirectory(prg)
and
prg/CMakeList.txt
cmake_minimum_required(VERSION 3.16) set(PROJECT_SOURCES main.cpp MainWindow.h MainWindow.cpp MainWindow.ui ) add_executable(FoE ${PROJECT_SOURCES}) target_link_libraries(FoE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Sql) target_include_directories(FoE INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) include(GNUInstallDirs) install( TARGETS FoE BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
I also have a second cmake project from some month ago and this has to be different. The important part is:
find_package(Qt6 REQUIRED COMPONENTS Widgets) find_package(Qt6 REQUIRED COMPONENTS Core) find_package(Qt6 REQUIRED COMPONENTS Sql)
If I omit the lines with
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets)
,
cmakes complains.CMake Error at CMakeLists.txt:xx (find_package): By not providing "FindQt.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt", but CMake did not find one.
Why is the behaviour of the two projects different? They are on the same machine, same Qt installation, same IDE, ...
Do I miss something?
Joachim
-
M MasterQ referenced this topic on
-
Simply use
find_package(Qt6 REQUIRED COMPONTENS Widgets Sql
andtarget_link_libraries(FoE PRIVATE Qt6::Widgets Qt6::Sql)
- don't think you will ever support anything other than Qt6 so it's not worth the trouble. -
Hi,
I have a very small cmake project for learning Qt. Now I have put my source code (cpp, h, ui) into a subdirectory (prg) of the project.
CMakeList.txt:
cmake_minimum_required(VERSION 3.16) project(FoE VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_PREFIX_PATH "/home/joachim/Qt/6.7.2/gcc_64/lib/cmake/") find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Sql) find_package(QT NAMES Qt6 REQUIRED COMPONENTS Sql) add_subdirectory(prg)
and
prg/CMakeList.txt
cmake_minimum_required(VERSION 3.16) set(PROJECT_SOURCES main.cpp MainWindow.h MainWindow.cpp MainWindow.ui ) add_executable(FoE ${PROJECT_SOURCES}) target_link_libraries(FoE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Sql) target_include_directories(FoE INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) include(GNUInstallDirs) install( TARGETS FoE BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
I also have a second cmake project from some month ago and this has to be different. The important part is:
find_package(Qt6 REQUIRED COMPONENTS Widgets) find_package(Qt6 REQUIRED COMPONENTS Core) find_package(Qt6 REQUIRED COMPONENTS Sql)
If I omit the lines with
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets)
,
cmakes complains.CMake Error at CMakeLists.txt:xx (find_package): By not providing "FindQt.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt", but CMake did not find one.
Why is the behaviour of the two projects different? They are on the same machine, same Qt installation, same IDE, ...
Do I miss something?
Joachim
-
Simply use
find_package(Qt6 REQUIRED COMPONTENS Widgets Sql
andtarget_link_libraries(FoE PRIVATE Qt6::Widgets Qt6::Sql)
- don't think you will ever support anything other than Qt6 so it's not worth the trouble. -
@MasterQ said in understanding cmake -part 1-:
Why is the behaviour of the two projects different?
If you remove the package dependency, it won't work anymore as expected... so what is different?!
@Christian-Ehrlicher said in understanding cmake -part 1-:
Simply use
find_package(Qt6 REQUIRED COMPONTENS Widgets Sql
andtarget_link_libraries(FoE PRIVATE Qt6::Widgets Qt6::Sql)
- don't think you will ever support anything other than Qt6 so it's not worth the trouble.Year, that's it.
OK, still not knowing what the real root cause is behind. Nevermind, it is running now.
Thnx
-
M MasterQ has marked this topic as solved on