From 10c4a4b4bdfdd468e52ae0fbbf84c77b64df2f8f Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Fri, 3 Dec 2021 22:33:28 +0200 Subject: WIP: Change the build system to enable building with Qt 6 This was built with: -DQT_MAJOR_VERSION=6 \ -DEXCLUDE_DEPRECATED_BEFORE_AND_AT=5.90.0 \ -DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x055a00 Move the include(KDEInstallDirs) call before the first find_package(Qt*, the former is what auto-detects the Qt version, and defaults to 5. This is needed to be able to build against Qt5 by default. All unit tests still pass. --- CMakeLists.txt | 39 +++++++++++++++---------------- KF5ConfigConfig.cmake.in | 4 ++-- KF5ConfigMacros.cmake | 2 +- autotests/CMakeLists.txt | 22 ++++++++--------- autotests/kconfig_compiler/CMakeLists.txt | 6 ++--- autotests/kconfigtest.cpp | 26 +++++++++++++++------ src/CMakeLists.txt | 4 ++-- src/core/CMakeLists.txt | 10 ++++---- src/gui/CMakeLists.txt | 8 +++---- src/kconf_update/CMakeLists.txt | 2 +- src/kconfig_compiler/CMakeLists.txt | 2 +- src/qml/CMakeLists.txt | 6 ++--- 12 files changed, 71 insertions(+), 60 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fe55a63..d880c52a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,25 +10,6 @@ feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKA set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) -set(REQUIRED_QT_VERSION 5.15.2) - -find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Xml) -option(KCONFIG_USE_GUI "Build components using Qt5Gui" ON) -if(KCONFIG_USE_GUI) - find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Gui) -endif() -find_package(Qt5 ${REQUIRED_QT_VERSION} OPTIONAL_COMPONENTS Qml) - -if (NOT ANDROID) - option(KCONFIG_USE_DBUS "Build components using Qt5DBus" ON) - if(KCONFIG_USE_DBUS) - find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED DBus) - endif() -else() - set(KCONFIG_USE_DBUS Off) -endif() - - include(KDEInstallDirs) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) @@ -42,6 +23,24 @@ include(ECMPoQmTools) include(ECMAddQch) include(ECMQtDeclareLoggingCategory) +set(REQUIRED_QT_VERSION 5.15.2) + +find_package(Qt${QT_MAJOR_VERSION} ${REQUIRED_QT_VERSION} CONFIG REQUIRED Xml) +option(KCONFIG_USE_GUI "Build components using Qt${QT_MAJOR_VERSION}Gui" ON) +if(KCONFIG_USE_GUI) + find_package(Qt${QT_MAJOR_VERSION} ${REQUIRED_QT_VERSION} CONFIG REQUIRED Gui) +endif() +find_package(Qt${QT_MAJOR_VERSION} ${REQUIRED_QT_VERSION} OPTIONAL_COMPONENTS Qml) + +if (NOT ANDROID) + option(KCONFIG_USE_DBUS "Build components using Qt${QT_MAJOR_VERSION}DBus" ON) + if(KCONFIG_USE_DBUS) + find_package(Qt${QT_MAJOR_VERSION} ${REQUIRED_QT_VERSION} CONFIG REQUIRED DBus) + endif() +else() + set(KCONFIG_USE_DBUS Off) +endif() + set(EXCLUDE_DEPRECATED_BEFORE_AND_AT 0 CACHE STRING "Control the range of deprecated API excluded from the build [default=0].") option(BUILD_QCH "Build API documentation in QCH format (for e.g. Qt Assistant, Qt Creator & KDevelop)" OFF) @@ -98,7 +97,7 @@ install(EXPORT KF5ConfigCompilerTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5ConfigCompilerTargets.cmake NAMESPACE KF5:: COMPONENT Devel) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kconfig_version.h - DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel ) + DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF} COMPONENT Devel ) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/KF5ConfigConfig.cmake.in b/KF5ConfigConfig.cmake.in index d24ae2ba..9b696ceb 100644 --- a/KF5ConfigConfig.cmake.in +++ b/KF5ConfigConfig.cmake.in @@ -6,10 +6,10 @@ include("${CMAKE_CURRENT_LIST_DIR}/KF5ConfigTargets.cmake") @PACKAGE_INCLUDE_QCHTARGETS@ include(CMakeFindDependencyMacro) -find_dependency(Qt5Xml "@REQUIRED_QT_VERSION@") +find_dependency(Qt@QT_MAJOR_VERSION@Xml @REQUIRED_QT_VERSION@) if(@KCONFIG_USE_DBUS@) - find_dependency(Qt5DBus "@REQUIRED_QT_VERSION@") + find_dependency(Qt@QT_MAJOR_VERSION@DBus "@REQUIRED_QT_VERSION@") endif() if(CMAKE_CROSSCOMPILING AND KF5_HOST_TOOLING) diff --git a/KF5ConfigMacros.cmake b/KF5ConfigMacros.cmake index 3ceaf17c..80c947d8 100644 --- a/KF5ConfigMacros.cmake +++ b/KF5ConfigMacros.cmake @@ -111,7 +111,7 @@ function (KCONFIG_ADD_KCFG_FILES _target_or_source_var) if(ARG_GENERATE_MOC) list(APPEND sources ${_moc_FILE}) - qt5_generate_moc(${_header_FILE} ${_moc_FILE}) + qt_generate_moc(${_header_FILE} ${_moc_FILE}) set_property(SOURCE ${_src_FILE} APPEND PROPERTY OBJECT_DEPENDS ${_moc_FILE} ) endif() diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index cae4c0b1..a7e37e5a 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,14 +1,14 @@ include(ECMAddTests) -find_package(Qt5Test ${REQUIRED_QT_VERSION} CONFIG QUIET) -find_package(Qt5Concurrent ${REQUIRED_QT_VERSION} CONFIG QUIET) +find_package(Qt${QT_MAJOR_VERSION}Test ${REQUIRED_QT_VERSION} CONFIG QUIET) +find_package(Qt${QT_MAJOR_VERSION}Concurrent ${REQUIRED_QT_VERSION} CONFIG QUIET) -if(NOT Qt5Test_FOUND) +if(NOT Qt${QT_MAJOR_VERSION}Test_FOUND) message(STATUS "Qt5Test not found, autotests will not be built.") return() endif() -if(NOT Qt5Concurrent_FOUND) +if(NOT Qt${QT_MAJOR_VERSION}Concurrent_FOUND) message(STATUS "Qt5Concurrent not found, autotests will not be built.") return() endif() @@ -18,7 +18,7 @@ ecm_add_test( kentrymaptest.cpp ../src/core/kconfigdata.cpp TEST_NAME kentrymaptest - LINK_LIBRARIES Qt5::Test + LINK_LIBRARIES Qt${QT_MAJOR_VERSION}::Test ) target_include_directories(kentrymaptest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src/core) @@ -27,17 +27,17 @@ ecm_add_test( test_kconfigutils.cpp ../src/kconf_update/kconfigutils.cpp TEST_NAME test_kconfigutils - LINK_LIBRARIES KF5::ConfigCore Qt5::Test + LINK_LIBRARIES KF5::ConfigCore Qt${QT_MAJOR_VERSION}::Test ) target_include_directories(test_kconfigutils PRIVATE ../src/kconf_update) qt_add_resources(sharedconfigresources sharedconfigresources.qrc) -ecm_add_test(ksharedconfigtest.cpp ${sharedconfigresources} TEST_NAME kconfigcore-ksharedconfigtest LINK_LIBRARIES KF5::ConfigCore Qt5::Test Qt5::Concurrent) +ecm_add_test(ksharedconfigtest.cpp ${sharedconfigresources} TEST_NAME kconfigcore-ksharedconfigtest LINK_LIBRARIES KF5::ConfigCore Qt${QT_MAJOR_VERSION}::Test Qt${QT_MAJOR_VERSION}::Concurrent) # test for fallback to :/kconfig/xxxx config resource qt_add_resources(fallbackconfigresources fallbackconfigresources.qrc) -ecm_add_test(fallbackconfigresourcestest.cpp ${fallbackconfigresources} TEST_NAME kconfigcore-fallbackconfigresourcestest LINK_LIBRARIES KF5::ConfigCore Qt5::Test Qt5::Concurrent) +ecm_add_test(fallbackconfigresourcestest.cpp ${fallbackconfigresources} TEST_NAME kconfigcore-fallbackconfigresourcestest LINK_LIBRARIES KF5::ConfigCore Qt${QT_MAJOR_VERSION}::Test Qt${QT_MAJOR_VERSION}::Concurrent) ecm_add_tests( kconfignokdehometest.cpp @@ -46,19 +46,19 @@ ecm_add_tests( test_kconf_update.cpp ksharedconfig_in_global_object.cpp NAME_PREFIX kconfigcore- - LINK_LIBRARIES KF5::ConfigCore Qt5::Test Qt5::Concurrent + LINK_LIBRARIES KF5::ConfigCore Qt${QT_MAJOR_VERSION}::Test Qt${QT_MAJOR_VERSION}::Concurrent ) target_include_directories(test_kconf_update PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../src/kconf_update) -if(TARGET Qt5::Gui) +if(TARGET Qt${QT_MAJOR_VERSION}::Gui) ecm_add_tests( kconfigguitest.cpp kconfigloadertest.cpp kconfigskeletontest.cpp kstandardshortcuttest.cpp NAME_PREFIX kconfiggui- - LINK_LIBRARIES KF5::ConfigGui Qt5::Test + LINK_LIBRARIES KF5::ConfigGui Qt${QT_MAJOR_VERSION}::Test ) # These tests do a global cleanup of ~/.qttest, so they can't run in parallel diff --git a/autotests/kconfig_compiler/CMakeLists.txt b/autotests/kconfig_compiler/CMakeLists.txt index 4caa17af..5cbf2e44 100644 --- a/autotests/kconfig_compiler/CMakeLists.txt +++ b/autotests/kconfig_compiler/CMakeLists.txt @@ -177,7 +177,7 @@ set(test_state_config_SRCS test_state_config_main.cpp) gen_kcfg_test_source(test_state_config test_state_config_SRCS GENERATE_MOC) ecm_add_test(TEST_NAME test_state_config ${test_state_config_SRCS}) -target_link_libraries(test_state_config KF5::ConfigGui Qt5::Test) +target_link_libraries(test_state_config KF5::ConfigGui Qt${QT_MAJOR_VERSION}::Test) ########### next target ############### @@ -234,7 +234,7 @@ gen_kcfg_test_source(signals_test_no_singleton_dpointer kconfigcompiler_test_sig ecm_add_test(${kconfigcompiler_test_signals_SRCS} TEST_NAME kconfigcompiler-signals-test - LINK_LIBRARIES Qt5::Test KF5::ConfigGui + LINK_LIBRARIES Qt${QT_MAJOR_VERSION}::Test KF5::ConfigGui ) ########### next target ############### @@ -261,7 +261,7 @@ ecm_add_test(${test_param_minmax_SRCS} ecm_add_test(kconfigcompiler_test.cpp TEST_NAME kconfigcompiler-basic-test - LINK_LIBRARIES Qt5::Test + LINK_LIBRARIES Qt${QT_MAJOR_VERSION}::Test ) diff --git a/autotests/kconfigtest.cpp b/autotests/kconfigtest.cpp index 4657ea8d..95a87584 100644 --- a/autotests/kconfigtest.cpp +++ b/autotests/kconfigtest.cpp @@ -1974,18 +1974,30 @@ void KConfigTest::testXdgListEntry() void KConfigTest::testThreads() { QThreadPool::globalInstance()->setMaxThreadCount(6); - QList> futures; // Run in parallel some tests that work on different config files, // otherwise unexpected things might indeed happen. - futures << QtConcurrent::run(this, &KConfigTest::testAddConfigSources); - futures << QtConcurrent::run(this, &KConfigTest::testSimple); - futures << QtConcurrent::run(this, &KConfigTest::testDefaults); - futures << QtConcurrent::run(this, &KConfigTest::testSharedConfig); - futures << QtConcurrent::run(this, &KConfigTest::testSharedConfig); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + const QList> futures = { + QtConcurrent::run(&KConfigTest::testAddConfigSources, this), + QtConcurrent::run(&KConfigTest::testSimple, this), + QtConcurrent::run(&KConfigTest::testDefaults, this), + QtConcurrent::run(&KConfigTest::testSharedConfig, this), + QtConcurrent::run(&KConfigTest::testSharedConfig, this), + }; +#else + const QList> futures = { + QtConcurrent::run(this, &KConfigTest::testAddConfigSources), + QtConcurrent::run(this, &KConfigTest::testSimple), + QtConcurrent::run(this, &KConfigTest::testDefaults), + QtConcurrent::run(this, &KConfigTest::testSharedConfig), + QtConcurrent::run(this, &KConfigTest::testSharedConfig), + }; +#endif + // QEXPECT_FAIL triggers race conditions, it should be fixed to use QThreadStorage... // futures << QtConcurrent::run(this, &KConfigTest::testDeleteWhenLocalized); // futures << QtConcurrent::run(this, &KConfigTest::testEntryMap); - for (QFuture f : std::as_const(futures)) { + for (QFuture f : futures) { f.waitForFinished(); } } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 89fe7284..715890e0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,8 @@ add_subdirectory(core) -if(TARGET Qt5::Gui) +if(TARGET Qt${QT_MAJOR_VERSION}::Gui) add_subdirectory(gui) endif() -if(TARGET Qt5::Qml) +if(TARGET Qt${QT_MAJOR_VERSION}::Qml) add_subdirectory(qml) endif() add_subdirectory(kconfig_compiler) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index c91dd040..2b5e949c 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -41,12 +41,12 @@ target_compile_definitions(KF5ConfigCore KCONF_UPDATE_INSTALL_LOCATION="${KDE_INSTALL_FULL_LIBEXECDIR_KF5}/$" ) -target_include_directories(KF5ConfigCore INTERFACE "$") +target_include_directories(KF5ConfigCore INTERFACE "$") -target_link_libraries(KF5ConfigCore PUBLIC Qt5::Core) +target_link_libraries(KF5ConfigCore PUBLIC Qt${QT_MAJOR_VERSION}::Core) if(KCONFIG_USE_DBUS) - target_link_libraries(KF5ConfigCore PRIVATE Qt5::DBus) + target_link_libraries(KF5ConfigCore PRIVATE Qt${QT_MAJOR_VERSION}::DBus) endif() set_target_properties(KF5ConfigCore PROPERTIES VERSION ${KCONFIG_VERSION} @@ -98,7 +98,7 @@ install(TARGETS KF5ConfigCore EXPORT KF5ConfigTargets ${KF5_INSTALL_TARGETS_DEFA install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kconfigcore_export.h ${KConfigCore_HEADERS} - DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KConfigCore COMPONENT Devel + DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF}/KConfigCore COMPONENT Devel ) # make available to ecm_add_qch in parent folder @@ -106,5 +106,5 @@ set(KConfigCore_APIDOX_SRCS ${KConfigCore_HEADERS} PARENT_SCOPE) set(KConfigCore_APIDOX_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE) include(ECMGeneratePriFile) -ecm_generate_pri_file(BASE_NAME KConfigCore LIB_NAME KF5ConfigCore DEPS "core" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KConfigCore) +ecm_generate_pri_file(BASE_NAME KConfigCore LIB_NAME KF5ConfigCore DEPS "core" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF}/KConfigCore) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 9dad629a..4d5512d1 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -21,9 +21,9 @@ ecm_generate_export_header(KF5ConfigGui EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT} ) -target_include_directories(KF5ConfigGui INTERFACE "$") +target_include_directories(KF5ConfigGui INTERFACE "$") -target_link_libraries(KF5ConfigGui PUBLIC Qt5::Gui Qt5::Xml KF5::ConfigCore) +target_link_libraries(KF5ConfigGui PUBLIC Qt${QT_MAJOR_VERSION}::Gui Qt${QT_MAJOR_VERSION}::Xml KF5::ConfigCore) set_target_properties(KF5ConfigGui PROPERTIES VERSION ${KCONFIG_VERSION} SOVERSION ${KCONFIG_SOVERSION} @@ -68,7 +68,7 @@ install(TARGETS KF5ConfigGui EXPORT KF5ConfigTargets ${KF5_INSTALL_TARGETS_DEFAU install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kconfiggui_export.h ${KConfigGui_HEADERS} - DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KConfigGui COMPONENT Devel + DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF}/KConfigGui COMPONENT Devel ) # make available to ecm_add_qch in parent folder @@ -76,5 +76,5 @@ set(KConfigGui_APIDOX_SRCS ${KConfigGui_HEADERS} PARENT_SCOPE) set(KConfigGui_APIDOX_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE) include(ECMGeneratePriFile) -ecm_generate_pri_file(BASE_NAME KConfigGui LIB_NAME KF5ConfigGui DEPS "gui xml KConfigCore" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KConfigGui) +ecm_generate_pri_file(BASE_NAME KConfigGui LIB_NAME KF5ConfigGui DEPS "gui xml KConfigCore" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF}/KConfigGui) install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) diff --git a/src/kconf_update/CMakeLists.txt b/src/kconf_update/CMakeLists.txt index 40fb4ccb..8c23b358 100644 --- a/src/kconf_update/CMakeLists.txt +++ b/src/kconf_update/CMakeLists.txt @@ -15,7 +15,7 @@ ecm_qt_declare_logging_category(kconf_update EXPORT KCONFIG ) -target_link_libraries(kconf_update Qt5::Core KF5::ConfigCore) +target_link_libraries(kconf_update Qt${QT_MAJOR_VERSION}::Core KF5::ConfigCore) include(ECMMarkNonGuiExecutable) ecm_mark_nongui_executable(kconf_update) diff --git a/src/kconfig_compiler/CMakeLists.txt b/src/kconfig_compiler/CMakeLists.txt index 0e11ee58..a475b511 100644 --- a/src/kconfig_compiler/CMakeLists.txt +++ b/src/kconfig_compiler/CMakeLists.txt @@ -21,7 +21,7 @@ set_target_properties(kconfig_compiler PROPERTIES OUTPUT_NAME "kconfig_compiler_kf5" ) -target_link_libraries(kconfig_compiler Qt5::Xml) +target_link_libraries(kconfig_compiler Qt${QT_MAJOR_VERSION}::Xml) ecm_mark_nongui_executable(kconfig_compiler) diff --git a/src/qml/CMakeLists.txt b/src/qml/CMakeLists.txt index 1cdae88a..17f90ad0 100644 --- a/src/qml/CMakeLists.txt +++ b/src/qml/CMakeLists.txt @@ -16,7 +16,7 @@ ecm_generate_export_header(KF5ConfigQml target_link_libraries(KF5ConfigQml PUBLIC KF5::ConfigCore # KCoreConfigSkeleton, in ConfigPropertyMap - Qt5::Qml + Qt${QT_MAJOR_VERSION}::Qml ) set_target_properties(KF5ConfigQml PROPERTIES VERSION ${KCONFIG_VERSION} SOVERSION ${KCONFIG_SOVERSION} @@ -29,11 +29,11 @@ ecm_generate_headers(KConfigQml_HEADERS REQUIRED_HEADERS KConfigQml_HEADERS ) -target_include_directories(KF5ConfigQml INTERFACE "$") +target_include_directories(KF5ConfigQml INTERFACE "$") install(TARGETS KF5ConfigQml EXPORT KF5ConfigTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kconfigqml_export.h ${KConfigQml_HEADERS} - DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KConfigQml COMPONENT Devel + DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF}/KConfigQml COMPONENT Devel ) -- cgit v1.2.1