1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-25 12:13:00 +01:00

Add Qt5 and Qt6 compatibility to CMake

Because the WebEngine got renamed we have
to make it this ugly. This will only work with Qt5
for now because Qt6 still breaks things.
This commit is contained in:
Elias Steurer 2021-07-11 08:27:13 +02:00
parent 2fb9e728d0
commit d5276b8169
7 changed files with 206 additions and 136 deletions

View File

@ -4,25 +4,12 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)
find_package(
QT NAMES Qt6 Qt5
COMPONENTS Quick Widgets Gui LinguistTools Svg WebSockets WebEngine QuickCompiler
REQUIRED)
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Quick Widgets Gui LinguistTools Svg WebSockets WebEngine QuickCompiler
REQUIRED)
message(STATUS "[PROJECT] QT_VERSION_MAJOR = ${QT_VERSION_MAJOR}")
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core)
find_package(OpenSSL REQUIRED)
find_package(benchmark CONFIG REQUIRED)
find_package(doctest CONFIG REQUIRED)
# CURL must be included before sentry
# because sentry needs the module
# and does not include it itself on macos...
# CURL must be included before sentry because sentry needs the module and does not include it itself on macos...
find_package(CURL CONFIG REQUIRED)
find_package(sentry CONFIG REQUIRED)
@ -77,16 +64,85 @@ set(l10n
set_source_files_properties(${l10n} PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/translations")
qt5_add_translation(qmFiles ${l10n})
qt5_add_big_resources(fonts fonts.qrc)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Core
Quick
Gui
Widgets
WebSockets
Svg
WebEngineCore
WebEngineQuick
WebChannel
Positioning
LinguistTools)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
qt5_add_resources(qml qml.qrc assets.qrc)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
qt_add_resources(qml qml.qrc assets.qrc)
else()
qtquick_compiler_add_resources(qml qml.qrc assets.qrc)
endif()
add_executable(${PROJECT_NAME} ${src} ${headers} ${resources} ${qml} ${fonts})
target_link_libraries(
${PROJECT_NAME}
PRIVATE ScreenPlaySDK
ScreenPlayUtil
benchmark::benchmark
benchmark::benchmark_main
doctest::doctest
sentry::sentry
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
Qt${QT_VERSION_MAJOR}::Svg
Qt6::WebEngineCore
Qt6::WebEngineQuick)
qt_add_translation(qmFiles ${l10n})
else()
qtquick_compiler_add_resources(qml qml.qrc assets.qrc)
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Core
Quick
Gui
Widgets
WebSockets
Svg
LinguistTools
WebEngine)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
qt_add_resources(qml qml.qrc assets.qrc)
else()
qtquick_compiler_add_resources(qml qml.qrc assets.qrc)
endif()
add_executable(${PROJECT_NAME} ${src} ${headers} ${resources} ${qml} ${fonts})
target_link_libraries(
${PROJECT_NAME}
PRIVATE ScreenPlaySDK
ScreenPlayUtil
benchmark::benchmark
benchmark::benchmark_main
doctest::doctest
sentry::sentry
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
Qt${QT_VERSION_MAJOR}::Svg
Qt5::WebEngine)
qt5_add_translation(qmFiles ${l10n})
endif()
add_executable(${PROJECT_NAME} ${src} ${headers} ${resources} ${qml} ${fonts})
qt_add_big_resources(fonts fonts.qrc)
target_compile_definitions(${PROJECT_NAME} PRIVATE "GIT_VERSION=${GIT_VERSION}")
@ -110,54 +166,37 @@ endif()
if(APPLE)
# Creates a ScreenPlay.app
set_target_properties(${PROJECT_NAME} PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}
MACOSX_BUNDLE TRUE
MACOSX_RPATH TRUE
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
MACOSX_FRAMEWORK_IDENTIFIER screen-play.app
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@loader_path/Libraries"
RESOURCE "${RESOURCE_FILES}"
XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME TRUE
XCODE_ATTRIBUTE_EXECUTABLE_NAME ${PROJECT_NAME}
)
set_target_properties(
${PROJECT_NAME}
PROPERTIES OUTPUT_NAME ${PROJECT_NAME}
MACOSX_BUNDLE TRUE
MACOSX_RPATH TRUE
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
MACOSX_FRAMEWORK_IDENTIFIER screen-play.app
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@loader_path/Libraries"
RESOURCE "${RESOURCE_FILES}"
XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME TRUE
XCODE_ATTRIBUTE_EXECUTABLE_NAME ${PROJECT_NAME})
# Needed for the Steam Workshop qml plugin
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/Workshop)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/../Common/ffmpeg/ffmpeg
${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/ )
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/../Common/ffmpeg/ffmpeg
${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/../Common/ffmpeg/ffprobe
${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/ )
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/../Common/ffmpeg/ffprobe
${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${VCPKG_INSTALLED_PATH}/tools/sentry-native/crashpad_handler
${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/ )
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${VCPKG_INSTALLED_PATH}/tools/sentry-native/crashpad_handler
${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/)
endif()
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}::WebSockets
Qt${QT_VERSION_MAJOR}::WebEngine
Qt${QT_VERSION_MAJOR}::Svg
ScreenPlaySDK
ScreenPlayUtil
benchmark::benchmark
benchmark::benchmark_main
doctest::doctest
sentry::sentry)

View File

@ -20,10 +20,5 @@ add_library(${PROJECT_NAME} ${src} ${headers})
target_include_directories(${PROJECT_NAME} PUBLIC inc)
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_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)

View File

@ -42,24 +42,18 @@ file(MAKE_DIRECTORY ${DESTDIR})
configure_file(qmldir ${DESTDIR} COPYONLY)
if(APPLE)
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMENT "Copying into ScreenPlay.app bundle"
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bin/$<TARGET_FILE_NAME:${PROJECT_NAME}>
${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/$<TARGET_FILE_NAME:${PROJECT_NAME}>)
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMENT "Copying into ScreenPlay.app bundle"
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/bin/$<TARGET_FILE_NAME:${PROJECT_NAME}>
${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/$<TARGET_FILE_NAME:${PROJECT_NAME}>)
else()
# Copies ScreenPlayShader.* into qt qml plugins folder
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:ScreenPlayShader>
${DESTDIR}/$<TARGET_FILE_NAME:ScreenPlayShader>)
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:ScreenPlayShader> ${DESTDIR}/$<TARGET_FILE_NAME:ScreenPlayShader>)
endif()
target_link_libraries(
${PROJECT_NAME}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::Gui)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick Qt${QT_VERSION_MAJOR}::Gui)

View File

@ -61,9 +61,4 @@ add_custom_command(
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:ScreenPlaySysInfo> ${DESTDIR}/$<TARGET_FILE_NAME:ScreenPlaySysInfo>)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Quick
infoware)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick infoware)

View File

@ -23,7 +23,4 @@ target_include_directories(
PUBLIC inc/public/
PRIVATE src/)
target_link_libraries(
${PROJECT_NAME}
PRIVATE
Qt${QT_VERSION_MAJOR}::Core)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core)

View File

@ -3,14 +3,8 @@ project(ScreenPlayWallpaper LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)
find_package(
QT NAMES Qt6 Qt5
COMPONENTS Quick Widgets Gui WebEngine QuickCompiler
REQUIRED)
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Quick Widgets Gui WebEngine QuickCompiler
REQUIRED)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core)
if(WIN32)
set(src_plattform src/windowsdesktopproperties.cpp src/winwindow.cpp)
@ -42,21 +36,52 @@ if(WIN32)
endif()
if(APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
)
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
target_link_libraries(${PROJECT_NAME} PRIVATE "-framework Cocoa")
endif()
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
ScreenPlaySDK
ScreenPlayUtil)
target_link_libraries(${PROJECT_NAME} PRIVATE ScreenPlaySDK ScreenPlayUtil)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Core
Quick
Gui
Widgets
WebSockets
Svg
WebEngineCore
WebEngineQuick
WebChannel
Positioning)
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}::WebSockets
Qt${QT_VERSION_MAJOR}::Svg
Qt6::WebEngineCore
Qt6::WebEngineQuick)
else()
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Core
Quick
Gui
Widgets
WebSockets
Svg
WebEngine)
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}::WebSockets
Qt${QT_VERSION_MAJOR}::Svg
Qt5::WebEngine)
endif()

View File

@ -3,15 +3,8 @@ project(ScreenPlayWidget LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)
find_package(
QT NAMES Qt6 Qt5
COMPONENTS Quick Widgets Gui WebEngine QuickCompiler
REQUIRED)
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Quick Widgets Gui WebEngine QuickCompiler
REQUIRED)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core)
set(src main.cpp src/widgetwindow.cpp)
set(headers src/widgetwindow.h)
@ -31,19 +24,51 @@ if(WIN32)
endif()
if(APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
)
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
endif()
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
ScreenPlaySDK
ScreenPlayUtil)
target_link_libraries(${PROJECT_NAME} PRIVATE ScreenPlaySDK ScreenPlayUtil)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Core
Quick
Gui
Widgets
WebSockets
Svg
WebEngineCore
WebEngineQuick
WebChannel
Positioning)
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}::WebSockets
Qt${QT_VERSION_MAJOR}::Svg
Qt6::WebEngineCore
Qt6::WebEngineQuick)
else()
find_package(
Qt${QT_VERSION_MAJOR}
COMPONENTS Core
Quick
Gui
Widgets
WebSockets
Svg
WebEngine)
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}::WebSockets
Qt${QT_VERSION_MAJOR}::Svg
Qt5::WebEngine)
endif()