diff options
author | Craig Scott <craig.scott@crascit.com> | 2021-10-04 11:10:56 (GMT) |
---|---|---|
committer | Craig Scott <craig.scott@crascit.com> | 2021-10-04 11:10:57 (GMT) |
commit | a7420884723c4fb09e6370fb25710a2172c10a0c (patch) | |
tree | 7d1d5cd434ca27e8b038457c784bf08af7f36c2f /Tests/RunCMake/Ninja | |
parent | b3a0bddc4e1c8f1f86078cdffaebbc4c493e4409 (diff) | |
download | CMake-a7420884723c4fb09e6370fb25710a2172c10a0c.zip CMake-a7420884723c4fb09e6370fb25710a2172c10a0c.tar.gz CMake-a7420884723c4fb09e6370fb25710a2172c10a0c.tar.bz2 |
Tests: Add support for testing Qt6
The minimum CMake version for Qt6 is 3.16, so all the calls to
cmake_minimum_required() are updated here to enforce that
minimum. This will avoid any CMake version-related warnings
from Qt.
Avoid hard-coding Qt5 where the tests could now be using
Qt5 or Qt6.
Fixes: #22188
Diffstat (limited to 'Tests/RunCMake/Ninja')
-rw-r--r-- | Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake | 21 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/QtAutoMocDeps.cmake | 27 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/QtSubDir3/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/Ninja/RunCMakeTest.cmake | 21 |
6 files changed, 44 insertions, 31 deletions
diff --git a/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake b/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake deleted file mode 100644 index 46b840f..0000000 --- a/Tests/RunCMake/Ninja/Qt5AutoMocDeps.cmake +++ /dev/null @@ -1,21 +0,0 @@ -enable_language(CXX) - -find_package(Qt5Core REQUIRED) - -set(CMAKE_AUTOMOC ON) - -add_library(simple_lib SHARED simple_lib.cpp) -add_executable(app_with_qt app.cpp app_qt.cpp) -target_link_libraries(app_with_qt PRIVATE simple_lib Qt5::Core) - -if(Qt5Widgets_DIR) - find_package(Qt5Widgets REQUIRED) - qt5_wrap_ui(_headers MyWindow.ui) - add_executable(app_with_widget app.cpp MyWindow.cpp ${_headers}) - target_link_libraries(app_with_widget PRIVATE Qt5::Widgets) - target_include_directories(app_with_widget PRIVATE "${CMAKE_BINARY_DIR}") -endif() - -add_subdirectory(QtSubDir1) -add_subdirectory(QtSubDir2) -add_subdirectory(QtSubDir3) diff --git a/Tests/RunCMake/Ninja/QtAutoMocDeps.cmake b/Tests/RunCMake/Ninja/QtAutoMocDeps.cmake new file mode 100644 index 0000000..c441169 --- /dev/null +++ b/Tests/RunCMake/Ninja/QtAutoMocDeps.cmake @@ -0,0 +1,27 @@ +enable_language(CXX) + +set(QtX Qt${with_qt_version}) + +find_package(${QtX} REQUIRED COMPONENTS Core) + +set(CMAKE_AUTOMOC ON) + +add_library(simple_lib SHARED simple_lib.cpp) +add_executable(app_with_qt app.cpp app_qt.cpp) +target_link_libraries(app_with_qt PRIVATE simple_lib ${QtX}::Core) + +if(${QtX}Widgets_DIR) + find_package(${QtX} REQUIRED COMPONENTS Widgets) + if(with_qt_version STREQUAL 5) + qt5_wrap_ui(_headers MyWindow.ui) + else() + qt_wrap_ui(_headers MyWindow.ui) + endif() + add_executable(app_with_widget app.cpp MyWindow.cpp ${_headers}) + target_link_libraries(app_with_widget PRIVATE ${QtX}::Widgets) + target_include_directories(app_with_widget PRIVATE "${CMAKE_BINARY_DIR}") +endif() + +add_subdirectory(QtSubDir1) +add_subdirectory(QtSubDir2) +add_subdirectory(QtSubDir3) diff --git a/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt b/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt index 64016b6..3a12dcd 100644 --- a/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt +++ b/Tests/RunCMake/Ninja/QtSubDir1/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_policy(SET CMP0116 OLD) add_executable(sub_exe_1 ../app.cpp) -target_link_libraries(sub_exe_1 PRIVATE Qt5::Core) +target_link_libraries(sub_exe_1 PRIVATE ${QtX}::Core) diff --git a/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt b/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt index 3176426..a2f77e4 100644 --- a/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt +++ b/Tests/RunCMake/Ninja/QtSubDir2/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_policy(SET CMP0116 NEW) add_executable(sub_exe_2 ../app.cpp) -target_link_libraries(sub_exe_2 PRIVATE Qt5::Core) +target_link_libraries(sub_exe_2 PRIVATE ${QtX}::Core) diff --git a/Tests/RunCMake/Ninja/QtSubDir3/CMakeLists.txt b/Tests/RunCMake/Ninja/QtSubDir3/CMakeLists.txt index d38cfe0..70644fa 100644 --- a/Tests/RunCMake/Ninja/QtSubDir3/CMakeLists.txt +++ b/Tests/RunCMake/Ninja/QtSubDir3/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable(sub_exe_3 ../app.cpp) -target_link_libraries(sub_exe_3 PRIVATE Qt5::Core) +target_link_libraries(sub_exe_3 PRIVATE ${QtX}::Core) diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake index 3f239b9..2a5b556 100644 --- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake +++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake @@ -319,12 +319,17 @@ function (run_ChangeBuildType) endfunction() run_ChangeBuildType() -function(run_Qt5AutoMocDeps) - if(CMake_TEST_Qt5 AND CMAKE_TEST_Qt5Core_Version VERSION_GREATER_EQUAL 5.15.0) - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Qt5AutoMocDeps-build) - set(RunCMake_TEST_OPTIONS "-DQt5Core_DIR=${Qt5Core_DIR}" "-DQt5Widgets_DIR=${Qt5Widgets_DIR}") - run_cmake(Qt5AutoMocDeps) - unset(RunCMake_TEST_OPTIONS) +function(run_QtAutoMocDeps) + set(QtX Qt${CMake_TEST_Qt_version}) + if(CMake_TEST_${QtX}Core_Version VERSION_GREATER_EQUAL 5.15.0) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/QtAutoMocDeps-build) + run_cmake_with_options(QtAutoMocDeps + "-Dwith_qt_version=${CMake_TEST_Qt_version}" + "-D${QtX}_DIR=${${QtX}_DIR}" + "-D${QtX}Core_DIR=${${QtX}Core_DIR}" + "-D${QtX}Widgets_DIR=${${QtX}Widgets_DIR}" + "-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}" + ) # Build the project. run_ninja("${RunCMake_TEST_BINARY_DIR}") # Touch just the library source file, which shouldn't cause a rerun of AUTOMOC @@ -352,4 +357,6 @@ function(run_Qt5AutoMocDeps) run_ninja("${RunCMake_TEST_BINARY_DIR}") endif() endfunction() -run_Qt5AutoMocDeps() +if(CMake_TEST_Qt_version) + run_QtAutoMocDeps() +endif() |