From a577decdc92cd5ce1f659243f293e55742bab01c Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Sun, 20 Jun 2021 18:50:54 +0200 Subject: [PATCH] Add some Qt6 cmake support WebEngine is missing because the current 6.2 installed has a broken WebEngine --- CMakeLists.txt | 3 +-- ScreenPlay/CMakeLists.txt | 38 +++++++++++++----------------- ScreenPlaySDK/CMakeLists.txt | 10 +++++--- ScreenPlayShader/CMakeLists.txt | 11 +++++---- ScreenPlaySysInfo/CMakeLists.txt | 11 ++++++--- ScreenPlayUtil/CMakeLists.txt | 29 +++++++++++------------ ScreenPlayWallpaper/CMakeLists.txt | 26 +++++++++++++------- ScreenPlayWidget/CMakeLists.txt | 12 ++++++---- 8 files changed, 79 insertions(+), 61 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e9ead731..93546d80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,7 @@ elseif(APPLE) set(VCPKG_ARCH "x64-osx") endif() -# Assume built-in pthreads on MacOS -# https://stackoverflow.com/questions/54587052/cmake-on-mac-could-not-find-threads-missing-threads-found +# Assume built-in pthreads on MacOS https://stackoverflow.com/questions/54587052/cmake-on-mac-could-not-find-threads-missing-threads-found if(APPLE) set(CMAKE_THREAD_LIBS_INIT "-lpthread") set(CMAKE_HAVE_THREADS_LIBRARY 1) diff --git a/ScreenPlay/CMakeLists.txt b/ScreenPlay/CMakeLists.txt index af377ef7..53eb6952 100644 --- a/ScreenPlay/CMakeLists.txt +++ b/ScreenPlay/CMakeLists.txt @@ -5,16 +5,17 @@ set(CMAKE_AUTORCC ON) set(CMAKE_AUTOMOC ON) find_package( - Qt5 - COMPONENTS Quick - QuickCompiler - Widgets - Gui - WebEngine - LinguistTools - WebSockets + QT NAMES Qt6 Qt5 + COMPONENTS Quick Widgets Gui LinguistTools WebSockets REQUIRED) +find_package( + Qt${QT_VERSION_MAJOR} + COMPONENTS Quick Widgets Gui LinguistTools WebSockets + REQUIRED) + +message(STATUS "[PROJECT] QT_VERSION_MAJOR = ${QT_VERSION_MAJOR}") + find_package(OpenSSL REQUIRED) find_package(benchmark CONFIG REQUIRED) find_package(doctest CONFIG REQUIRED) @@ -73,10 +74,10 @@ set(l10n translations/ScreenPlay_vi.ts) set_source_files_properties(${l10n} PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/translations") -qt5_add_translation(qmFiles ${l10n}) +qt_add_translation(qmFiles ${l10n}) if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - qt5_add_resources(qml qml.qrc Resources.qrc) + qt_add_resources(qml qml.qrc Resources.qrc) else() qtquick_compiler_add_resources(qml qml.qrc Resources.qrc) endif() @@ -100,12 +101,11 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE "GIT_VERSION=${GIT_VERSION}") target_link_libraries( ${PROJECT_NAME} - PRIVATE Qt5::Quick - Qt5::Gui - Qt5::Widgets - Qt5::Core - Qt5::WebEngine - Qt5::WebSockets + PRIVATE Qt${QT_VERSION_MAJOR}::Quick + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::WebSockets ScreenPlaySDK ScreenPlayUtil benchmark::benchmark @@ -127,10 +127,4 @@ if(WIN32) endforeach() configure_file(${VCPKG_INSTALLED_PATH}/tools/sentry-native/crashpad_handler.exe ${CMAKE_BINARY_DIR}/bin/ COPYONLY) -elseif(APPLE) - # cmake-format: off - # Auto ffmpeg download missing for osx - #configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../Common/ffmpeg/ffmpeg ${CMAKE_BINARY_DIR}/bin/ COPYONLY) - #configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../Common/ffmpeg/ffprobe ${CMAKE_BINARY_DIR}/bin/ COPYONLY) - # cmake-format: on endif() diff --git a/ScreenPlaySDK/CMakeLists.txt b/ScreenPlaySDK/CMakeLists.txt index e5e48a3f..07ac0d61 100644 --- a/ScreenPlaySDK/CMakeLists.txt +++ b/ScreenPlaySDK/CMakeLists.txt @@ -3,9 +3,12 @@ project(ScreenPlaySDK LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOMOC ON) - find_package( - Qt5 + QT NAMES Qt6 Qt5 + COMPONENTS Quick Network Core + REQUIRED) +find_package( + Qt${QT_VERSION_MAJOR} COMPONENTS Quick Network Core REQUIRED) @@ -15,6 +18,7 @@ set(headers inc/screenplay-sdk_plugin.h inc/screenplaysdk.h) add_library(${PROJECT_NAME} ${src} ${headers}) -target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick Qt5::Gui Qt5::Network) +target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Network) target_include_directories(${PROJECT_NAME} PUBLIC inc) diff --git a/ScreenPlayShader/CMakeLists.txt b/ScreenPlayShader/CMakeLists.txt index 158d920b..709245b3 100644 --- a/ScreenPlayShader/CMakeLists.txt +++ b/ScreenPlayShader/CMakeLists.txt @@ -3,9 +3,12 @@ project(ScreenPlayShader LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOMOC ON) - find_package( - Qt5 + QT NAMES Qt6 Qt5 + COMPONENTS Quick Core + REQUIRED) +find_package( + Qt${QT_VERSION_MAJOR} COMPONENTS Quick Core REQUIRED) @@ -17,7 +20,7 @@ set(shader shader.qrc) add_library(${PROJECT_NAME} SHARED ${src} ${headers} ${shader}) -target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick Qt5::Gui) +target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::Gui) target_include_directories(${PROJECT_NAME} PUBLIC inc) @@ -25,7 +28,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC inc) set(URI "ScreenPlay/Shader") string(REPLACE "." "/" TARGETPATH ${URI}) if(NOT DEFINED QT_QMAKE_EXECUTABLE) - get_target_property(QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION) + get_target_property(QT_QMAKE_EXECUTABLE Qt${QT_VERSION_MAJOR}::qmake IMPORTED_LOCATION) if(NOT QT_QMAKE_EXECUTABLE) message(FATAL_ERROR "Cannot find qmake") endif() diff --git a/ScreenPlaySysInfo/CMakeLists.txt b/ScreenPlaySysInfo/CMakeLists.txt index d9fe67ca..4d1bf54e 100644 --- a/ScreenPlaySysInfo/CMakeLists.txt +++ b/ScreenPlaySysInfo/CMakeLists.txt @@ -6,7 +6,12 @@ set(CMAKE_AUTOMOC ON) find_package(infoware CONFIG REQUIRED) find_package( - Qt5 + QT NAMES Qt6 Qt5 + COMPONENTS Quick Core + REQUIRED) + +find_package( + Qt${QT_VERSION_MAJOR} COMPONENTS Quick Core REQUIRED) @@ -31,13 +36,13 @@ set(headers add_library(${PROJECT_NAME} SHARED ${src} ${headers}) -target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick infoware) +target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick infoware) # QML module deployment set(URI "ScreenPlay/Sysinfo") string(REPLACE "." "/" TARGETPATH ${URI}) if(NOT DEFINED QT_QMAKE_EXECUTABLE) - get_target_property(QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION) + get_target_property(QT_QMAKE_EXECUTABLE Qt${QT_VERSION_MAJOR}::qmake IMPORTED_LOCATION) if(NOT QT_QMAKE_EXECUTABLE) message(FATAL_ERROR "Cannot find qmake") endif() diff --git a/ScreenPlayUtil/CMakeLists.txt b/ScreenPlayUtil/CMakeLists.txt index baa75dca..e39867de 100644 --- a/ScreenPlayUtil/CMakeLists.txt +++ b/ScreenPlayUtil/CMakeLists.txt @@ -3,25 +3,24 @@ project(ScreenPlayUtil LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOMOC ON) - find_package( - Qt5 - COMPONENTS Core + QT NAMES Qt6 Qt5 + COMPONENTS Core + REQUIRED) +find_package( + Qt${QT_VERSION_MAJOR} + COMPONENTS Core REQUIRED) -set(SOURCES - src/util.cpp - src/contenttypes.cpp - ) +set(SOURCES src/util.cpp src/contenttypes.cpp) -set(HEADER - inc/public/ScreenPlayUtil/util.h - inc/public/ScreenPlayUtil/contenttypes.h - inc/public/ScreenPlayUtil/projectfile.h - ) +set(HEADER inc/public/ScreenPlayUtil/util.h inc/public/ScreenPlayUtil/contenttypes.h inc/public/ScreenPlayUtil/projectfile.h) -add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADER}) +add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADER}) -target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core ) +target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core) -target_include_directories(${PROJECT_NAME} PUBLIC inc/public/ PRIVATE src/) +target_include_directories( + ${PROJECT_NAME} + PUBLIC inc/public/ + PRIVATE src/) diff --git a/ScreenPlayWallpaper/CMakeLists.txt b/ScreenPlayWallpaper/CMakeLists.txt index 5e63bd3b..c16aee18 100644 --- a/ScreenPlayWallpaper/CMakeLists.txt +++ b/ScreenPlayWallpaper/CMakeLists.txt @@ -3,10 +3,13 @@ project(ScreenPlayWallpaper LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOMOC ON) - find_package( - Qt5 - COMPONENTS Quick Widgets Gui WebEngine QuickCompiler + QT NAMES Qt6 Qt5 + COMPONENTS Quick Widgets Gui + REQUIRED) +find_package( + Qt${QT_VERSION_MAJOR} + COMPONENTS Quick Widgets Gui WebEngine REQUIRED) if(WIN32) @@ -35,14 +38,21 @@ if(WIN32) # Disable console window on Windows # https://stackoverflow.com/questions/8249028/how-do-i-keep-my-qt-c-program-from-opening-a-console-in-windows set_property(TARGET ${PROJECT_NAME} PROPERTY WIN32_EXECUTABLE true) - target_link_libraries(${PROJECT_NAME} PRIVATE shcore.lib ) + target_link_libraries(${PROJECT_NAME} PRIVATE shcore.lib) endif() if(APPLE) set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE true) - target_link_libraries(${PROJECT_NAME} PRIVATE "-framework Cocoa") + target_link_libraries(${PROJECT_NAME} PRIVATE "-framework Cocoa") endif() -target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Quick Qt5::Gui Qt5::Widgets Qt5::Core Qt5::WebEngine shcore.lib ScreenPlaySDK ScreenPlayUtil) - - +target_link_libraries( + ${PROJECT_NAME} + PRIVATE Qt${QT_VERSION_MAJOR}::Quick + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::WebEngine + shcore.lib + ScreenPlaySDK + ScreenPlayUtil) diff --git a/ScreenPlayWidget/CMakeLists.txt b/ScreenPlayWidget/CMakeLists.txt index dbc1b9e3..dd21044f 100644 --- a/ScreenPlayWidget/CMakeLists.txt +++ b/ScreenPlayWidget/CMakeLists.txt @@ -3,10 +3,13 @@ project(ScreenPlayWidget LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOMOC ON) - find_package( - Qt5 - COMPONENTS Quick Widgets Gui QuickCompiler WebEngine + QT NAMES Qt6 Qt5 + COMPONENTS Quick Widgets Gui + REQUIRED) +find_package( + Qt${QT_VERSION_MAJOR} + COMPONENTS Quick Widgets Gui WebEngine REQUIRED) set(src main.cpp src/widgetwindow.cpp) @@ -31,4 +34,5 @@ if(APPLE) set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE true) endif() -target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Quick Qt5::Gui Qt5::Widgets Qt5::Core ScreenPlaySDK ScreenPlayUtil) +target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Core ScreenPlaySDK ScreenPlayUtil)