From 245f5ca8b3dc15d534e729f99c26764870dc5fa7 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 20 Feb 2025 11:09:08 +0100 Subject: Tests: Make CMakeGUI test build with both Qt5 and Qt6 Fixes: #26710 --- .../configure_fedora41_makefiles_symlinked.cmake | 4 +- Source/QtDialog/CMakeLists.txt | 1 + Tests/CMakeGUI/CMakeGUITest.cxx | 3 +- Tests/CMakeGUI/CMakeLists.txt | 56 +++++++++++++++++----- Tests/CMakeGUI/QCMakePresetItemModelTest.cxx | 2 + 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/.gitlab/ci/configure_fedora41_makefiles_symlinked.cmake b/.gitlab/ci/configure_fedora41_makefiles_symlinked.cmake index 6dd27f8..317de3a 100644 --- a/.gitlab/ci/configure_fedora41_makefiles_symlinked.cmake +++ b/.gitlab/ci/configure_fedora41_makefiles_symlinked.cmake @@ -1,3 +1,5 @@ -set(CMake_QT_MAJOR_VERSION "5" CACHE STRING "") +set(CMake_QT_MAJOR_VERSION "6" CACHE STRING "") +set(CMake_TEST_GUI "ON" CACHE BOOL "") + include("${CMAKE_CURRENT_LIST_DIR}/configure_symlinked_common.cmake") include("${CMAKE_CURRENT_LIST_DIR}/configure_fedora41_common.cmake") diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index ce363f4..7f851bd 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -264,6 +264,7 @@ target_link_libraries( ) add_executable(cmake-gui WIN32 MACOSX_BUNDLE CMakeGUIExec.cxx) +set_property(TARGET cmake-gui PROPERTY CMake_QT_MAJOR_VERSION "${CMake_QT_MAJOR_VERSION}") target_link_libraries(cmake-gui PRIVATE CMakeGUIMainLib diff --git a/Tests/CMakeGUI/CMakeGUITest.cxx b/Tests/CMakeGUI/CMakeGUITest.cxx index a3414fd..c6b6f63 100644 --- a/Tests/CMakeGUI/CMakeGUITest.cxx +++ b/Tests/CMakeGUI/CMakeGUITest.cxx @@ -75,7 +75,8 @@ void CMakeGUITest::tryConfigure(int expectedResult, int timeout) Qt::QueuedConnection); QVERIFY(configureDoneSpy.wait(timeout)); - QCOMPARE(configureDoneSpy, { { expectedResult } }); + QList configureDoneSignalArguments = configureDoneSpy.takeFirst(); + QCOMPARE(configureDoneSignalArguments.at(0).toInt(), expectedResult); } void CMakeGUITest::sourceBinaryArgs() diff --git a/Tests/CMakeGUI/CMakeLists.txt b/Tests/CMakeGUI/CMakeLists.txt index c9f44e9..d4c9bf8 100644 --- a/Tests/CMakeGUI/CMakeLists.txt +++ b/Tests/CMakeGUI/CMakeLists.txt @@ -1,6 +1,8 @@ include(CMakeParseArguments) -find_package(Qt5Test REQUIRED) +get_property(CMake_QT_MAJOR_VERSION TARGET cmake-gui PROPERTY CMake_QT_MAJOR_VERSION) + +find_package(Qt${CMake_QT_MAJOR_VERSION}Test REQUIRED) if(MSVC) # QTBUG-118993: Qt uses deprecated stdext::checked_array_iterator @@ -14,21 +16,40 @@ include_directories( ) set(MOC_SRCS) -qt5_wrap_cpp(MOC_SRCS - CatchShow.h - ) +if(CMake_QT_MAJOR_VERSION VERSION_LESS 6) + qt5_wrap_cpp(MOC_SRCS + CatchShow.h + ) +else() + qt_wrap_cpp(MOC_SRCS + CatchShow.h + ) +endif() add_library(CMakeGUITestLib STATIC ${MOC_SRCS} CatchShow.cxx CatchShow.h ) -target_link_libraries(CMakeGUITestLib Qt5::Core Qt5::Gui Qt5::Widgets) +target_link_libraries(CMakeGUITestLib + Qt${CMake_QT_MAJOR_VERSION}::Core + Qt${CMake_QT_MAJOR_VERSION}::Gui + Qt${CMake_QT_MAJOR_VERSION}::Widgets) set(MOC_SRCS) -qt5_wrap_cpp(MOC_SRCS - CMakeGUITest.h - ) +if(CMake_QT_MAJOR_VERSION VERSION_LESS 6) + qt5_wrap_cpp(MOC_SRCS + CMakeGUITest.h + ) +else() + qt_wrap_cpp(MOC_SRCS + CMakeGUITest.h + ) +endif() add_executable(CMakeGUITest CMakeGUITest.cxx ${MOC_SRCS}) -target_link_libraries(CMakeGUITest CMakeGUIMainLib CMakeGUITestLib Qt5::Core Qt5::Test Qt5::Widgets) +target_link_libraries(CMakeGUITest CMakeGUIMainLib CMakeGUITestLib + Qt${CMake_QT_MAJOR_VERSION}::Core + Qt${CMake_QT_MAJOR_VERSION}::Test + Qt${CMake_QT_MAJOR_VERSION}::Widgets +) target_compile_definitions(CMakeGUITest PRIVATE "CMakeGUITest_SOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"" "CMakeGUITest_BINARY_DIR=\"${CMAKE_CURRENT_BINARY_DIR}\"" @@ -47,11 +68,20 @@ function(add_cmake_gui_lib_test name) cmake_parse_arguments(_t "" "" "SOURCES;MOC_SOURCES" ${ARGN}) set(MOC_SRCS) - qt5_wrap_cpp(MOC_SRCS - ${_t_MOC_SOURCES} - ) + if(CMake_QT_MAJOR_VERSION VERSION_LESS 6) + qt5_wrap_cpp(MOC_SRCS + ${_t_MOC_SOURCES} + ) + else() + qt_wrap_cpp(MOC_SRCS + ${_t_MOC_SOURCES} + ) + endif() add_executable(${name} ${_t_SOURCES} ${MOC_SRCS}) - target_link_libraries(${name} CMakeGUILib CMakeGUITestLib Qt5::Core Qt5::Test Qt5::Widgets) + target_link_libraries(${name} CMakeGUILib CMakeGUITestLib + Qt${CMake_QT_MAJOR_VERSION}::Core + Qt${CMake_QT_MAJOR_VERSION}::Test + Qt${CMake_QT_MAJOR_VERSION}::Widgets) add_test(NAME "CMakeGUILib.${name}" COMMAND ${name}) endfunction() diff --git a/Tests/CMakeGUI/QCMakePresetItemModelTest.cxx b/Tests/CMakeGUI/QCMakePresetItemModelTest.cxx index 97dbb30..a2320b3 100644 --- a/Tests/CMakeGUI/QCMakePresetItemModelTest.cxx +++ b/Tests/CMakeGUI/QCMakePresetItemModelTest.cxx @@ -17,7 +17,9 @@ using QItemDataHash = QHash; void QCMakePresetItemModelTest::initTestCase() { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QMetaType::registerComparators(); +#endif } void QCMakePresetItemModelTest::initTestCase_data() -- cgit v0.12