From f78dbf3bae14cf3342c7a1428b02cd0a4db95c91 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Fri, 20 May 2022 19:03:40 +0200 Subject: [PATCH] allow detection of qt5 or qt6 Signed-off-by: Matthieu Gallien --- CMakeLists.txt | 4 + .../libcloudproviders/CMakeLists.txt | 9 ++- src/CMakeLists.txt | 16 +++- src/cmd/CMakeLists.txt | 4 +- src/csync/CMakeLists.txt | 2 +- src/gui/CMakeLists.txt | 75 +++++++++++++------ src/libsync/CMakeLists.txt | 22 ++++-- test/CMakeLists.txt | 2 +- test/csync/CMakeLists.txt | 2 +- test/nextcloud_add_test.cmake | 19 +++-- 10 files changed, 108 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0176eaf9af3e2..0f11ce904f4c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,10 @@ if(APPLE AND BUILD_OWNCLOUD_OSX_BUNDLE) set(BIN_INSTALL_DIR "${APPLICATION_NAME}.app/Contents/MacOS") endif() +find_package(Qt5 COMPONENTS Core) +if (NOT Qt5Core_FOUND) + find_package(Qt6 COMPONENTS Core) +endif() option(QUICK_COMPILER "Use QtQuick compiler to improve performance" OFF) diff --git a/shell_integration/libcloudproviders/CMakeLists.txt b/shell_integration/libcloudproviders/CMakeLists.txt index d5391a7a401d2..7e3a7a5e4d4b7 100644 --- a/shell_integration/libcloudproviders/CMakeLists.txt +++ b/shell_integration/libcloudproviders/CMakeLists.txt @@ -41,8 +41,13 @@ macro(libcloudproviders_add_config _sources) endmacro(libcloudproviders_add_config _sources) -find_package(Qt5 5.15 COMPONENTS DBus) -IF (Qt5DBus_FOUND) +if (Qt6_FOUND) + find_package(Qt6 COMPONENTS COMPONENTS DBus) +else() + set(REQUIRED_QT_VERSION "5.15.0") + find_package(Qt5 ${REQUIRED_QT_VERSION} COMPONENTS DBus) +endif() +IF (Qt5DBus_FOUND OR Qt6DBus_FOUND) STRING(TOLOWER "${APPLICATION_VENDOR}" DBUS_VENDOR) STRING(REGEX REPLACE "[^A-z0-9]" "" DBUS_VENDOR "${DBUS_VENDOR}") STRING(REGEX REPLACE "[^A-z0-9]" "" DBUS_APPLICATION_NAME "${APPLICATION_SHORTNAME}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0c051c9a46d01..a1784f938b4c4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,18 +4,26 @@ endif() include(ECMEnableSanitizers) -find_package(Qt5 5.15 COMPONENTS Core Network Xml Concurrent REQUIRED) -find_package(Qt5 5.15 COMPONENTS WebEngineWidgets WebEngine) +if (Qt6_FOUND) + find_package(Qt6 COMPONENTS REQUIRED Core Network Xml Concurrent WebEngineWidgets) +else() + set(REQUIRED_QT_VERSION "5.15.0") + find_package(Qt5 ${REQUIRED_QT_VERSION} COMPONENTS REQUIRED Core Network Xml Concurrent WebEngineWidgets WebEngine) +endif() if(Qt5WebEngine_FOUND AND Qt5WebEngineWidgets_FOUND) add_compile_definitions(WITH_WEBENGINE=1) endif() -get_target_property (QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION) +get_target_property (QT_QMAKE_EXECUTABLE Qt::qmake IMPORTED_LOCATION) message(STATUS "Using Qt ${Qt5Core_VERSION} (${QT_QMAKE_EXECUTABLE})") if(NOT TOKEN_AUTH_ONLY) - find_package(Qt5Keychain REQUIRED) + if(NOT Qt6_FOUND) + find_package(Qt5Keychain REQUIRED) + else() + find_package(Qt6Keychain REQUIRED) + endif() endif() # TODO: Mingw64 7.3 might also need to be excluded here as it seems to not automatically link libssp diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index 8ddebfdcec4e9..fad2ed6ed0a11 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -10,8 +10,8 @@ add_library(cmdCore STATIC target_link_libraries(cmdCore PUBLIC Nextcloud::sync - Qt5::Core - Qt5::Network + Qt::Core + Qt::Network ) # Need tokenizer for netrc parser diff --git a/src/csync/CMakeLists.txt b/src/csync/CMakeLists.txt index 5bdd5e5bf3b8e..a1d804c55c138 100644 --- a/src/csync/CMakeLists.txt +++ b/src/csync/CMakeLists.txt @@ -89,7 +89,7 @@ generate_export_header(nextcloud_csync target_link_libraries(nextcloud_csync PUBLIC ${CSYNC_REQUIRED_LIBRARIES} - Qt5::Core Qt5::Concurrent + Qt::Core Qt::Concurrent ) if(ZLIB_FOUND) diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 9209968367385..bcb841801bd50 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -1,15 +1,29 @@ project(gui) -find_package(Qt5 REQUIRED COMPONENTS Widgets Svg Qml Quick QuickControls2 Xml Network) +if (Qt6_FOUND) + find_package(Qt6 COMPONENTS REQUIRED Widgets Svg Qml Quick QuickControls2 Xml Network) +else() + set(REQUIRED_QT_VERSION "5.15.0") + find_package(Qt5 ${REQUIRED_QT_VERSION} COMPONENTS REQUIRED Widgets Svg Qml Quick QuickControls2 Xml Network) +endif() if(QUICK_COMPILER) - find_package(Qt5QuickCompiler) + if (Qt6_FOUND) +# find_package(Qt6 COMPONENTS QuickCompiler) +# set_package_properties(Qt6QuickCompiler PROPERTIES +# DESCRIPTION "Compile QML at build time" +# TYPE REQUIRED +# ) + else() + set(REQUIRED_QT_VERSION "5.15.0") + find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED QuickCompiler) set_package_properties(Qt5QuickCompiler PROPERTIES DESCRIPTION "Compile QML at build time" TYPE REQUIRED ) + endif() endif() -if (NOT TARGET Qt5::GuiPrivate) +if (NOT TARGET Qt::GuiPrivate) message(FATAL_ERROR "Could not find GuiPrivate component of Qt5. It might be shipped as a separate package, please check that.") endif() @@ -57,7 +71,7 @@ set(client_UI_SRCS wizard/welcomepage.ui ) -if(QUICK_COMPILER) +if(Qt5QuickCompiler_FOUND) qtquick_compiler_add_resources(client_UI_SRCS ../../resources.qrc ${CMAKE_SOURCE_DIR}/theme.qrc) else() qt_add_resources(client_UI_SRCS ../../resources.qrc ${CMAKE_SOURCE_DIR}/theme.qrc) @@ -318,9 +332,14 @@ else() list(APPEND 3rdparty_SRC ../3rdparty/qtlockedfile/qtlockedfile_win.cpp ) endif() -find_package(Qt5LinguistTools) -if(Qt5LinguistTools_FOUND) - qt5_add_translation(client_I18N ${TRANSLATIONS}) +if (Qt6_FOUND) + find_package(Qt6 COMPONENTS LinguistTools) +else() + set(REQUIRED_QT_VERSION "5.15.0") + find_package(Qt5 ${REQUIRED_QT_VERSION} COMPONENTS LinguistTools) +endif() +if(Qt5LinguistTools_FOUND OR Qt6LinguistTools_FOUND) + qt_add_translation(client_I18N ${TRANSLATIONS}) endif() IF( WIN32 ) @@ -533,20 +552,20 @@ add_library(nextcloudCore STATIC ${final_src}) target_link_libraries(nextcloudCore PUBLIC Nextcloud::sync - Qt5::Widgets - Qt5::GuiPrivate - Qt5::Svg - Qt5::Network - Qt5::Xml - Qt5::Qml - Qt5::Quick - Qt5::QuickControls2 + Qt::Widgets + Qt::GuiPrivate + Qt::Svg + Qt::Network + Qt::Xml + Qt::Qml + Qt::Quick + Qt::QuickControls2 ) add_subdirectory(socketapi) if(Qt5WebEngine_FOUND AND Qt5WebEngineWidgets_FOUND) - target_link_libraries(nextcloudCore PUBLIC Qt5::WebEngineWidgets) + target_link_libraries(nextcloudCore PUBLIC Qt::WebEngineWidgets) endif() set_target_properties(nextcloudCore @@ -604,7 +623,7 @@ else() set (QM_DIR ${OWNCLOUD_OSX_BUNDLE}/Contents/Resources/Translations) install(FILES ${client_I18N} DESTINATION ${QM_DIR}) - get_target_property(_qmake Qt5::qmake LOCATION) + get_target_property(_qmake Qt::qmake LOCATION) execute_process(COMMAND ${_qmake} -query QT_INSTALL_TRANSLATIONS OUTPUT_VARIABLE QT_TRANSLATIONS_DIR OUTPUT_STRIP_TRAILING_WHITESPACE @@ -619,7 +638,7 @@ endif() IF(BUILD_UPDATER) add_library(updater STATIC ${updater_SRCS}) - target_link_libraries(updater Nextcloud::sync ${updater_DEPS} Qt5::Widgets Qt5::Svg Qt5::Network Qt5::Xml) + target_link_libraries(updater Nextcloud::sync ${updater_DEPS} Qt::Widgets Qt::Svg Qt::Network Qt::Xml) target_include_directories(updater PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(updater PROPERTIES AUTOMOC ON) target_link_libraries(nextcloudCore PUBLIC updater) @@ -656,14 +675,24 @@ endif() ## handle DBUS for Fdo notifications if( UNIX AND NOT APPLE ) - find_package(Qt5 COMPONENTS DBus) - target_link_libraries(nextcloudCore PUBLIC Qt5::DBus) + if (Qt6_FOUND) + find_package(Qt6 COMPONENTS DBus) + else() + set(REQUIRED_QT_VERSION "5.15.0") + find_package(Qt5 ${REQUIRED_QT_VERSION} COMPONENTS DBus) + endif() + target_link_libraries(nextcloudCore PUBLIC Qt::DBus) target_compile_definitions(nextcloudCore PUBLIC "USE_FDO_NOTIFICATIONS") endif() if (APPLE) - find_package(Qt5 COMPONENTS MacExtras) - target_link_libraries(nextcloudCore PUBLIC Qt5::MacExtras "-framework UserNotifications") + if (Qt6_FOUND) + find_package(Qt6 COMPONENTS MacExtras) + else() + set(REQUIRED_QT_VERSION "5.15.0") + find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG MacExtras) + endif() + target_link_libraries(nextcloudCore PUBLIC Qt::MacExtras "-framework UserNotifications") endif() if(WITH_CRASHREPORTER) @@ -690,7 +719,7 @@ install(TARGETS nextcloud # # OSX: Run macdeployqt for src/gui and for src/cmd using the -executable option if(BUILD_OWNCLOUD_OSX_BUNDLE AND NOT BUILD_LIBRARIES_ONLY) - get_target_property (QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION) + get_target_property (QT_QMAKE_EXECUTABLE Qt::qmake IMPORTED_LOCATION) get_filename_component(QT_BIN_DIR "${QT_QMAKE_EXECUTABLE}" DIRECTORY) find_program(MACDEPLOYQT_EXECUTABLE macdeployqt HINTS "${QT_BIN_DIR}") diff --git a/src/libsync/CMakeLists.txt b/src/libsync/CMakeLists.txt index 4d1aacd7b1d85..37c8ac3f2c282 100644 --- a/src/libsync/CMakeLists.txt +++ b/src/libsync/CMakeLists.txt @@ -166,7 +166,12 @@ IF (NOT APPLE) ) ENDIF(NOT APPLE) -find_package(Qt5 REQUIRED COMPONENTS WebSockets) +if (Qt6_FOUND) + find_package(Qt6 COMPONENTS REQUIRED WebSockets) +else() + set(REQUIRED_QT_VERSION "5.15.0") + find_package(Qt5 ${REQUIRED_QT_VERSION} COMPONENTS REQUIRED WebSockets) +endif() add_library(nextcloudsync SHARED ${libsync_SRCS}) add_library(Nextcloud::sync ALIAS nextcloudsync) @@ -177,14 +182,19 @@ target_link_libraries(nextcloudsync OpenSSL::Crypto OpenSSL::SSL ${OS_SPECIFIC_LINK_LIBRARIES} - Qt5::Core - Qt5::Network - Qt5::WebSockets + Qt::Core + Qt::Network + Qt::WebSockets ) if (NOT TOKEN_AUTH_ONLY) - find_package(Qt5 REQUIRED COMPONENTS Widgets Svg) - target_link_libraries(nextcloudsync PUBLIC Qt5::Widgets Qt5::Svg qt5keychain) + if (Qt6_FOUND) + find_package(Qt6 COMPONENTS REQUIRED Widgets Svg) + else() + set(REQUIRED_QT_VERSION "5.15.0") + find_package(Qt5 ${REQUIRED_QT_VERSION} COMPONENTS REQUIRED Widgets Svg) + endif() + target_link_libraries(nextcloudsync PUBLIC Qt::Widgets Qt::Svg qt5keychain) endif() if(Inotify_FOUND) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a6e6304c905cc..6433a72aa6694 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,7 +12,7 @@ add_library(testutils testhelper.cpp ) -target_link_libraries(testutils PUBLIC Nextcloud::sync Qt5::Test) +target_link_libraries(testutils PUBLIC Nextcloud::sync Qt::Test) target_include_directories(testutils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(testutils PROPERTIES FOLDER Tests) diff --git a/test/csync/CMakeLists.txt b/test/csync/CMakeLists.txt index a621e5f958401..904828d9e90fc 100644 --- a/test/csync/CMakeLists.txt +++ b/test/csync/CMakeLists.txt @@ -14,7 +14,7 @@ include_directories( add_library(${TORTURE_LIBRARY} STATIC torture.c cmdline.c) target_link_libraries(${TORTURE_LIBRARY} ${CMOCKA_LIBRARIES}) -set(TEST_TARGET_LIBRARIES ${TORTURE_LIBRARY} Qt5::Core Nextcloud::csync) +set(TEST_TARGET_LIBRARIES ${TORTURE_LIBRARY} Qt::Core Nextcloud::csync) # create tests diff --git a/test/nextcloud_add_test.cmake b/test/nextcloud_add_test.cmake index 98f3ef7673cdd..a570fbf01503a 100644 --- a/test/nextcloud_add_test.cmake +++ b/test/nextcloud_add_test.cmake @@ -1,4 +1,9 @@ -find_package(Qt5 COMPONENTS Core Test Xml Network Qml Quick REQUIRED) +if (Qt6_FOUND) + find_package(Qt6 COMPONENTS REQUIRED Core Test Xml Network Qml Quick) +else() + set(REQUIRED_QT_VERSION "5.15.0") + find_package(Qt5 ${REQUIRED_QT_VERSION} COMPONENTS REQUIRED Core Test Xml Network Qml Quick) +endif() macro(nextcloud_add_test test_class) set(CMAKE_AUTOMOC TRUE) @@ -13,8 +18,8 @@ macro(nextcloud_add_test test_class) testutils nextcloudCore cmdCore - Qt5::Test - Qt5::Quick + Qt::Test + Qt::Quick ) if (WIN32) @@ -62,10 +67,10 @@ macro(nextcloud_add_benchmark test_class) testutils nextcloudCore cmdCore - Qt5::Core - Qt5::Test - Qt5::Xml - Qt5::Network + Qt::Core + Qt::Test + Qt::Xml + Qt::Network ) IF(BUILD_UPDATER)