Skip to content

Commit

Permalink
allow detection of qt5 or qt6
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed May 20, 2022
1 parent cb8cc2a commit f78dbf3
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 7 additions & 2 deletions shell_integration/libcloudproviders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
16 changes: 12 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/csync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
75 changes: 52 additions & 23 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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}")

Expand Down
22 changes: 16 additions & 6 deletions src/libsync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion test/csync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 12 additions & 7 deletions test/nextcloud_add_test.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -13,8 +18,8 @@ macro(nextcloud_add_test test_class)
testutils
nextcloudCore
cmdCore
Qt5::Test
Qt5::Quick
Qt::Test
Qt::Quick
)

if (WIN32)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f78dbf3

Please sign in to comment.