Skip to content

Commit

Permalink
cmake: Add support for Qt6
Browse files Browse the repository at this point in the history
Fixes #811
  • Loading branch information
Xaymar committed Aug 6, 2022
1 parent 3901f3c commit efa4690
Showing 1 changed file with 93 additions and 35 deletions.
128 changes: 93 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function(parse_version_string)
"INPUT;OUTPUT"
""
)

set(_tmp_MAJOR 0)
set(_tmp_MINOR 0)
set(_tmp_PATCH 0)
Expand All @@ -79,7 +79,7 @@ function(parse_version_string)
# Replace separators with list separators
string(REPLACE "-" "." _tmp "${_ARGS_INPUT}")
string(REPLACE "." ";" _tmp "${_tmp}")

# Parse version differently depending on total string length.
list(LENGTH _tmp _tmp_len)
if(_tmp_len GREATER_EQUAL 1) # A[...]
Expand Down Expand Up @@ -112,7 +112,7 @@ function(parse_version_string)
if(T_MATCHES)
set(_tmp_PATCH ${CMAKE_MATCH_1})
set(_tmp_STAGE ${CMAKE_MATCH_2})
set(_tmp_TWEAK ${CMAKE_MATCH_3})
set(_tmp_TWEAK ${CMAKE_MATCH_3})
endif()
endif()

Expand All @@ -128,7 +128,7 @@ endfunction()
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
set(VERSION_BASE "0.11.0") # Automatic versioning base
set(VERSION_TARGET "0.12.0") # Automatic versioning target

# Parse target version as it is for output.
parse_version_string(OUTPUT "VERSION" INPUT "${VERSION_TARGET}")

Expand All @@ -142,7 +142,7 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git")
)

if(GIT)
# Tweak
# Tweak
execute_process(
COMMAND "${GIT}" describe --tags --long --match "${VERSION_BASE}" --abbrev=8 HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
Expand Down Expand Up @@ -190,7 +190,7 @@ endif()
# Allow manual overrides of the detected version.
set(${PREFIX}VERSION "" CACHE STRING "Override StreamFX version with this string. Format: Major.Minor.Patch[Stage][Tweak[-Commit8c]]")
if(NOT (${PREFIX}VERSION STREQUAL ""))
parse_version_string(OUTPUT "VERSION" INPUT "${${PREFIX}VERSION}")
parse_version_string(OUTPUT "VERSION" INPUT "${${PREFIX}VERSION}")
endif()

# Generate Version String
Expand Down Expand Up @@ -963,7 +963,7 @@ endfunction()
function(feature_frontend RESOLVE)
is_feature_enabled(FRONTEND T_CHECK)
if(RESOLVE AND T_CHECK)
if(NOT HAVE_QT)
if(NOT (Qt6_FOUND OR Qt5_FOUND))
message(WARNING "${LOGPREFIX}Front-End requires Qt. Disabling...")
set_feature_disabled(FRONTEND ON)
elseif(NOT HAVE_OBS_FRONTEND_API)
Expand Down Expand Up @@ -1160,12 +1160,43 @@ if(REQUIRE_NVIDIA_CUDA AND D_PLATFORM_WINDOWS)
endif()

#- Qt5
set(HAVE_QT OFF)
if(REQUIRE_QT)
find_package(Qt5
COMPONENTS Widgets Core REQUIRED
)
set(HAVE_QT ${Qt5_FOUND})
find_package(Qt6
COMPONENTS Core Widgets
CONFIG
HINTS
"${Qt6_DIR}"
"${Qt6_DIR}/lib"
"${Qt6_DIR}/lib/cmake"
"${Qt6_DIR}/lib/cmake/Qt6"
"${QTDIR}"
"${QTDIR}/lib"
"${QTDIR}/lib/cmake"
"${QTDIR}/lib/cmake/Qt6"
"${DepsPath}"
"${DepsPath}/lib"
"${DepsPath}/lib/cmake"
"${DepsPath}/lib/cmake/Qt6"
)
if(NOT Qt6_FOUND)
find_package(Qt5
COMPONENTS Core Widgets
CONFIG
HINTS
"${Qt5_DIR}"
"${Qt5_DIR}/lib"
"${Qt5_DIR}/lib/cmake"
"${Qt5_DIR}/lib/cmake/Qt5"
"${QTDIR}"
"${QTDIR}/lib"
"${QTDIR}/lib/cmake"
"${QTDIR}/lib/cmake/Qt5"
"${DepsPath}"
"${DepsPath}/lib"
"${DepsPath}/lib/cmake"
"${DepsPath}/lib/cmake/Qt5"
)
endif()
endif()

# Verify Requirements
Expand Down Expand Up @@ -1367,8 +1398,12 @@ if(REQUIRE_OBS_FRONTEND_API AND HAVE_OBS_FRONTEND_API)
list(APPEND PROJECT_LIBRARIES obs-frontend-api)
endif()

if(REQUIRE_QT AND HAVE_QT)
list(APPEND PROJECT_LIBRARIES Qt5::Core Qt5::Widgets)
if(REQUIRE_QT)
if(Qt5_FOUND)
list(APPEND PROJECT_LIBRARIES Qt5::Core Qt5::Widgets)
elseif(Qt6_FOUND)
list(APPEND PROJECT_LIBRARIES Qt6::Core Qt6::Widgets)
endif()
endif()

################################################################################
Expand Down Expand Up @@ -2013,7 +2048,7 @@ set_source_files_properties(${PROJECT_DATA} ${PROJECT_TEMPLATES} ${PROJECT_UI} P
)

# Prevent non-UI files from being Qt'd
if(HAVE_QT)
if(Qt5_Found OR Qt6_FOUND)
set_source_files_properties(${PROJECT_DATA} ${PROJECT_TEMPLATES} ${PROJECT_PRIVATE_GENERATED} ${PROJECT_PRIVATE_SOURCE} PROPERTIES
SKIP_AUTOGEN ON
SKIP_AUTOMOC ON
Expand Down Expand Up @@ -2259,7 +2294,7 @@ if(D_PLATFORM_WINDOWS)
endif()

# Enable Qt if needed
if(HAVE_QT)
if(Qt5_FOUND OR Qt6_FOUND)
set_target_properties(${PROJECT_NAME} PROPERTIES
AUTOUIC ON
AUTOUIC_SEARCH_PATHS "${PROJECT_SOURCE_DIR};${PROJECT_SOURCE_DIR}/ui"
Expand Down Expand Up @@ -2316,28 +2351,51 @@ if(D_PLATFORM_MAC)
message(STATUS "${LOGPREFIX}Added post-build step for adjusting libobs-frontend-api linking path.")
endif()

# Qt5
if(REQUIRE_QT AND HAVE_QT)
# Figure out the linker location for Qt5::Core
mac_get_linker_id(TARGET Qt5::Core OUTPUT T_QT5CORE_LINK)
# Qt
if(REQUIRE_QT)
if(Qt5_FOUND)
# Figure out the linker location for Qt5::Core
mac_get_linker_id(TARGET Qt5::Core OUTPUT T_QT5CORE_LINK)

# Figure out the linker location for Qt5::Gui
mac_get_linker_id(TARGET Qt5::Gui OUTPUT T_QT5GUI_LINK)
# Figure out the linker location for Qt5::Gui
mac_get_linker_id(TARGET Qt5::Gui OUTPUT T_QT5GUI_LINK)

# Figure out the linker location for Qt5::Widsgets
mac_get_linker_id(TARGET Qt5::Widgets OUTPUT T_QT5WIDGETS_LINK)
# Figure out the linker location for Qt5::Widsgets
mac_get_linker_id(TARGET Qt5::Widgets OUTPUT T_QT5WIDGETS_LINK)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
# - QtCore
COMMAND install_name_tool ARGS -change "${T_QT5CORE_LINK}" "@executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore" $<TARGET_FILE:${PROJECT_NAME}>
# - QtGui
COMMAND install_name_tool ARGS -change "${T_QT5GUI_LINK}" "@executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui" $<TARGET_FILE:${PROJECT_NAME}>
# - QtWidgets
COMMAND install_name_tool ARGS -change "${T_QT5WIDGETS_LINK}" "@executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets" $<TARGET_FILE:${PROJECT_NAME}>
)
message(STATUS "${LOGPREFIX}Added post-build step for adjusting Qt5::Core linking path (Found: ${Qt5_DIR} resolved to ${T_QT5CORE_LINK}).")
message(STATUS "${LOGPREFIX}Added post-build step for adjusting Qt5::Gui linking path (Found: ${Qt5_DIR} resolved to ${T_QT5GUI_LINK}).")
message(STATUS "${LOGPREFIX}Added post-build step for adjusting Qt5::Widgets linking path (Found: ${Qt5_DIR} resolved to ${T_QT5WIDGETS_LINK}).")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
# - QtCore
COMMAND install_name_tool ARGS -change "${T_QT5CORE_LINK}" "@executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore" $<TARGET_FILE:${PROJECT_NAME}>
# - QtGui
COMMAND install_name_tool ARGS -change "${T_QT5GUI_LINK}" "@executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui" $<TARGET_FILE:${PROJECT_NAME}>
# - QtWidgets
COMMAND install_name_tool ARGS -change "${T_QT5WIDGETS_LINK}" "@executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets" $<TARGET_FILE:${PROJECT_NAME}>
)
message(STATUS "${LOGPREFIX}Added post-build step for adjusting Qt5::Core linking path (Found: ${Qt5_DIR} resolved to ${T_QT5CORE_LINK}).")
message(STATUS "${LOGPREFIX}Added post-build step for adjusting Qt5::Gui linking path (Found: ${Qt5_DIR} resolved to ${T_QT5GUI_LINK}).")
message(STATUS "${LOGPREFIX}Added post-build step for adjusting Qt5::Widgets linking path (Found: ${Qt5_DIR} resolved to ${T_QT5WIDGETS_LINK}).")
elseif(Qt6_FOUND)
# Figure out the linker location for Qt6::Core
mac_get_linker_id(TARGET Qt6::Core OUTPUT T_QT6CORE_LINK)

# Figure out the linker location for Qt6::Gui
mac_get_linker_id(TARGET Qt6::Gui OUTPUT T_QT6GUI_LINK)

# Figure out the linker location for Qt6::Widsgets
mac_get_linker_id(TARGET Qt6::Widgets OUTPUT T_QT6WIDGETS_LINK)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
# - QtCore
COMMAND install_name_tool ARGS -change "${T_QT6CORE_LINK}" "@executable_path/../Frameworks/QtCore.framework/Versions/6/QtCore" $<TARGET_FILE:${PROJECT_NAME}>
# - QtGui
COMMAND install_name_tool ARGS -change "${T_QT6GUI_LINK}" "@executable_path/../Frameworks/QtGui.framework/Versions/6/QtGui" $<TARGET_FILE:${PROJECT_NAME}>
# - QtWidgets
COMMAND install_name_tool ARGS -change "${T_QT6WIDGETS_LINK}" "@executable_path/../Frameworks/QtWidgets.framework/Versions/6/QtWidgets" $<TARGET_FILE:${PROJECT_NAME}>
)
message(STATUS "${LOGPREFIX}Added post-build step for adjusting Qt6::Core linking path (Found: ${Qt6_DIR} resolved to ${T_QT6CORE_LINK}).")
message(STATUS "${LOGPREFIX}Added post-build step for adjusting Qt6::Gui linking path (Found: ${Qt6_DIR} resolved to ${T_QT6GUI_LINK}).")
message(STATUS "${LOGPREFIX}Added post-build step for adjusting Qt6::Widgets linking path (Found: ${Qt6_DIR} resolved to ${T_QT6WIDGETS_LINK}).")
endif()
endif()
endif()

Expand Down

0 comments on commit efa4690

Please sign in to comment.