diff --git a/cmake/Modules/ObsDefaults_Linux.cmake b/cmake/Modules/ObsDefaults_Linux.cmake index 0442367d8..d1e58a083 100644 --- a/cmake/Modules/ObsDefaults_Linux.cmake +++ b/cmake/Modules/ObsDefaults_Linux.cmake @@ -68,23 +68,22 @@ macro(setup_obs_project) set(OBS_INCLUDE_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/obs") set(OBS_LIBRARY_DESTINATION "${CMAKE_INSTALL_LIBDIR}") set(OBS_PLUGIN_DESTINATION "${OBS_LIBRARY_DESTINATION}/obs-plugins") - set(OBS_SCRIPT_PLUGIN_DESTINATION - "${OBS_LIBRARY_DESTINATION}/obs-scripting") + set(OBS_PLUGIN_PATH "${OBS_PLUGIN_DESTINATION}") + set(OBS_SCRIPT_PLUGIN_DESTINATION "${OBS_LIBRARY_DESTINATION}/obs-scripting") set(OBS_DATA_DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/obs") set(OBS_CMAKE_DESTINATION "${OBS_LIBRARY_DESTINATION}/cmake") set(OBS_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/") set(OBS_DATA_PATH "${OBS_DATA_DESTINATION}") - set(OBS_SCRIPT_PLUGIN_PATH - "${CMAKE_INSTALL_PREFIX}/${OBS_SCRIPT_PLUGIN_DESTINATION}") - set(CMAKE_INSTALL_RPATH - "${CMAKE_INSTALL_PREFIX}/${OBS_LIBRARY_DESTINATION}") + set(OBS_SCRIPT_PLUGIN_PATH "${CMAKE_INSTALL_PREFIX}/${OBS_SCRIPT_PLUGIN_DESTINATION}") + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${OBS_LIBRARY_DESTINATION}") else() set(OBS_EXECUTABLE_DESTINATION "bin/${_ARCH_SUFFIX}bit") set(OBS_INCLUDE_DESTINATION "include") set(OBS_LIBRARY_DESTINATION "bin/${_ARCH_SUFFIX}bit") set(OBS_PLUGIN_DESTINATION "obs-plugins/${_ARCH_SUFFIX}bit") + set(OBS_PLUGIN_PATH "../../${OBS_PLUGIN_DESTINATION}") set(OBS_SCRIPT_PLUGIN_DESTINATION "data/obs-scripting/${_ARCH_SUFFIX}bit") set(OBS_DATA_DESTINATION "data") set(OBS_CMAKE_DESTINATION "cmake") @@ -93,8 +92,7 @@ macro(setup_obs_project) set(OBS_DATA_PATH "../../${OBS_DATA_DESTINATION}") set(OBS_SCRIPT_PLUGIN_PATH "../../${OBS_SCRIPT_PLUGIN_DESTINATION}") - set(CMAKE_INSTALL_RPATH "$ORIGIN/" - "$ORIGIN/../../${OBS_LIBRARY_DESTINATION}") + set(CMAKE_INSTALL_RPATH "$ORIGIN/" "$ORIGIN/../../${OBS_LIBRARY_DESTINATION}") endif() if(BUILD_FOR_PPA) @@ -111,8 +109,7 @@ macro(setup_obs_project) set(CPACK_PACKAGE_VENDOR "${OBS_WEBSITE}") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${OBS_COMPANY_NAME}") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${OBS_COMMENTS}") - set(CPACK_RESOURCE_FILE_LICENSE - "${CMAKE_SOURCE_DIR}/UI/data/license/gplv2.txt") + set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/UI/data/license/gplv2.txt") set(CPACK_PACKAGE_VERSION "${OBS_VERSION_CANONICAL}-${OBS_BUILD_NUMBER}") set(CPACK_PACKAGE_EXECUTABLES "obs") @@ -122,8 +119,7 @@ macro(setup_obs_project) set(CPACK_SET_DESTDIR ON) set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON) elseif(OS_FREEBSD) - option(ENABLE_CPACK_GENERATOR - "Enable FreeBSD CPack generator (experimental)" OFF) + option(ENABLE_CPACK_GENERATOR "Enable FreeBSD CPack generator (experimental)" OFF) if(ENABLE_CPACK_GENERATOR) set(CPACK_GENERATOR "FreeBSD") diff --git a/cmake/Modules/ObsDefaults_Windows.cmake b/cmake/Modules/ObsDefaults_Windows.cmake index 67139c535..ce9f27aa2 100644 --- a/cmake/Modules/ObsDefaults_Windows.cmake +++ b/cmake/Modules/ObsDefaults_Windows.cmake @@ -39,6 +39,7 @@ macro(setup_obs_project) set(OBS_LIBRARY_EXPORT_DESTINATION "bin/${_ARCH_SUFFIX}bit") set(OBS_PLUGIN_DESTINATION "obs-plugins/${_ARCH_SUFFIX}bit") + set(OBS_PLUGIN_PATH "../../${OBS_PLUGIN_DESTINATION}") set(OBS_PLUGIN32_DESTINATION "obs-plugins/32bit") set(OBS_PLUGIN64_DESTINATION "obs-plugins/64bit") @@ -48,8 +49,7 @@ macro(setup_obs_project) set(OBS_DATA_PATH "../../${OBS_DATA_DESTINATION}") set(OBS_INSTALL_PREFIX "") - set(OBS_SCRIPT_PLUGIN_DESTINATION - "${OBS_DATA_DESTINATION}/obs-scripting/${_ARCH_SUFFIX}bit") + set(OBS_SCRIPT_PLUGIN_DESTINATION "${OBS_DATA_DESTINATION}/obs-scripting/${_ARCH_SUFFIX}bit") set(OBS_SCRIPT_PLUGIN_PATH "../../${OBS_SCRIPT_PLUGIN_DESTINATION}") string(REPLACE "-" ";" UI_VERSION_SPLIT ${OBS_VERSION}) @@ -62,10 +62,7 @@ macro(setup_obs_project) if(INSTALLER_RUN AND NOT DEFINED ENV{OBS_InstallerTempDir} AND NOT DEFINED ENV{obsInstallerTempDir}) - message( - FATAL_ERROR - "Environment variable obsInstallerTempDir is needed for multiarch installer generation" - ) + message(FATAL_ERROR "Environment variable obsInstallerTempDir is needed for multiarch installer generation") endif() if(DEFINED ENV{OBS_DepsPath${_ARCH_SUFFIX}}) @@ -89,19 +86,16 @@ macro(setup_obs_project) endif() if(DEFINED DepsPath${_ARCH_SUFFIX}) - list(APPEND CMAKE_PREFIX_PATH "${DepsPath${_ARCH_SUFFIX}}" - "${DepsPath${_ARCH_SUFFIX}}/bin") + list(APPEND CMAKE_PREFIX_PATH "${DepsPath${_ARCH_SUFFIX}}" "${DepsPath${_ARCH_SUFFIX}}/bin") elseif(DEFINED DepsPath) list(APPEND CMAKE_PREFIX_PATH "${DepsPath}" "${DepsPath}/bin") elseif(NOT DEFINED CMAKE_PREFIX_PATH) message( - WARNING - "No CMAKE_PREFIX_PATH set: OBS requires pre-built dependencies for building on Windows." - "Please download the appropriate obs-deps package for your architecture and set CMAKE_PREFIX_PATH " - "to the base directory and 'bin' directory inside it:\n" - "CMAKE_PREFIX_PATH=\"\"\n" - "Download pre-built OBS dependencies at https://github.com/obsproject/obs-deps/releases\n" - ) + WARNING "No CMAKE_PREFIX_PATH set: OBS requires pre-built dependencies for building on Windows." + "Please download the appropriate obs-deps package for your architecture and set CMAKE_PREFIX_PATH " + "to the base directory and 'bin' directory inside it:\n" + "CMAKE_PREFIX_PATH=\"\"\n" + "Download pre-built OBS dependencies at https://github.com/obsproject/obs-deps/releases\n") endif() if(DEFINED QTDIR${_ARCH_SUFFIX}) @@ -146,8 +140,7 @@ macro(setup_obs_project) set(ENV{OBS_AdditionalInstallFiles} "${_ADDITIONAL_FILES}") unset(_ADDITIONAL_FILES) - list(APPEND CMAKE_INCLUDE_PATH - "$ENV{OBS_AdditionalInstallFiles}/include${_ARCH_SUFFIX}" + list(APPEND CMAKE_INCLUDE_PATH "$ENV{OBS_AdditionalInstallFiles}/include${_ARCH_SUFFIX}" "$ENV{OBS_AdditionalInstallFiles}/include") list( diff --git a/cmake/Modules/ObsHelpers.cmake b/cmake/Modules/ObsHelpers.cmake index a5df070f4..5dc75b8ef 100644 --- a/cmake/Modules/ObsHelpers.cmake +++ b/cmake/Modules/ObsHelpers.cmake @@ -18,22 +18,20 @@ endif() # Create global property to hold list of activated modules set_property(GLOBAL PROPERTY OBS_MODULE_LIST "") -# ############################################################################## +# ###################################################################################################################### # GLOBAL HELPER FUNCTIONS # -# ############################################################################## +# ###################################################################################################################### # Helper function to set up runtime or library targets function(setup_binary_target target) # Set up installation paths for program install install( TARGETS ${target} - RUNTIME DESTINATION ${OBS_EXECUTABLE_DESTINATION} - COMPONENT ${target}_Runtime + RUNTIME DESTINATION ${OBS_EXECUTABLE_DESTINATION} COMPONENT ${target}_Runtime LIBRARY DESTINATION ${OBS_LIBRARY_DESTINATION} COMPONENT ${target}_Runtime NAMELINK_COMPONENT ${target}_Development - ARCHIVE DESTINATION ${OBS_LIBRARY_DESTINATION} - COMPONENT ${target}_Development + ARCHIVE DESTINATION ${OBS_LIBRARY_DESTINATION} COMPONENT ${target}_Development PUBLIC_HEADER DESTINATION ${OBS_INCLUDE_DESTINATION} COMPONENT ${target}_Development @@ -56,10 +54,8 @@ function(setup_binary_target target) add_custom_command( TARGET ${target} POST_BUILD - COMMAND - "${CMAKE_COMMAND}" -E env DESTDIR= "${CMAKE_COMMAND}" --install .. - --config $ --prefix ${OBS_OUTPUT_DIR}/$ --component - obs_${target} > "$,nul,/dev/null>" + COMMAND "${CMAKE_COMMAND}" -E env DESTDIR= "${CMAKE_COMMAND}" --install .. --config $ --prefix + ${OBS_OUTPUT_DIR}/$ --component obs_${target} > "$,nul,/dev/null>" COMMENT "Installing OBS rundir" VERBATIM) @@ -90,10 +86,8 @@ function(setup_plugin_target target) add_custom_command( TARGET ${target} POST_BUILD - COMMAND - "${CMAKE_COMMAND}" -E env DESTDIR= "${CMAKE_COMMAND}" --install .. - --config $ --prefix ${OBS_OUTPUT_DIR}/$ --component - obs_${target} > "$,nul,/dev/null>" + COMMAND "${CMAKE_COMMAND}" -E env DESTDIR= "${CMAKE_COMMAND}" --install .. --config $ --prefix + ${OBS_OUTPUT_DIR}/$ --component obs_${target} > "$,nul,/dev/null>" COMMENT "Installing ${target} to OBS rundir" VERBATIM) @@ -130,10 +124,8 @@ function(setup_script_plugin_target target) add_custom_command( TARGET ${target} POST_BUILD - COMMAND - "${CMAKE_COMMAND}" -E env DESTDIR= "${CMAKE_COMMAND}" --install .. - --config $ --prefix ${OBS_OUTPUT_DIR}/$ --component - obs_${target} > "$,nul,/dev/null>" + COMMAND "${CMAKE_COMMAND}" -E env DESTDIR= "${CMAKE_COMMAND}" --install .. --config $ --prefix + ${OBS_OUTPUT_DIR}/$ --component obs_${target} > "$,nul,/dev/null>" COMMENT "Installing ${target} to OBS rundir" VERBATIM) @@ -182,8 +174,7 @@ function(setup_obs_app target) add_dependencies(${target} ${OBS_MODULE_LIST}) endif() - get_property(OBS_SCRIPTING_MODULE_LIST GLOBAL - PROPERTY OBS_SCRIPTING_MODULE_LIST) + get_property(OBS_SCRIPTING_MODULE_LIST GLOBAL PROPERTY OBS_SCRIPTING_MODULE_LIST) list(LENGTH OBS_SCRIPTING_MODULE_LIST _LEN) if(_LEN GREATER 0) add_dependencies(${target} ${OBS_SCRIPTING_MODULE_LIST}) @@ -200,10 +191,8 @@ function(setup_obs_app target) add_custom_command( TARGET ${target} POST_BUILD - COMMAND - "${CMAKE_COMMAND}" -E env DESTDIR= "${CMAKE_COMMAND}" --install .. - --config $ --prefix ${OBS_OUTPUT_DIR}/$ --component - obs_rundir > "$,nul,/dev/null>" + COMMAND "${CMAKE_COMMAND}" -E env DESTDIR= "${CMAKE_COMMAND}" --install .. --config $ --prefix + ${OBS_OUTPUT_DIR}/$ --component obs_rundir > "$,nul,/dev/null>" COMMENT "Installing OBS rundir" VERBATIM) endfunction() @@ -233,8 +222,8 @@ function(setup_target_browser target) EXCLUDE_FROM_ALL) endfunction() -# Helper function to export target to build and install tree. Allows usage of -# `find_package(libobs)` by other build trees +# Helper function to export target to build and install tree. Allows usage of `find_package(libobs)` by other build +# trees function(export_target target) set(CMAKE_EXPORT_PACKAGE_REGISTRY OFF) @@ -263,17 +252,14 @@ function(export_target target) ${_EXCLUDE}) include(GenerateExportHeader) - generate_export_header(${target} EXPORT_FILE_NAME - ${CMAKE_CURRENT_BINARY_DIR}/${target}_EXPORT.h) + generate_export_header(${target} EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/${target}_EXPORT.h) - target_sources(${target} - PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/${target}_EXPORT.h) + target_sources(${target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/${target}_EXPORT.h) set(TARGETS_EXPORT_NAME "${target}Targets") include(CMakePackageConfigHelpers) configure_package_config_file( - ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${target}Config.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/${target}Config.cmake + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${target}Config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${target}Config.cmake INSTALL_DESTINATION ${OBS_CMAKE_DESTINATION}/${target} PATH_VARS OBS_PLUGIN_DESTINATION OBS_DATA_DESTINATION) @@ -298,8 +284,7 @@ function(export_target target) ${_EXCLUDE}) install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/${target}Config.cmake - ${CMAKE_CURRENT_BINARY_DIR}/${target}ConfigVersion.cmake + FILES ${CMAKE_CURRENT_BINARY_DIR}/${target}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${target}ConfigVersion.cmake DESTINATION ${OBS_CMAKE_DESTINATION}/${target} COMPONENT obs_libraries ${_EXCLUDE}) @@ -311,16 +296,11 @@ function(define_graphic_modules target) string(TOUPPER ${_GRAPHICS_API} _GRAPHICS_API_u) if(TARGET OBS::libobs-${_GRAPHICS_API}) if(OS_POSIX AND NOT LINUX_PORTABLE) - target_compile_definitions( - ${target} - PRIVATE - DL_${_GRAPHICS_API_u}="$" - ) + target_compile_definitions(${target} + PRIVATE DL_${_GRAPHICS_API_u}="$") else() - target_compile_definitions( - ${target} - PRIVATE - DL_${_GRAPHICS_API_u}="$") + target_compile_definitions(${target} + PRIVATE DL_${_GRAPHICS_API_u}="$") endif() add_dependencies(${target} OBS::libobs-${_GRAPHICS_API}) else() @@ -338,8 +318,7 @@ endif() macro(find_qt) set(multiValueArgs COMPONENTS COMPONENTS_WIN COMPONENTS_MAC COMPONENTS_LINUX) - cmake_parse_arguments(FIND_QT "" "${oneValueArgs}" "${multiValueArgs}" - ${ARGN}) + cmake_parse_arguments(FIND_QT "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) set(QT_NO_CREATE_VERSIONLESS_TARGETS ON) find_package( Qt5 @@ -372,10 +351,7 @@ macro(find_qt) else() set(FALLBACK_QT_VERSION 6) endif() - message( - WARNING - "Qt${QT_VERSION} was not found, falling back to Qt${FALLBACK_QT_VERSION}" - ) + message(WARNING "Qt${QT_VERSION} was not found, falling back to Qt${FALLBACK_QT_VERSION}") if(TARGET Qt${FALLBACK_QT_VERSION}::Core) set(_QT_VERSION @@ -415,14 +391,11 @@ macro(find_qt) list(APPEND FIND_QT_COMPONENTS_LINUX "GuiPrivate") endif() - foreach(_COMPONENT IN LISTS FIND_QT_COMPONENTS FIND_QT_COMPONENTS_WIN - FIND_QT_COMPONENTS_MAC FIND_QT_COMPONENTS_LINUX) + foreach(_COMPONENT IN LISTS FIND_QT_COMPONENTS FIND_QT_COMPONENTS_WIN FIND_QT_COMPONENTS_MAC FIND_QT_COMPONENTS_LINUX) if(NOT TARGET Qt::${_COMPONENT} AND TARGET Qt${_QT_VERSION}::${_COMPONENT}) add_library(Qt::${_COMPONENT} INTERFACE IMPORTED) - set_target_properties( - Qt::${_COMPONENT} PROPERTIES INTERFACE_LINK_LIBRARIES - "Qt${_QT_VERSION}::${_COMPONENT}") + set_target_properties(Qt::${_COMPONENT} PROPERTIES INTERFACE_LINK_LIBRARIES "Qt${_QT_VERSION}::${_COMPONENT}") endif() endforeach() endmacro() @@ -455,9 +428,9 @@ elseif(OS_POSIX) include(ObsHelpers_Linux) endif() -# ############################################################################## +# ###################################################################################################################### # LEGACY FALLBACKS # -# ############################################################################## +# ###################################################################################################################### # Helper function to install OBS plugin with associated resource directory function(_install_obs_plugin_with_data target source) @@ -474,16 +447,14 @@ function(_install_obs_plugin_with_data target source) install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${source}/ - DESTINATION - ${OBS_OUTPUT_DIR}/$/${OBS_DATA_DESTINATION}/obs-plugins/${target} + DESTINATION ${OBS_OUTPUT_DIR}/$/${OBS_DATA_DESTINATION}/obs-plugins/${target} COMPONENT obs_${target} EXCLUDE_FROM_ALL) if(OS_WINDOWS AND DEFINED ENV{obsInstallerTempDir}) install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${source}/ - DESTINATION - $ENV{obsInstallerTempDir}/${OBS_DATA_DESTINATION}/obs-plugins/${target} + DESTINATION $ENV{obsInstallerTempDir}/${OBS_DATA_DESTINATION}/obs-plugins/${target} COMPONENT obs_${target} EXCLUDE_FROM_ALL) endif() @@ -502,8 +473,7 @@ function(_install_obs_datatarget target destination) LIBRARY DESTINATION ${OBS_DATA_DESTINATION}/${destination} COMPONENT ${target}_Runtime NAMELINK_COMPONENT ${target}_Development - RUNTIME DESTINATION ${OBS_DATA_DESTINATION}/${destination} - COMPONENT ${target}_Runtime) + RUNTIME DESTINATION ${OBS_DATA_DESTINATION}/${destination} COMPONENT ${target}_Runtime) install( TARGETS ${target} @@ -516,21 +486,18 @@ function(_install_obs_datatarget target destination) if(OS_WINDOWS) if(MSVC) - add_target_resource(${target} "$" - "${destination}" OPTIONAL) + add_target_resource(${target} "$" "${destination}" OPTIONAL) endif() if(DEFINED ENV{obsInstallerTempDir}) install( TARGETS ${target} RUNTIME - DESTINATION - $ENV{obsInstallerTempDir}/${OBS_DATA_DESTINATION}/${destination}/$ + DESTINATION $ENV{obsInstallerTempDir}/${OBS_DATA_DESTINATION}/${destination}/$ COMPONENT obs_${target} EXCLUDE_FROM_ALL LIBRARY - DESTINATION - $ENV{obsInstallerTempDir}/${OBS_DATA_DESTINATION}/${destination}/$ + DESTINATION $ENV{obsInstallerTempDir}/${OBS_DATA_DESTINATION}/${destination}/$ COMPONENT obs_${target} EXCLUDE_FROM_ALL) endif() @@ -539,10 +506,18 @@ function(_install_obs_datatarget target destination) add_custom_command( TARGET ${target} POST_BUILD - COMMAND - "${CMAKE_COMMAND}" -E env DESTDIR= "${CMAKE_COMMAND}" --install .. - --config $ --prefix ${OBS_OUTPUT_DIR}/$ --component - obs_${target} > "$,nul,/dev/null>" + COMMAND "${CMAKE_COMMAND}" -E env DESTDIR= "${CMAKE_COMMAND}" --install .. --config $ --prefix + ${OBS_OUTPUT_DIR}/$ --component obs_${target} > "$,nul,/dev/null>" COMMENT "Installing ${target} to OBS rundir" VERBATIM) endfunction() + +# legacy_check: Macro to check for CMake framework version and include legacy list file +macro(legacy_check) + if(OBS_CMAKE_VERSION VERSION_LESS 3.0.0) + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cmake/legacy.cmake) + include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/legacy.cmake) + endif() + return() + endif() +endmacro() diff --git a/cmake/common/.cmake-format.json b/cmake/common/.cmake-format.json new file mode 100644 index 000000000..75fd03ad3 --- /dev/null +++ b/cmake/common/.cmake-format.json @@ -0,0 +1,41 @@ +{ + "format": { + "line_width": 120, + "tab_size": 2, + "dangle_parens": false, + "enable_sort": true, + "autosort": true + }, + "additional_commands": { + "find_qt": { + "flags": [], + "kwargs": { + "COMPONENTS": "+", + "COMPONENTS_WIN": "+", + "COMPONENTS_MACOS": "+", + "COMPONENTS_LINUX": "+" + } + }, + "set_target_properties_obs": { + "pargs": 1, + "flags": [], + "kwargs": { + "PROPERTIES": { + "kwargs": { + "PREFIX": 1, + "OUTPUT_NAME": 1, + "FOLDER": 1, + "VERSION": 1, + "SOVERSION": 1, + "FRAMEWORK": 1, + "BUNDLE": 1, + "AUTOMOC": 1, + "AUTOUIC": 1, + "AUTORCC": 1, + "AUTOUIC_SEARCH_PATHS": 1 + } + } + } + } + } +} diff --git a/cmake/common/bootstrap.cmake b/cmake/common/bootstrap.cmake new file mode 100644 index 000000000..8d72a36db --- /dev/null +++ b/cmake/common/bootstrap.cmake @@ -0,0 +1,51 @@ +# OBS CMake bootstrap module + +# Enable automatic PUSH and POP of policies to parent scope +if(POLICY CMP0011) + cmake_policy(SET CMP0011 NEW) +endif() + +# Prohibit in-source builds +if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}") + message( + FATAL_ERROR + "OBS: In-source builds of OBS are not supported. Specify a build directory via 'cmake -S -B ' instead." + ) +endif() +file(REMOVE_RECURSE "${CMAKE_SOURCE_DIR}/CMakeCache.txt" "${CMAKE_SOURCE_DIR}/CMakeFiles") + +# Use folders for source file organization with IDE generators (Visual Studio/Xcode) +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +# Set default global project variables +set(OBS_COMPANY_NAME "OBS Project") +set(OBS_PRODUCT_NAME "OBS Studio") +set(OBS_WEBSITE "https://www.obsproject.com") +set(OBS_COMMENTS "Free and open source software for video recording and live streaming") +set(OBS_LEGAL_COPYRIGHT "(C) Hugh Bailey") + +# Configure default version strings +message(DEBUG "Setting default project version variables...") +set(_obs_default_version "0" "0" "1") +set(_obs_release_candidate "0" "0" "0" "0") +set(_obs_beta "0" "0" "0" "0") + +# Add common module directories to default search path +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/common" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/finders") + +include(versionconfig) +include(buildnumber) +include(osconfig) + +# Allow selection of common build types via UI +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE + "RelWithDebInfo" + CACHE STRING "OBS build type [Release, RelWithDebInfo, Debug, MinSizeRel]" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Release RelWithDebInfo Debug MinSizeRel) +endif() + +# Disable exports automatically going into the CMake package registry +set(CMAKE_EXPORT_PACKAGE_REGISTRY FALSE) +# Enable default inclusion of targets' source and binary directory +set(CMAKE_INCLUDE_CURRENT_DIR TRUE) diff --git a/cmake/common/buildnumber.cmake b/cmake/common/buildnumber.cmake new file mode 100644 index 000000000..e20ac5b80 --- /dev/null +++ b/cmake/common/buildnumber.cmake @@ -0,0 +1,19 @@ +# OBS CMake build number module + +# Define build number cache file +set(_BUILD_NUMBER_CACHE + "${CMAKE_SOURCE_DIR}/cmake/.CMakeBuildNumber" + CACHE INTERNAL "OBS build number cache file") + +# Read build number from cache file or manual override +if(NOT DEFINED OBS_BUILD_NUMBER AND EXISTS "${_BUILD_NUMBER_CACHE}") + file(READ "${_BUILD_NUMBER_CACHE}" OBS_BUILD_NUMBER) + math(EXPR OBS_BUILD_NUMBER "${OBS_BUILD_NUMBER}+1") +elseif(NOT DEFINED OBS_BUILD_NUMBER) + if($ENV{CI} AND $ENV{GITHUB_RUN_ID}) + set(OBS_BUILD_NUMBER "$ENV{GITHUB_RUN_ID}") + else() + set(OBS_BUILD_NUMBER "1") + endif() +endif() +file(WRITE "${_BUILD_NUMBER_CACHE}" "${OBS_BUILD_NUMBER}") diff --git a/cmake/common/ccache.cmake b/cmake/common/ccache.cmake new file mode 100644 index 000000000..f63f2ab83 --- /dev/null +++ b/cmake/common/ccache.cmake @@ -0,0 +1,20 @@ +# OBS CMake ccache module + +if(NOT DEFINED CCACHE_PROGRAM) + message(DEBUG "Trying to find ccache on build host...") + find_program(CCACHE_PROGRAM "ccache") + mark_as_advanced(CCACHE_PROGRAM) +endif() + +if(CCACHE_PROGRAM) + message(DEBUG "CCache found as ${CCACHE_PROGRAM}...") + option(ENABLE_CCACHE "Enable compiler acceleration with ccache" ON) + + if(ENABLE_CCACHE) + set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") + set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") + set(CMAKE_OBJC_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") + set(CMAKE_OBJCXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") + set(CMAKE_CUDA_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") + endif() +endif() diff --git a/cmake/common/compiler_common.cmake b/cmake/common/compiler_common.cmake new file mode 100644 index 000000000..def41575a --- /dev/null +++ b/cmake/common/compiler_common.cmake @@ -0,0 +1 @@ +# OBS CMake common compiler options module diff --git a/cmake/common/cpackconfig_common.cmake b/cmake/common/cpackconfig_common.cmake new file mode 100644 index 000000000..e68bbedb0 --- /dev/null +++ b/cmake/common/cpackconfig_common.cmake @@ -0,0 +1,10 @@ +# OBS CMake common CPack module + +# Set default global CPack variables +set(CPACK_PACKAGE_NAME obs-studio) +set(CPACK_PACKAGE_VENDOR "${OBS_WEBSITE}") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${OBS_COMMENTS}") + +set(CPACK_PACKAGE_VERSION_MAJOR ${OBS_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${OBS_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${OBS_VERSION_PATCH}) diff --git a/cmake/common/helpers_common.cmake b/cmake/common/helpers_common.cmake new file mode 100644 index 000000000..707a67055 --- /dev/null +++ b/cmake/common/helpers_common.cmake @@ -0,0 +1,521 @@ +# OBS CMake common helper functions module + +# cmake-format: off +# cmake-lint: disable=C0103 +# cmake-lint: disable=C0301 +# cmake-lint: disable=C0307 +# cmake-lint: disable=R0912 +# cmake-lint: disable=R0915 +# cmake-format: on + +# message_configuration: Function to print configuration outcome +function(message_configuration) + include(FeatureSummary) + feature_summary(WHAT ALL VAR _feature_summary) + + message(DEBUG "${_feature_summary}") + + message( + NOTICE + " _ _ _ _ \n" + " ___ | |__ ___ ___| |_ _ _ __| (_) ___ \n" + " / _ \\| '_ \\/ __|_____/ __| __| | | |/ _` | |/ _ \\ \n" + " | (_) | |_) \\__ \\_____\\__ \\ |_| |_| | (_| | | (_) |\n" + " \\___/|_.__/|___/ |___/\\__|\\__,_|\\__,_|_|\\___/ \n" + "\nOBS: Application Version: ${OBS_VERSION} - Build Number: ${OBS_BUILD_NUMBER}\n" + "==================================================================================\n\n") + + get_property(OBS_FEATURES_ENABLED GLOBAL PROPERTY OBS_FEATURES_ENABLED) + list( + SORT OBS_FEATURES_ENABLED + COMPARE NATURAL + CASE SENSITIVE + ORDER ASCENDING) + if(OBS_FEATURES_ENABLED) + message(NOTICE "------------------------ Enabled Features ------------------------") + foreach(feature IN LISTS OBS_FEATURES_ENABLED) + message(NOTICE " - ${feature}") + endforeach() + endif() + + get_property(OBS_FEATURES_DISABLED GLOBAL PROPERTY OBS_FEATURES_DISABLED) + list( + SORT OBS_FEATURES_DISABLED + COMPARE NATURAL + CASE SENSITIVE + ORDER ASCENDING) + if(OBS_FEATURES_DISABLED) + message(NOTICE "------------------------ Disabled Features ------------------------") + foreach(feature IN LISTS OBS_FEATURES_DISABLED) + message(NOTICE " - ${feature}") + endforeach() + endif() + + if(ENABLE_PLUGINS) + get_property(OBS_MODULES_ENABLED GLOBAL PROPERTY OBS_MODULES_ENABLED) + list( + SORT OBS_MODULES_ENABLED + COMPARE NATURAL + CASE SENSITIVE + ORDER ASCENDING) + if(OBS_MODULES_ENABLED) + message(NOTICE "------------------------ Enabled Modules ------------------------") + foreach(feature IN LISTS OBS_MODULES_ENABLED) + message(NOTICE " - ${feature}") + endforeach() + endif() + + get_property(OBS_MODULES_DISABLED GLOBAL PROPERTY OBS_MODULES_DISABLED) + list( + SORT OBS_MODULES_DISABLED + COMPARE NATURAL + CASE SENSITIVE + ORDER ASCENDING) + if(OBS_MODULES_DISABLED) + message(NOTICE "------------------------ Disabled Modules ------------------------") + foreach(feature IN LISTS OBS_MODULES_DISABLED) + message(NOTICE " - ${feature}") + endforeach() + endif() + endif() + message(NOTICE "----------------------------------------------------------------------------------") +endfunction() + +# target_enable_feature: Adds feature to list of enabled application features and sets optional compile definitions +function(target_enable_feature target feature_description) + set_property(GLOBAL APPEND PROPERTY OBS_FEATURES_ENABLED "${feature_description}") + + if(ARGN) + target_compile_definitions(${target} PRIVATE ${ARGN}) + endif() +endfunction() + +# target_disable_feature: Adds feature to list of disabled application features and sets optional compile definitions +function(target_disable_feature target feature_description) + set_property(GLOBAL APPEND PROPERTY OBS_FEATURES_DISABLED "${feature_description}") + + if(ARGN) + target_compile_definitions(${target} PRIVATE ${ARGN}) + endif() +endfunction() + +# target_disable: Adds target to list of disabled modules +function(target_disable target) + set_property(GLOBAL APPEND PROPERTY OBS_MODULES_DISABLED ${target}) +endfunction() + +# * Use QT_VERSION value as a hint for desired Qt version +# * If "AUTO" was specified, prefer Qt6 over Qt5 +# * Creates versionless targets of desired component if none had been created by Qt itself (Qt versions < 5.15) +if(NOT QT_VERSION) + set(QT_VERSION + AUTO + CACHE STRING "OBS Qt version [AUTO, 5, 6]" FORCE) + set_property(CACHE QT_VERSION PROPERTY STRINGS AUTO 5 6) +endif() + +# find_qt: Macro to find best possible Qt version for use with the project: +macro(find_qt) + set(multiValueArgs COMPONENTS COMPONENTS_WIN COMPONENTS_MAC COMPONENTS_LINUX) + cmake_parse_arguments(find_qt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + # Do not use versionless targets in the first step to avoid Qt::Core being clobbered by later opportunistic + # find_package runs + set(QT_NO_CREATE_VERSIONLESS_TARGETS TRUE) + + message(DEBUG "Start Qt version discovery...") + # Loop until _QT_VERSION is set or FATAL_ERROR aborts script execution early + while(NOT _QT_VERSION) + message(DEBUG "QT_VERSION set to ${QT_VERSION}") + if(QT_VERSION STREQUAL AUTO AND NOT qt_test_version) + set(qt_test_version 6) + elseif(NOT QT_VERSION STREQUAL AUTO) + set(qt_test_version ${QT_VERSION}) + endif() + message(DEBUG "Attempting to find Qt${qt_test_version}") + + find_package( + Qt${qt_test_version} + COMPONENTS Core + QUIET) + + if(TARGET Qt${qt_test_version}::Core) + set(_QT_VERSION + ${qt_test_version} + CACHE INTERNAL "") + message(STATUS "Qt version found: ${_QT_VERSION}") + unset(qt_test_version) + break() + elseif(QT_VERSION STREQUAL AUTO) + if(qt_test_version EQUAL 6) + message(WARNING "Qt6 was not found, falling back to Qt5") + set(qt_test_version 5) + continue() + endif() + endif() + message(FATAL_ERROR "Neither Qt6 nor Qt5 found.") + endwhile() + + # Enable versionless targets for the remaining Qt components + set(QT_NO_CREATE_VERSIONLESS_TARGETS FALSE) + + set(qt_components ${find_qt_COMPONENTS}) + if(OS_WINDOWS) + list(APPEND qt_components ${find_qt_COMPONENTS_WIN}) + elseif(OS_MACOS) + list(APPEND qt_components ${find_qt_COMPONENTS_MAC}) + else() + list(APPEND qt_components ${find_qt_COMPONENTS_LINUX}) + endif() + message(DEBUG "Trying to find Qt components ${qt_components}...") + + find_package(Qt${_QT_VERSION} REQUIRED ${qt_components}) + + list(APPEND qt_components Core) + + if("Gui" IN_LIST find_qt_COMPONENTS_LINUX) + list(APPEND qt_components "GuiPrivate") + endif() + + # Check for versionless targets of each requested component and create if necessary + foreach(component IN LISTS qt_components) + message(DEBUG "Checking for target Qt::${component}") + if(NOT TARGET Qt::${component} AND TARGET Qt${_QT_VERSION}::${component}) + add_library(Qt::${component} INTERFACE IMPORTED) + set_target_properties(Qt::${component} PROPERTIES INTERFACE_LINK_LIBRARIES Qt${_QT_VERSION}::${component}) + endif() + endforeach() +endmacro() + +# find_dependencies: Check linked interface and direct dependencies of target +function(find_dependencies) + set(oneValueArgs TARGET FOUND_VAR) + set(multiValueArgs) + cmake_parse_arguments(var "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(NOT DEFINED is_root) + # Root of recursive dependency resolution + set(is_root TRUE) + set(nested_depth 0) + else() + # Branch of recursive dependency resolution + set(is_root FALSE) + math(EXPR nested_depth "${nested_depth}+1") + endif() + + # * LINK_LIBRARIES are direct dependencies + # * INTERFACE_LINK_LIBRARIES are transitive dependencies + get_target_property(linked_libraries ${var_TARGET} LINK_LIBRARIES) + get_target_property(interface_libraries ${var_TARGET} INTERFACE_LINK_LIBRARIES) + message(DEBUG "[${nested_depth}] Linked libraries in target ${var_TARGET}: ${linked_libraries}") + message(DEBUG "[${nested_depth}] Linked interface libraries in target ${var_TARGET}: ${interface_libraries}") + + # Consider CMake targets only + list(FILTER linked_libraries INCLUDE REGEX ".+::.+") + list(FILTER interface_libraries INCLUDE REGEX ".+::.+") + + foreach(library IN LISTS linked_libraries interface_libraries) + if(NOT library) + continue() + elseif(library MATCHES "\\$<.*:[^>]+>") + # Generator expression found + if(library MATCHES "\\$<\\$]+>:.+>") + # Platform-dependent generator expression found - platforms are a comma-separated list of CMake host OS + # identifiers. Convert to CMake list and check if current host os is contained in list. + string(REGEX REPLACE "\\$<\\$]+)>:([^>]+)>" "\\1;\\2" gen_expression "${library}") + list(GET gen_expression 0 gen_platform) + list(GET gen_expression 1 gen_library) + string(REPLACE "," ";" gen_platform "${gen_platform}") + if(CMAKE_HOST_SYSTEM_NAME IN_LIST platform) + set(library "${gen_library}") + else() + continue() + endif() + elseif(library MATCHES "\\$<\\$]+>:.+>") + # Boolean generator expression found - consider parameter a CMake variable that resolves into a CMake-like + # boolean value for a simple conditional check. + string(REGEX REPLACE "\\$<\\$]+)>:([^>]+)>" "\\1;\\2" gen_expression "${library}") + list(GET gen_expression 0 gen_boolean) + list(GET gen_expression 1 gen_library) + if(${gen_boolean}) + set(library "${gen_library}") + else() + continue() + endif() + elseif(library MATCHES "\\$]+>") + # Target-dependent generator expression found - consider parameter to be a CMake target identifier and check for + # target existence. + string(REGEX REPLACE "\\$]+)>" "\\1" gen_target "${library}") + if(TARGET ${gen_target}) + set(library "${gen_target}") + else() + continue() + endif() + elseif(library MATCHES "\\$<.*Qt6::EntryPointPrivate>" OR library MATCHES + "\\$<.*Qt6::QDarwinBluetoothPermissionPlugin>") + # Known Qt6-specific generator expression, ignored. + continue() + else() + # Unknown or unimplemented generator expression found - abort script run to either add to ignore list or + # implement detection. + message(FATAL_ERROR "${library} is an unsupported generator expression for linked libraries.") + endif() + endif() + + message(DEBUG "[${nested_depth}] Found ${library}...") + + if(NOT library IN_LIST ${var_FOUND_VAR}) + list(APPEND found_libraries ${library}) + # Enter recursive branch + find_dependencies(TARGET ${library} FOUND_VAR ${var_FOUND_VAR}) + endif() + endforeach() + + if(NOT is_root) + set(found_libraries + ${found_libraries} + PARENT_SCOPE) + # Exit recursive branch + return() + endif() + + list(REMOVE_DUPLICATES found_libraries) + list(APPEND ${var_FOUND_VAR} ${found_libraries}) + set(${var_FOUND_VAR} + ${${var_FOUND_VAR}} + PARENT_SCOPE) +endfunction() + +# find_qt_plugins: Find and add Qt plugin libraries associated with Qt component to target +function(find_qt_plugins) + set(oneValueArgs COMPONENT TARGET FOUND_VAR) + cmake_parse_arguments(var "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + string(REPLACE "::" ";" library_tuple "${var_COMPONENT}") + list(GET library_tuple 0 library_namespace) + list(GET library_tuple 1 library_name) + + if(NOT ${library_namespace} MATCHES "Qt[56]?") + message(FATAL_ERROR "'find_qt_plugins' has to be called with a valid target from the Qt, Qt5, or Qt6 namespace.") + endif() + + list( + APPEND + qt_plugins_Core + platforms + printsupport + styles + imageformats + iconengines) + list(APPEND qt_plugins_Gui platforminputcontexts virtualkeyboard) + list(APPEND qt_plugins_Network bearer) + list(APPEND qt_plugins_Sql sqldrivers) + list(APPEND qt_plugins_Multimedia mediaservice audio) + list(APPEND qt_plugins_3dRender sceneparsers geometryloaders) + list(APPEND qt_plugins_3dQuickRender renderplugins) + list(APPEND qt_plugins_Positioning position) + list(APPEND qt_plugins_Location geoservices) + list(APPEND qt_plugins_TextToSpeech texttospeech) + list(APPEND qt_plugins_WebView webview) + + if(qt_plugins_${library_name}) + get_target_property(library_location ${var_COMPONENT} IMPORTED_LOCATION) + get_target_property(is_framework ${var_COMPONENT} FRAMEWORK) + + if(is_framework) + # Resolve Qt plugin location relative to framework binary location on macOS + set(plugins_location "../../../../../plugins") + cmake_path(ABSOLUTE_PATH plugins_location BASE_DIRECTORY "${library_location}" NORMALIZE) + else() + # Resolve Qt plugin location relative to dynamic library location + set(plugins_location "../../plugins") + cmake_path(ABSOLUTE_PATH plugins_location BASE_DIRECTORY "${library_location}" NORMALIZE) + endif() + + foreach(plugin IN ITEMS ${qt_plugins_${library_name}}) + if(NOT plugin IN_LIST plugins_list) + if(EXISTS "${plugins_location}/${plugin}") + # Gather all .dll or .dylib files in given plugin subdirectory + file( + GLOB plugin_libraries + RELATIVE "${plugins_location}/${plugin}" + "${plugins_location}/${plugin}/*.dylib" "${plugins_location}/${plugin}/*.dll") + message(DEBUG "Found Qt plugin ${plugin} libraries: ${plugin_libraries}") + foreach(plugin_library IN ITEMS ${plugin_libraries}) + set(plugin_full_path "${plugins_location}/${plugin}/${plugin_library}") + list(APPEND plugins_list ${plugin_full_path}) + endforeach() + endif() + endif() + endforeach() + endif() + + set(${var_FOUND_VAR} + ${plugins_list} + PARENT_SCOPE) +endfunction() + +# target_export: Helper function to export target as CMake package +function(target_export target) + if(NOT DEFINED exclude_variant) + set(exclude_variant EXCLUDE_FROM_ALL) + endif() + + get_target_property(is_framework ${target} FRAMEWORK) + if(is_framework) + set(package_destination "Frameworks/${target}.framework/Resources/cmake") + set(include_destination "Frameworks/${target}.framework/Headers") + else() + set(package_destination "${OBS_CMAKE_DESTINATION}/${target}") + set(include_destination "${OBS_INCLUDE_DESTINATION}") + endif() + + install( + TARGETS ${target} + EXPORT ${target}Targets + RUNTIME DESTINATION "${OBS_EXECUTABLE_DESTINATION}" + COMPONENT Development + ${exclude_variant} + LIBRARY DESTINATION "${OBS_LIBRARY_DESTINATION}" + COMPONENT Development + ${exclude_variant} + ARCHIVE DESTINATION "${OBS_LIBRARY_DESTINATION}" + COMPONENT Development + ${exclude_variant} + FRAMEWORK DESTINATION Frameworks + COMPONENT Development + ${exclude_variant} + INCLUDES + DESTINATION "${include_destination}" + PUBLIC_HEADER + DESTINATION "${include_destination}" + COMPONENT Development + ${exclude_variant}) + + get_target_property(obs_public_headers ${target} OBS_PUBLIC_HEADERS) + + if(obs_public_headers) + foreach(header IN LISTS obs_public_headers) + cmake_path(GET header PARENT_PATH header_dir) + if(header_dir) + if(NOT ${header_dir} IN_LIST header_dirs) + list(APPEND header_dirs ${header_dir}) + endif() + list(APPEND headers_${header_dir} ${header}) + else() + list(APPEND headers ${header}) + endif() + endforeach() + + foreach(header_dir IN LISTS header_dirs) + install( + FILES ${headers_${header_dir}} + DESTINATION "${include_destination}/${header_dir}" + COMPONENT Development + ${exclude_variant}) + endforeach() + + if(headers) + install( + FILES ${headers} + DESTINATION "${include_destination}" + COMPONENT Development + ${exclude_variant}) + endif() + endif() + + if(target STREQUAL libobs AND NOT EXISTS "${include_destination}/obsconfig.h") + install( + FILES "${CMAKE_BINARY_DIR}/config/obsconfig.h" + DESTINATION "${include_destination}" + COMPONENT Development + ${exclude_variant}) + endif() + + message(DEBUG "Generating export header for target ${target} as ${target}_EXPORT.h...") + include(GenerateExportHeader) + generate_export_header(${target} EXPORT_FILE_NAME "${target}_EXPORT.h") + target_sources(${target} PUBLIC $ + $) + set_property( + TARGET ${target} + APPEND + PROPERTY PUBLIC_HEADER "${target}_EXPORT.h") + + set(TARGETS_EXPORT_NAME ${target}Targets) + message( + DEBUG + "Generating CMake package configuration file ${target}Config.cmake with targets file ${TARGETS_EXPORT_NAME}...") + include(CMakePackageConfigHelpers) + configure_package_config_file(cmake/${target}Config.cmake.in ${target}Config.cmake + INSTALL_DESTINATION "${package_destination}") + + message(DEBUG "Generating CMake package version configuration file ${target}ConfigVersion.cmake...") + write_basic_package_version_file( + "${target}ConfigVersion.cmake" + VERSION ${OBS_VERSION_CANONICAL} + COMPATIBILITY SameMajorVersion) + + export( + EXPORT ${target}Targets + FILE "${TARGETS_EXPORT_NAME}.cmake" + NAMESPACE OBS::) + + export(PACKAGE ${target}) + + install( + EXPORT ${TARGETS_EXPORT_NAME} + FILE ${TARGETS_EXPORT_NAME}.cmake + NAMESPACE OBS:: + DESTINATION "${package_destination}" + COMPONENT Development + ${exclude_variant}) + + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${target}ConfigVersion.cmake" + DESTINATION "${package_destination}" + COMPONENT Development + ${exclude_variant}) +endfunction() + +# check_uuid: Helper function to check for valid UUID +function(check_uuid uuid_string return_value) + set(valid_uuid TRUE) + set(uuid_token_lengths 8 4 4 4 12) + set(token_num 0) + + string(REPLACE "-" ";" uuid_tokens ${uuid_string}) + list(LENGTH uuid_tokens uuid_num_tokens) + + if(uuid_num_tokens EQUAL 5) + message(DEBUG "UUID ${uuid_string} is valid with 5 tokens.") + foreach(uuid_token IN LISTS uuid_tokens) + list(GET uuid_token_lengths ${token_num} uuid_target_length) + string(LENGTH "${uuid_token}" uuid_actual_length) + if(uuid_actual_length EQUAL uuid_target_length) + string(REGEX MATCH "[0-9a-fA-F]+" uuid_hex_match ${uuid_token}) + if(NOT uuid_hex_match STREQUAL uuid_token) + set(valid_uuid FALSE) + break() + endif() + else() + set(valid_uuid FALSE) + break() + endif() + math(EXPR token_num "${token_num}+1") + endforeach() + else() + set(valid_uuid FALSE) + endif() + message(DEBUG "UUID ${uuid_string} valid: ${valid_uuid}") + set(${return_value} + ${valid_uuid} + PARENT_SCOPE) +endfunction() + +# legacy_check: Checks if new CMake framework was not enabled and load legacy rules instead +macro(legacy_check) + if(OBS_CMAKE_VERSION VERSION_LESS 3.0.0) + message(FATAL_ERROR "CMake version changed between CMakeLists.txt.") + endif() +endmacro() diff --git a/cmake/common/osconfig.cmake b/cmake/common/osconfig.cmake new file mode 100644 index 000000000..6b692fcfc --- /dev/null +++ b/cmake/common/osconfig.cmake @@ -0,0 +1,15 @@ +# OBS CMake operating system bootstrap module + +# Set minimum CMake version specific to host operating system, add OS-specific module directory to default search paths, +# and set helper variables for OS detection in other CMake list files. +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/windows") + set(OS_WINDOWS TRUE) +elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos") + set(OS_MACOS TRUE) +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD|OpenBSD") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/linux") + string(TOUPPER "${CMAKE_HOST_SYSTEM_NAME}" _SYSTEM_NAME_U) + set(OS_${_SYSTEM_NAME_U} TRUE) +endif() diff --git a/cmake/common/versionconfig.cmake b/cmake/common/versionconfig.cmake new file mode 100644 index 000000000..a03b22b7f --- /dev/null +++ b/cmake/common/versionconfig.cmake @@ -0,0 +1,90 @@ +# OBS CMake common version helper module + +# cmake-format: off +# cmake-lint: disable=C0301 +# cmake-format: on + +# Attempt to automatically discover expected OBS version +if(NOT DEFINED OBS_VERSION_OVERRIDE) + if(DEFINED RELEASE_CANDIDATE) + if(RELEASE_CANDIDATE MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+-rc[0-9]+") + string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)-rc([0-9])+" "\\1;\\2;\\3;\\4" _obs_release_candidate + ${RELEASE_CANDIDATE}) + list(GET _obs_release_candidate 0 1 2 _obs_version_canonical) + set(_obs_version ${RELEASE_CANDIDATE}) + else() + message(FATAL_ERROR "Invalid release candidate version supplied - must be ..-rc.") + endif() + elseif(DEFINED BETA) + if(BETA MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+-beta[0-9]+") + string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)-beta([0-9])+" "\\1;\\2;\\3;\\4" _obs_beta ${BETA}) + list(GET _beta 0 1 2 _obs_version_canonical) + set(_obs_version ${BETA}) + else() + message(FATAL_ERROR "Invalid beta version supplied - must be ..-beta.") + endif() + elseif(EXISTS "${CMAKE_SOURCE_DIR}/.git") + execute_process( + COMMAND git describe --always --tags --dirty=-modified + OUTPUT_VARIABLE _obs_version + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE _obs_version_result + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if(_obs_version_result EQUAL 0) + if(_obs_version MATCHES "rc[0-9]+$") + set(RELEASE_CANDIDATE ${_obs_version}) + elseif(_obs_version MATCHES "beta[0-9]+$") + set(BETA ${_obs_version}) + endif() + + string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\1;\\2;\\3" _obs_version_canonical ${_obs_version}) + else() + set(_obs_version ${_obs_default_version}) + set(_obs_version_canonical ${_obs_default_version}) + endif() + endif() +else() + if(OBS_VERSION_OVERRIDE MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+).*") + string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\1;\\2;\\3" _obs_version_canonical ${_obs_version}) + set(_obs_version ${OBS_VERSION_OVERRIDE}) + else() + message(FATAL_ERROR "Invalid version supplied - must be ...") + endif() +endif() + +list(GET _obs_version_canonical 0 OBS_VERSION_MAJOR) +list(GET _obs_version_canonical 1 OBS_VERSION_MINOR) +list(GET _obs_version_canonical 2 OBS_VERSION_PATCH) +list(GET _obs_release_candidate 0 OBS_RELEASE_CANDIDATE_MAJOR) +list(GET _obs_release_candidate 1 OBS_RELEASE_CANDIDATE_MINOR) +list(GET _obs_release_candidate 2 OBS_RELEASE_CANDIDATE_PATCH) +list(GET _obs_release_candidate 3 OBS_RELEASE_CANDIDATE) +list(GET _obs_beta 0 OBS_BETA_MAJOR) +list(GET _obs_beta 1 OBS_BETA_MINOR) +list(GET _obs_beta 2 OBS_BETA_PATCH) +list(GET _obs_beta 3 OBS_BETA) + +string(REPLACE ";" "." OBS_VERSION_CANONICAL "${_obs_version_canonical}") +string(REPLACE ";" "." OBS_VERSION "${_obs_version}") + +if(OBS_RELEASE_CANDIDATE GREATER 0) + message( + AUTHOR_WARNING + "******************************************************************************\n" + " + OBS-Studio - Release candidate detected, OBS_VERSION is now: ${OBS_VERSION}\n" + "******************************************************************************") +elseif(OBS_BETA GREATER 0) + message( + AUTHOR_WARNING + "******************************************************************************\n" + " + OBS-Studio - Beta detected, OBS_VERSION is now: ${OBS_VERSION}\n" + "******************************************************************************") +endif() + +unset(_obs_default_version) +unset(_obs_version) +unset(_obs_version_canonical) +unset(_obs_release_candidate) +unset(_obs_beta) +unset(_obs_version_result) diff --git a/cmake/finders/.cmake-format.json b/cmake/finders/.cmake-format.json new file mode 100644 index 000000000..75fd03ad3 --- /dev/null +++ b/cmake/finders/.cmake-format.json @@ -0,0 +1,41 @@ +{ + "format": { + "line_width": 120, + "tab_size": 2, + "dangle_parens": false, + "enable_sort": true, + "autosort": true + }, + "additional_commands": { + "find_qt": { + "flags": [], + "kwargs": { + "COMPONENTS": "+", + "COMPONENTS_WIN": "+", + "COMPONENTS_MACOS": "+", + "COMPONENTS_LINUX": "+" + } + }, + "set_target_properties_obs": { + "pargs": 1, + "flags": [], + "kwargs": { + "PROPERTIES": { + "kwargs": { + "PREFIX": 1, + "OUTPUT_NAME": 1, + "FOLDER": 1, + "VERSION": 1, + "SOVERSION": 1, + "FRAMEWORK": 1, + "BUNDLE": 1, + "AUTOMOC": 1, + "AUTOUIC": 1, + "AUTORCC": 1, + "AUTOUIC_SEARCH_PATHS": 1 + } + } + } + } + } +} diff --git a/cmake/finders/FindCEF.cmake b/cmake/finders/FindCEF.cmake new file mode 100644 index 000000000..ced4d4b6e --- /dev/null +++ b/cmake/finders/FindCEF.cmake @@ -0,0 +1,232 @@ +#[=======================================================================[.rst +FindCEF +---------- + +FindModule for CEF and associated libraries + +.. versionchanged:: 3.0 + Updated FindModule to CMake standards + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 2.0 + +This module defines the :prop_tgt:`IMPORTED` targets: + +``CEF::Wrapper`` + Static library loading wrapper + +``CEF::Library`` + Chromium Embedded Library + +Result Variables +^^^^^^^^^^^^^^^^ + +This module sets the following variables: + +``CEF_FOUND`` + True, if all required components and the core library were found. +``CEF_VERSION`` + Detected version of found CEF libraries. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``CEF_LIBRARY_WRAPPER_RELEASE`` + Path to the optimized wrapper component of CEF. +``CEF_LIBRARY_WRAPPER_DEBUG`` + Path to the debug wrapper component of CEF. +``CEF_LIBRARY_RELEASE`` + Path to the library component of CEF. +``CEF_LIBRARY_DEBUG`` + Path to the debug library component of CEF. +``CEF_INCLUDE_DIR`` + Directory containing ``cef_version.h``. + +#]=======================================================================] + +# cmake-format: off +# cmake-lint: disable=C0301 +# cmake-lint: disable=C0307 +# cmake-format: on + +include(FindPackageHandleStandardArgs) + +set(CEF_ROOT_DIR + "" + CACHE PATH "Alternative path to Chromium Embedded Framework") + +if(NOT DEFINED CEF_ROOT_DIR OR CEF_ROOT_DIR STREQUAL "") + message( + FATAL_ERROR + "CEF_ROOT_DIR is not set - if ENABLE_BROWSER is enabled, " + "a CEF distribution with compiled wrapper library is required.\n" + "Please download a CEF distribution for your appropriate architecture " + "and specify CEF_ROOT_DIR to its location") +endif() + +find_path( + CEF_INCLUDE_DIR "cef_version.h" + HINTS "${CEF_ROOT_DIR}/include" + DOC "Chromium Embedded Framework include directory.") + +if(CEF_INCLUDE_DIR) + file(STRINGS "${CEF_INCLUDE_DIR}/cef_version.h" _VERSION_STRING + REGEX "^.*CEF_VERSION_(MAJOR|MINOR|PATCH)[ \t]+[0-9]+[ \t]*$") + string(REGEX REPLACE ".*CEF_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" VERSION_MAJOR "${_VERSION_STRING}") + string(REGEX REPLACE ".*CEF_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" VERSION_MINOR "${_VERSION_STRING}") + string(REGEX REPLACE ".*CEF_VERSION_PATCH[ \t]+([0-9]+).*" "\\1" VERSION_PATCH "${_VERSION_STRING}") + set(CEF_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") +else() + if(NOT CEF_FIND_QUIETLY) + message(AUTHOR_WARNING "Failed to find Chromium Embedded Framework version.") + endif() + set(CEF_VERSION 0.0.0) +endif() + +if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) + find_library( + CEF_IMPLIB_RELEASE + NAMES cef.lib libcef.lib + NO_DEFAULT_PATH + PATHS "${CEF_ROOT_DIR}" "${CEF_ROOT_DIR}/Release" + DOC "Chromium Embedded Framework import library location") + + find_program( + CEF_LIBRARY_RELEASE + NAMES cef.dll libcef.dll + PATHS "${CEF_ROOT_DIR}" "${CEF_ROOT_DIR}/Release" + DOC "Chromium Embedded Framework library location") + + if(NOT CEF_LIBRARY_RELEASE) + set(CEF_LIBRARY_RELEASE "${CEF_IMPLIB_RELEASE}") + endif() + + find_library( + CEF_LIBRARY_WRAPPER_RELEASE + NAMES cef_dll_wrapper libcef_dll_wrapper + NO_DEFAULT_PATH + PATHS "${CEF_ROOT_DIR}/build/libcef_dll/Release" "${CEF_ROOT_DIR}/build/libcef_dll_wrapper/Release" + "${CEF_ROOT_DIR}/build/libcef_dll" "${CEF_ROOT_DIR}/build/libcef_dll_wrapper" + DOC "Chromium Embedded Framework static library wrapper.") + + find_library( + CEF_LIBRARY_WRAPPER_DEBUG + NAMES cef_dll_wrapper libcef_dll_wrapper + NO_DEFAULT_PATH + PATHS "${CEF_ROOT_DIR}/build/libcef_dll/Debug" "${CEF_ROOT_DIR}/build/libcef_dll_wrapper/Debug" + DOC "Chromium Embedded Framework static library wrapper (debug).") +elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) + find_library( + CEF_LIBRARY_RELEASE + NAMES "Chromium Embedded Framework" + NO_DEFAULT_PATH + PATHS "${CEF_ROOT_DIR}" "${CEF_ROOT_DIR}/Release" + DOC "Chromium Embedded Framework") + + find_library( + CEF_LIBRARY_WRAPPER_RELEASE + NAMES cef_dll_wrapper libcef_dll_wrapper + NO_DEFAULT_PATH + PATHS "${CEF_ROOT_DIR}/build/libcef_dll/Release" "${CEF_ROOT_DIR}/build/libcef_dll_wrapper/Release" + "${CEF_ROOT_DIR}/build/libcef_dll" "${CEF_ROOT_DIR}/build/libcef_dll_wrapper" + DOC "Chromium Embedded Framework static library wrapper.") + + find_library( + CEF_LIBRARY_WRAPPER_DEBUG + NAMES cef_dll_wrapper libcef_dll_wrapper + NO_DEFAULT_PATH + PATHS "${CEF_ROOT_DIR}/build/libcef_dll/Debug" "${CEF_ROOT_DIR}/build/libcef_dll_wrapper/Debug" + DOC "Chromium Embedded Framework static library wrapper (debug).") +elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL Linux) + find_library( + CEF_LIBRARY_RELEASE + NAMES libcef.so + NO_DEFAULT_PATH + PATHS "${CEF_ROOT_DIR}" "${CEF_ROOT_DIR}/Release" + DOC "Chromium Embedded Framework") + + find_library( + CEF_LIBRARY_WRAPPER_RELEASE + NAMES cef_dll_wrapper.a libcef_dll_wrapper.a + NO_DEFAULT_PATH + PATHS "${CEF_ROOT_DIR}/build/libcef_dll" "${CEF_ROOT_DIR}/build/libcef_dll_wrapper" + DOC "Chromium Embedded Framework static library wrapper.") +endif() + +include(SelectLibraryConfigurations) +select_library_configurations(CEF) + +find_package_handle_standard_args( + CEF + REQUIRED_VARS CEF_LIBRARY_RELEASE CEF_LIBRARY_WRAPPER_RELEASE CEF_INCLUDE_DIR + VERSION_VAR CEF_VERSION REASON_FAILURE_MESSAGE + "Ensure that location of pre-compiled Chromium Embedded Framework is set as CEF_ROOT_DIR.") +mark_as_advanced(CEF_LIBRARY CEF_LIBRARY_WRAPPER_RELEASE CEF_LIBRARY_WRAPPER_DEBUG CEF_INCLUDE_DIR) + +if(NOT TARGET CEF::Wrapper) + if(IS_ABSOLUTE "${CEF_LIBRARY_WRAPPER_RELEASE}") + add_library(CEF::Wrapper STATIC IMPORTED) + set_property(TARGET CEF::Wrapper PROPERTY IMPORTED_LOCATION_RELEASE "${CEF_LIBRARY_WRAPPER_RELEASE}") + else() + add_library(CEF::Wrapper INTERFACE IMPORTED) + set_property(TARGET CEF::Wrapper PROPERTY IMPORTED_LIBNAME_RELEASE "${CEF_LIBRARY_WRAPPER_RELEASE}") + endif() + set_property( + TARGET CEF::Wrapper + APPEND + PROPERTY IMPORTED_CONFIGURATIONS "Release") + + if(CEF_LIBRARY_WRAPPER_DEBUG) + if(IS_ABSOLUTE "${CEF_LIBRARY_WRAPPER_DEBUG}") + set_property(TARGET CEF::Wrapper PROPERTY IMPORTED_LOCATION_DEBUG "${CEF_LIBRARY_WRAPPER_DEBUG}") + else() + set_property(TARGET CEF::Wrapper PROPERTY IMPORTED_LIBNAME_DEBUG "${CEF_LIBRARY_WRAPPER_DEBUG}") + endif() + set_property( + TARGET CEF::Wrapper + APPEND + PROPERTY IMPORTED_CONFIGURATIONS "Debug") + endif() + + set_property( + TARGET CEF::Wrapper + APPEND + PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CEF_INCLUDE_DIR}" "${CEF_ROOT_DIR}") +endif() + +if(NOT TARGET CEF::Library) + if(IS_ABSOLUTE "${CEF_LIBRARY_RELEASE}") + if(DEFINED CEF_IMPLIB_RELEASE) + if(CEF_IMPLIB_RELEASE STREQUAL CEF_LIBRARY_RELEASE) + add_library(CEF::Library STATIC IMPORTED) + else() + add_library(CEF::Library SHARED IMPORTED) + set_property(TARGET CEF::Library PROPERTY IMPORTED_IMPLIB_RELEASE "${CEF_IMPLIB_RELEASE}") + endif() + else() + add_library(CEF::Library UNKNOWN IMPORTED) + endif() + set_property(TARGET CEF::Library PROPERTY IMPORTED_LOCATION_RELEASE "${CEF_LIBRARY_RELEASE}") + else() + add_library(CEF::Library INTERFACE IMPORTED) + set_property(TARGET CEF::Library PROPERTY IMPORTED_LIBNAME_RELEASE "${CEF_LIBRARY_RELEASE}") + endif() + + set_property( + TARGET CEF::Library + APPEND + PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CEF_INCLUDE_DIR}" "${CEF_ROOT_DIR}") + set_property(TARGET CEF::Library PROPERTY IMPORTED_CONFIGURATIONS "Release") +endif() + +include(FeatureSummary) +set_package_properties( + CEF PROPERTIES + URL "https://bitbucket.org/chromiumembedded/cef/" + DESCRIPTION + "Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications." +) diff --git a/cmake/finders/FindFFmpeg.cmake b/cmake/finders/FindFFmpeg.cmake new file mode 100644 index 000000000..b5f44350e --- /dev/null +++ b/cmake/finders/FindFFmpeg.cmake @@ -0,0 +1,345 @@ +#[=======================================================================[.rst +FindFFmpeg +---------- + +FindModule for FFmpeg and associated libraries + +.. versionchanged:: 3.0 + Updated FindModule to CMake standards + +Components +^^^^^^^^^^ + +.. versionadded:: 1.0 + +This module contains provides several components: + +``avcodec`` +``avdevice`` +``avfilter`` +``avformat`` +``avutil`` +``postproc`` +``swscale`` +``swresample`` + +Import targets exist for each component. + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 2.0 + +This module defines the :prop_tgt:`IMPORTED` targets: + +``FFmpeg::avcodec`` + AVcodec component + +``FFmpeg::avdevice`` + AVdevice component + +``FFmpeg::avfilter`` + AVfilter component + +``FFmpeg::avformat`` + AVformat component + +``FFmpeg::avutil`` + AVutil component + +``FFmpeg::postproc`` + postproc component + +``FFmpeg::swscale`` + SWscale component + +``FFmpeg::swresample`` + SWresample component + +Result Variables +^^^^^^^^^^^^^^^^ + +This module sets the following variables: + +``FFmpeg_FOUND`` + True, if all required components and the core library were found. +``FFmpeg_VERSION`` + Detected version of found FFmpeg libraries. +``FFmpeg_INCLUDE_DIRS`` + Include directories needed for FFmpeg. +``FFmpeg_LIBRARIES`` + Libraries needed to link to FFmpeg. +``FFmpeg_DEFINITIONS`` + Compiler flags required for FFmpeg. + +``FFmpeg__VERSION`` + Detected version of found FFmpeg component library. +``FFmpeg__INCLUDE_DIRS`` + Include directories needed for FFmpeg component. +``FFmpeg__LIBRARIES`` + Libraries needed to link to FFmpeg component. +``FFmpeg__DEFINITIONS`` + Compiler flags required for FFmpeg component. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``FFmpeg__LIBRARY`` + Path to the library component of FFmpeg. +``FFmpeg__INCLUDE_DIR`` + Directory containing ``.h``. + +#]=======================================================================] + +# cmake-format: off +# cmake-lint: disable=C0103 +# cmake-lint: disable=C0307 +# cmake-format: on + +include(FindPackageHandleStandardArgs) + +set(_DEFAULT_COMPONENTS + avcodec + avdevice + avformat + avfilter + avresample + avutil + postproc + swscale + swresample) + +set(component_avcodec libavcodec avcodec avcodec.h) +set(component_avdevice libavdevice avdevice avdevice.h) +set(component_avformat libavformat avformat avformat.h) +set(component_avfilter libavfilter avfilter avfilter.h) +set(component_avresample libavresample avresample avresample.h) +set(component_avutil libavutil avutil avutil.h) +set(component_postproc libpostproc postproc postprocess.h) +set(component_swscale libswscale swscale swscale.h) +set(component_swresample libswresample swresample swresample.h) + +if(NOT FFmpeg_FIND_COMPONENTS) + set(FFmpeg_FIND_COMPONENTS ${_DEFAULT_COMPONENTS}) +endif() + +# FFmpeg_find_component: Find and set up requested FFmpeg component +macro(FFmpeg_find_component component) + list(GET component_${component} 0 component_libname) + list(GET component_${component} 1 component_name) + list(GET component_${component} 2 component_header) + + if(NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") + find_package(PkgConfig QUIET) + if(PKG_CONFIG_FOUND) + pkg_search_module(PC_FFmpeg_${component} QUIET ${component_libname}) + endif() + endif() + + find_path( + FFmpeg_${component}_INCLUDE_DIR + NAMES ${component_libname}/${component_header} ${component_libname}/version.h + HINTS ${PC_FFmpeg_${component}_INCLUDE_DIRS} + PATHS /usr/include /usr/local/include + DOC "FFmpeg component ${component_name} include directory") + + ffmpeg_check_version() + + if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") + find_library( + FFmpeg_${component}_IMPLIB + NAMES ${component_libname} ${component_name} + DOC "FFmpeg component ${component_name} import library location") + + ffmpeg_find_dll() + else() + find_library( + FFmpeg_${component}_LIBRARY + NAMES ${component_libname} ${component_name} + HINTS ${PC_FFmpeg_${component}_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "FFmpeg component ${component_name} location") + endif() + + if(FFmpeg_${component}_LIBRARY AND FFmpeg_${component}_INCLUDE_DIR) + set(FFmpeg_${component}_FOUND TRUE) + set(FFmpeg_${component}_LIBRARIES ${${_library_var}}) + set(FFmpeg_${component}_INCLUDE_DIRS ${FFmpeg_${component}_INCLUDE_DIR}) + set(FFmpeg_${component}_DEFINITIONS ${PC_FFmpeg_${component}_CFLAGS_OTHER}) + mark_as_advanced(FFmpeg_${component}_LIBRARY FFmpeg_${component}_INCLUDE_DIR FFmpeg_${component}_IMPLIB) + endif() +endmacro() + +# FFmpeg_find_dll: Macro to find DLL for corresponding import library +macro(FFmpeg_find_dll) + cmake_path(GET FFmpeg_${component}_IMPLIB PARENT_PATH _implib_path) + cmake_path(SET _bin_path NORMALIZE "${_implib_path}/../bin") + + string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" _dll_version "${FFmpeg_${component}_VERSION}") + + find_program( + FFmpeg_${component}_LIBRARY + NAMES ${component_name}-${_dll_version}.dll + HINTS ${_implib_path} ${_bin_path} + DOC "FFmpeg component ${component_name} DLL location") + + if(NOT FFmpeg_${component}_LIBRARY) + set(FFmpeg_${component}_LIBRARY "${FFmpeg_${component}_IMPLIB}") + endif() + + unset(_implib_path) + unset(_bin_path) + unset(_dll_version) +endmacro() + +# FFmpeg_check_version: Macro to help extract version number from FFmpeg headers +macro(FFmpeg_check_version) + if(PC_FFmpeg_${component}_VERSION) + set(FFmpeg_${component}_VERSION ${PC_FFmpeg_${component}_VERSION}) + elseif(EXISTS "${FFmpeg_${component}_INCLUDE_DIR}/${component_libname}/version.h") + if(EXISTS "${FFmpeg_${component}_INCLUDE_DIR}/${component_libname}/version_major.h") + file(STRINGS "${FFmpeg_${component}_INCLUDE_DIR}/${component_libname}/version_major.h" _version_string + REGEX "^.*VERSION_MAJOR[ \t]+[0-9]+[ \t]*$") + string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" _version_major "${_version_string}") + + file(STRINGS "${FFmpeg_${component}_INCLUDE_DIR}/${component_libname}/version.h" _version_string + REGEX "^.*VERSION_(MINOR|MICRO)[ \t]+[0-9]+[ \t]*$") + string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" _version_minor "${_version_string}") + string(REGEX REPLACE ".*VERSION_MICRO[ \t]+([0-9]+).*" "\\1" _version_patch "${_version_string}") + else() + file(STRINGS "${FFmpeg_${component}_INCLUDE_DIR}/${component_libname}/version.h" _version_string + REGEX "^.*VERSION_(MAJOR|MINOR|MICRO)[ \t]+[0-9]+[ \t]*$") + string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" _version_major "${_version_string}") + string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" _version_minor "${_version_string}") + string(REGEX REPLACE ".*VERSION_MICRO[ \t]+([0-9]+).*" "\\1" _version_patch "${_version_string}") + endif() + + set(FFmpeg_${component}_VERSION "${_version_major}.${_version_minor}.${_version_patch}") + unset(_version_major) + unset(_version_minor) + unset(_version_patch) + else() + if(NOT FFmpeg_FIND_QUIETLY) + message(AUTHOR_WARNING "Failed to find ${component_name} version.") + endif() + set(FFmpeg_${component}_VERSION 0.0.0) + endif() +endmacro() + +# FFmpeg_set_soname: Set SONAME property on imported library targets +macro(FFmpeg_set_soname) + if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") + execute_process( + COMMAND sh -c "otool -D '${FFmpeg_${component}_LIBRARY}' | grep -v '${FFmpeg_${component}_LIBRARY}'" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0 AND _output MATCHES "^@rpath/") + set_property(TARGET FFmpeg::${component} PROPERTY IMPORTED_SONAME "${_output}") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + execute_process( + COMMAND sh -c "objdump -p '${FFmpeg_${component}_LIBRARY}' | grep SONAME" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0) + string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}") + set_property(TARGET FFmpeg::${component} PROPERTY IMPORTED_SONAME "${_soname}") + unset(_soname) + endif() + endif() + unset(_output) + unset(_result) +endmacro() + +foreach(component IN LISTS FFmpeg_FIND_COMPONENTS) + if(NOT component IN_LIST _DEFAULT_COMPONENTS) + message(FATAL_ERROR "Unknown FFmpeg component specified: ${component}.") + endif() + + if(NOT FFmpeg_${component}_FOUND) + ffmpeg_find_component(${component}) + endif() + + if(FFmpeg_${component}_FOUND) + list(APPEND FFmpeg_LIBRARIES ${FFmpeg_${component}_LIBRARY}) + list(APPEND FFmpeg_DEFINITIONS ${FFmpeg_${component}_DEFINITIONS}) + list(APPEND FFmpeg_INCLUDE_DIRS ${FFmpeg_${component}_INCLUDE_DIR}) + endif() +endforeach() + +if(NOT FFmpeg_avutil_FOUND) + ffmpeg_find_component(avutil) +endif() + +if(EXISTS "${FFmpeg_avutil_INCLUDE_DIR}/libavutil/ffversion.h") + file(STRINGS "${FFmpeg_avutil_INCLUDE_DIR}/libavutil/ffversion.h" _version_string + REGEX "^.*FFMPEG_VERSION[ \t]+\"n[0-9\\.]+\"[ \t]*$") + string(REGEX REPLACE ".*FFMPEG_VERSION[ \t]+\"n([0-9\\.]+)\".*" "\\1" FFmpeg_VERSION "${_version_string}") +endif() + +list(REMOVE_DUPLICATES FFmpeg_INCLUDE_DIRS) +list(REMOVE_DUPLICATES FFmpeg_LIBRARIES) +list(REMOVE_DUPLICATES FFmpeg_DEFINITIONS) + +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows") + set(FFmpeg_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.") +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + set(FFmpeg_ERROR_REASON "Ensure that required FFmpeg libraries are installed on the system.") +endif() + +find_package_handle_standard_args( + FFmpeg + REQUIRED_VARS FFmpeg_LIBRARIES FFmpeg_INCLUDE_DIRS + VERSION_VAR FFmpeg_VERSION + HANDLE_COMPONENTS REASON_FAILURE_MESSAGE "${FFmpeg_ERROR_REASON}") + +if(FFmpeg_FOUND AND NOT TARGET FFmpeg::FFmpeg) + add_library(FFmpeg::FFmpeg INTERFACE IMPORTED) +endif() + +foreach(component IN LISTS FFmpeg_FIND_COMPONENTS) + if(FFmpeg_${component}_FOUND AND NOT TARGET FFmpeg::${component}) + if(IS_ABSOLUTE "${FFmpeg_${component}_LIBRARY}") + if(DEFINED FFmpeg_${component}_IMPLIB) + if(FFmpeg_${component}_IMPLIB STREQUAL FFmpeg_${component}_LIBRARY) + add_library(FFmpeg::${component} STATIC IMPORTED) + else() + add_library(FFmpeg::${component} SHARED IMPORTED) + set_property(TARGET FFmpeg::${component} PROPERTY IMPORTED_IMPLIB "${FFmpeg_${component}_IMPLIB}") + endif() + else() + add_library(FFmpeg::${component} UNKNOWN IMPORTED) + ffmpeg_set_soname() + endif() + + set_property(TARGET FFmpeg::${component} PROPERTY IMPORTED_LOCATION "${FFmpeg_${component}_LIBRARY}") + + else() + add_library(FFmpeg::${component} INTERFACE IMPORTED) + set_property(TARGET FFmpeg::${component} PROPERTY IMPORTED_LIBNAME "${FFmpeg_${component}_LIBRARY}") + endif() + set_target_properties( + FFmpeg::${component} + PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_FFmpeg_${component}_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${FFmpeg_${component}_INCLUDE_DIR}" + VERSION ${FFmpeg_${component}_VERSION}) + + get_target_property(_ffmpeg_interface_libraries FFmpeg::FFmpeg INTERFACE_LINK_LIBRARIES) + if(NOT FFmpeg::${component} IN_LIST _ffmpeg_interface_libraries) + set_property( + TARGET FFmpeg::FFmpeg + APPEND + PROPERTY INTERFACE_LINK_LIBRARIES FFmpeg::${component}) + endif() + endif() +endforeach() + +include(FeatureSummary) +set_package_properties( + FFmpeg PROPERTIES + URL "https://www.ffmpeg.org" + DESCRIPTION "A complete, cross-platform solution to record, convert and stream audio and video.") diff --git a/cmake/finders/FindLibAJANTV2.cmake b/cmake/finders/FindLibAJANTV2.cmake new file mode 100644 index 000000000..333ecb6b9 --- /dev/null +++ b/cmake/finders/FindLibAJANTV2.cmake @@ -0,0 +1,160 @@ +#[=======================================================================[.rst +FindLibAJANTV2 +---------- + +FindModule for LibAJANTV2 and associated libraries + +.. versionchanged:: 3.0 + Updated FindModule to CMake standards + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 2.0 + +This module defines the :prop_tgt:`IMPORTED` target ``LibAJANTV2::LibAJANTV2``. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module sets the following variables: + +``LibAJANTV2_FOUND`` + True, if all required components and the core library were found. +``LibAJANTV2_VERSION`` + Detected version of found LibAJANTV2 libraries. +``LibAJANTV2_INCLUDE_DIRS`` + Include directories needed for LibAJANTV2. +``LibAJANTV2_LIBRARIES`` + Libraries needed to link to LibAJANTV2. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``LibAJANTV2_LIBRARY_RELEASE`` + Path to the library component of LibAJANTV2 in non-debug configuration. +``LibAJANTV2_LIBRARY_DEBUG`` + Optional path to the library component of LibAJANTV2 in debug configuration. +``LibAJANTV2_INCLUDE_DIR`` + Directory containing ``LibAJANTV2.h``. + +#]=======================================================================] + +# cmake-format: off +# cmake-lint: disable=C0103 +# cmake-lint: disable=C0301 +# cmake-lint: disable=C0307 +# cmake-format: on + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_LibAJANTV2 QUIET ajantv2) +endif() + +find_path( + LibAJANTV2_INCLUDE_DIR + NAMES ajalibraries + HINTS ${PC_LibAJANTV2_INCLUDE_DIRS} + PATHS /usr/include /usr/local/include + DOC "LibAJANTV2 include directory") + +find_library( + LibAJANTV2_LIBRARY_RELEASE + NAMES ajantv2 libajantv2 + HINTS ${PC_LibAJANTV2_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "LibAJANTV2 location") + +find_library( + LibAJANTV2_LIBRARY_DEBUG + NAMES ajantv2d libajantv2d + HINTS ${PC_LibAJANTV2_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "LibAJANTV2 debug location.") + +if(PC_LibAJANTV2_VERSION VERSION_GREATER 0) + set(LibAJANTV2_VERSION ${PC_LibAJANTV2_VERSION}) +else() + if(NOT LibAJANTV2_FIND_QUIETLY) + message(AUTHOR_WARNING "Failed to find LibAJANTV2 version.") + endif() + set(LibAJANTV2_VERSION 0.0.0) +endif() + +include(SelectLibraryConfigurations) +select_library_configurations(LibAJANTV2) + +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows") + set(LibAJANTV2_ERROR_REASON "Ensure obs-deps is provided as part of CMAKE_PREFIX_PATH.") +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + set(LibAJANTV2_ERROR_REASON "Ensure ajantv2 static libraries are available in local library paths.") +endif() + +find_package_handle_standard_args( + LibAJANTV2 + REQUIRED_VARS LibAJANTV2_LIBRARY LibAJANTV2_INCLUDE_DIR + VERSION_VAR LibAJANTV2_VERSION REASON_FAILURE_MESSAGE LibAJANTV2_ERROR_REASON) +mark_as_advanced(LibAJANTV2_LIBRARY LibAJANTV2_INCLUDE_DIR) +unset(LibAJANTV2_ERROR_REASON) + +if(LibAJANTV2_FOUND) + list( + APPEND + LibAJANTV2_INCLUDE_DIRS + ${LibAJANTV2_INCLUDE_DIR}/ajalibraries + ${LibAJANTV2_INCLUDE_DIR}/ajalibraries/ajaanc + ${LibAJANTV2_INCLUDE_DIR}/ajalibraries/ajabase + ${LibAJANTV2_INCLUDE_DIR}/ajalibraries/ajantv2 + ${LibAJANTV2_INCLUDE_DIR}/ajalibraries/ajantv2/includes) + set(LibAJANTV2_LIBRARIES ${LibAJANTV2_LIBRARY}) + mark_as_advanced(LibAJANTV2_INCLUDE_DIR LibAJANTV2_LIBRARY) + + if(NOT TARGET AJA::LibAJANTV2) + if(IS_ABSOLUTE "${LibAJANTV2_LIBRARY_RELEASE}") + add_library(AJA::LibAJANTV2 STATIC IMPORTED) + set_property(TARGET AJA::LibAJANTV2 PROPERTY IMPORTED_LOCATION "${LibAJANTV2_LIBRARY_RELEASE}") + else() + add_library(AJA::LibAJANTV2 INTERFACE IMPORTED) + set_property(TARGET AJA::LibAJANTV2 PROPERTY IMPORTED_LIBNAME "${LibAJANTV2_LIBRARY_RELEASE}") + endif() + + set_target_properties( + AJA::LibAJANTV2 + PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_LibAJANTV2_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${LibAJANTV2_INCLUDE_DIR}" + VERSION ${LibAJANTV2_VERSION} + IMPORTED_CONFIGURATIONS Release) + + if(LibAJANTV2_LIBRARY_DEBUG) + if(IS_ABSOLUTE "${LibAJANTV2_LIBRARY_DEBUG}") + set_property(TARGET AJA::LibAJANTV2 PROPERTY IMPORTED_LOCATION_DEBUG "${LibAJANTV2_LIBRARY_DEBUG}") + else() + set_property(TARGET AJA::LibAJANTV2 PROPERTY IMPORTED_LIBNAME_DEBUG "${LibAJANTV2_LIBRARY_DEBUG}") + endif() + set_property( + TARGET AJA::LibAJANTV2 + APPEND + PROPERTY IMPORTED_CONFIGURATIONS Debug) + endif() + + set_target_properties(AJA::LibAJANTV2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LibAJANTV2_INCLUDE_DIRS}") + set_property( + TARGET AJA::LibAJANTV2 + APPEND + PROPERTY INTERFACE_COMPILE_DEFINITIONS "$<$:AJA_WINDOWS;_WINDOWS;WIN32;MSWindows>" + "$<$,$>:_DEBUG;_NDEBUG>" "$<$:AJAMac;AJA_MAC>" + "$<$:AJA_LINUX;AJALinux>") + endif() +endif() + +include(FeatureSummary) +set_package_properties( + LibAJANTV2 PROPERTIES + URL "https://www.aja.com" + DESCRIPTION + "AJA NTV2 SDK - AJA simplifies professional digital video workflows with a line of award-winning products designed and manufactured in Grass Valley, CA." +) diff --git a/cmake/finders/FindLibVLC.cmake b/cmake/finders/FindLibVLC.cmake new file mode 100644 index 000000000..5a17b7300 --- /dev/null +++ b/cmake/finders/FindLibVLC.cmake @@ -0,0 +1,111 @@ +#[=======================================================================[.rst +FindLibVLC +---------- + +FindModule for LibVLC and associated libraries + +.. versionchanged:: 3.0 + Updated FindModule to CMake standards + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 2.0 + +This module defines the :prop_tgt:`IMPORTED` target ``VLC::LibVLC``. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module sets the following variables: + +``LibVLC_FOUND`` + True, if all required components and the core library were found. +``LibVLC_VERSION`` + Detected version of found LibVLC libraries. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``LibVLC_LIBRARY`` + Path to the library component of LibVLC. +``LibVLC_INCLUDE_DIR`` + Directory containing ``libvlc.h``. + +#]=======================================================================] + +# cmake-format: off +# cmake-lint: disable=C0103 +# cmake-lint: disable=C0301 +# cmake-format: on + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_LibVLC QUIET libvlc) +endif() + +find_path( + LibVLC_INCLUDE_DIR + NAMES libvlc.h + HINTS ${PC_LibVLC_INCLUDE_DIRS} + PATHS /usr/include /usr/local/include + PATH_SUFFIXES vlc include/vlc include + DOC "LibVLC include directory") + +find_library( + LibVLC_LIBRARY + NAMES vlc libvlc + HINTS ${PC_LibVLC_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "LibVLC location") + +if(PC_LibVLC_VERSION VERSION_GREATER 0) + set(LibVLC_VERSION ${PC_LibVLC_VERSION}) +elseif(EXISTS "${LibVLC_INCLUDE_DIR}/libvlc_version.h") + file(STRINGS "${LibVLC_INCLUDE_DIR}/libvlc_version.h" _VERSION_STRING + REGEX "^.*LIBVLC_VERSION_(MAJOR|MINOR|PATCH)[ \t]+[0-9]+[ \t]*$") + string(REGEX REPLACE ".*LIBVLC_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" VERSION_MAJOR "${_VERSION_STRING}") + string(REGEX REPLACE ".*LIBVLC_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" VERSION_MINOR "${_VERSION_STRING}") + string(REGEX REPLACE ".*LIBVLC_VERSION_REVISION[ \t]+([0-9]+).*" "\\1" VERSION_REVISION "${_VERSION_STRING}") + set(LibVLC_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}") +else() + if(NOT LibVLC_FIND_QUIETLY) + message(AUTHOR_WARNING "Failed to find LibVLC version.") + endif() + set(LibVLC_VERSION 0.0.0) +endif() + +find_package_handle_standard_args( + LibVLC + REQUIRED_VARS LibVLC_LIBRARY LibVLC_INCLUDE_DIR + VERSION_VAR LibVLC_VERSION REASON_FAILURE_MESSAGE "Ensure that libvlc-dev (vlc on BSD) is installed on the system.") +mark_as_advanced(LibVLC_INCLUDE_DIR LibVLC_LIBRARY) + +if(LibVLC_FOUND) + if(NOT TARGET VLC::LibVLC) + if(IS_ABSOLUTE "${LibVLC_LIBRARY}") + add_library(VLC::LibVLC UNKNOWN IMPORTED) + set_property(TARGET VLC::LibVLC PROPERTY IMPORTED_LOCATION "${LibVLC_LIBRARY}") + else() + add_library(VLC::LibVLC INTERFACE IMPORTED) + set_property(TARGET VLC::LibVLC PROPERTY IMPORTED_LIBNAME "${LibVLC_LIBRARY}") + endif() + + set_target_properties( + VLC::LibVLC + PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_LibVLC_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${LibVLC_INCLUDE_DIR}" + VERSION ${LibVLC_VERSION}) + endif() +endif() + +include(FeatureSummary) +set_package_properties( + LibVLC PROPERTIES + URL "https://www.videolan.org/vlc/libvlc.html" + DESCRIPTION + "libVLC is the core engine and the interface to the multimedia framework on which VLC media player is based.") diff --git a/cmake/finders/FindLibrist.cmake b/cmake/finders/FindLibrist.cmake new file mode 100644 index 000000000..bfd89df3c --- /dev/null +++ b/cmake/finders/FindLibrist.cmake @@ -0,0 +1,142 @@ +#[=======================================================================[.rst +FindLibrist +---------- + +FindModule for Librist and associated libraries + +.. versionchanged:: 3.0 + Updated FindModule to CMake standards + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 2.0 + +This module defines the :prop_tgt:`IMPORTED` target ``Librist::Librist``. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module sets the following variables: + +``Librist_FOUND`` + True, if all required components and the core library were found. +``Librist_VERSION`` + Detected version of found Librist libraries. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``Librist_LIBRARY`` + Path to the library component of Librist. +``Librist_INCLUDE_DIR`` + Directory containing ``librist.h``. + +#]=======================================================================] + +# cmake-format: off +# cmake-lint: disable=C0103 +# cmake-format: on + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_Librist QUIET librist) +endif() + +# Librist_set_soname: Set SONAME on imported library target +macro(Librist_set_soname) + if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") + execute_process( + COMMAND sh -c "otool -D '${Librist_LIBRARY}' | grep -v '${Librist_LIBRARY}'" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0 AND _output MATCHES "^@rpath/") + set_property(TARGET Librist::Librist PROPERTY IMPORTED_SONAME "${_output}") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + execute_process( + COMMAND sh -c "objdump -p '${Librist_LIBRARY}' | grep SONAME" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0) + string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}") + set_property(TARGET Librist::Librist PROPERTY IMPORTED_SONAME "${_soname}") + unset(_soname) + endif() + endif() + unset(_output) + unset(_result) +endmacro() + +find_path( + Librist_INCLUDE_DIR + NAMES librist.h librist/librist.h + HINTS ${PC_Librist_INCLUDE_DIRS} + PATHS /usr/include /usr/local/include + DOC "Librist include directory") + +if(PC_Librist_VERSION VERSION_GREATER 0) + set(Librist_VERSION ${PC_Librist_VERSION}) +elseif(EXISTS "${Librist_INCLUDE_DIR}/version.h") + file(STRINGS "${_VERSION_FILE}" _VERSION_STRING REGEX "^.*VERSION_(MAJOR|MINOR|PATCH)[ \t]+[0-9]+[ \t]*$") + string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" _VERSION_MAJOR "${_VERSION_STRING}") + string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" _VERSION_MINOR "${_VERSION_STRING}") + string(REGEX REPLACE ".*VERSION_PATCH[ \t]+([0-9]+).*" "\\1" _VERSION_PATCH "${_VERSION_STRING}") + set(Librist_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}") +else() + if(NOT Librist_FIND_QUIETLY) + message(AUTHOR_WARNING "Failed to find Librist version.") + endif() + set(Librist_VERSION 0.0.0) +endif() + +find_library( + Librist_LIBRARY + NAMES librist rist + HINTS ${PC_Librist_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "Librist location") + +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows") + set(Librist_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.") +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + set(Librist_ERROR_REASON "Ensure librist libraries are available in local library paths.") +endif() + +find_package_handle_standard_args( + Librist + REQUIRED_VARS Librist_LIBRARY Librist_INCLUDE_DIR + VERSION_VAR Librist_VERSION REASON_FAILURE_MESSAGE "${Librist_ERROR_REASON}") +mark_as_advanced(Librist_INCLUDE_DIR Librist_LIBRARY) +unset(Librist_ERROR_REASON) + +if(Librist_FOUND) + if(NOT TARGET Librist::Librist) + if(IS_ABSOLUTE "${Librist_LIBRARY}") + add_library(Librist::Librist UNKNOWN IMPORTED) + set_property(TARGET Librist::Librist PROPERTY IMPORTED_LOCATION "${Librist_LIBRARY}") + else() + add_library(Librist::Librist INTERFACE IMPORTED) + set_property(TARGET Librist::Librist PROPERTY IMPORTED_LIBNAME "${Librist_LIBRARY}") + endif() + + librist_set_soname() + set_target_properties( + Librist::Librist + PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_Librist_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${Librist_INCLUDE_DIR}" + VERSION ${Librist_VERSION}) + endif() +endif() + +include(FeatureSummary) +set_package_properties( + Librist PROPERTIES + URL "https://code.videolan.org/rist/librist" + DESCRIPTION "A library that can be used to easily add the RIST protocol to your application.") diff --git a/cmake/finders/FindLibrnnoise.cmake b/cmake/finders/FindLibrnnoise.cmake new file mode 100644 index 000000000..21424ec93 --- /dev/null +++ b/cmake/finders/FindLibrnnoise.cmake @@ -0,0 +1,137 @@ +#[=======================================================================[.rst +FindLibrnnoise +---------- + +FindModule for Librnnoise and associated libraries + +.. versionchanged:: 3.0 + Updated FindModule to CMake standards + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 2.0 + +This module defines the :prop_tgt:`IMPORTED` target ``Librnnoise::Librnnoise``. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module sets the following variables: + +``Librnnoise_FOUND`` + True, if all required components and the core library were found. +``Librnnoise_VERSION`` + Detected version of found Librnnoise libraries. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``Librnnoise_LIBRARY`` + Path to the library component of Librnnoise. +``Librnnoise_INCLUDE_DIR`` + Directory containing ``rnnoise.h``. + +#]=======================================================================] + +# cmake-format: off +# cmake-lint: disable=C0103 +# cmake-lint: disable=C0307 +# cmake-format: on + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_Librnnoise QUIET rnnoise) +endif() + +# librrnoise_set_soname: Set SONAME on imported library target +macro(librnnoise_set_soname) + if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") + execute_process( + COMMAND sh -c "otool -D '${Librnnoise_LIBRARY}' | grep -v '${Librnnoise_LIBRARY}'" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0 AND _output MATCHES "^@rpath/") + set_property(TARGET Librnnoise::Librnnoise PROPERTY IMPORTED_SONAME "${_output}") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + execute_process( + COMMAND sh -c "objdump -p '${Librnnoise_LIBRARY}' | grep SONAME" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0) + string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}") + set_property(TARGET Librnnoise::Librnnoise PROPERTY IMPORTED_SONAME "${_soname}") + unset(_soname) + endif() + endif() + unset(_output) + unset(_result) +endmacro() + +find_path( + Librnnoise_INCLUDE_DIR + NAMES rnnoise.h + HINTS ${PC_Librnnoise_INCLUDE_DIRS} + PATHS /usr/include /usr/local/include + DOC "Librnnoise include directory") + +if(PC_Librnnoise_VERSION VERSION_GREATER 0) + set(Librnnoise_VERSION ${PC_Librnnoise_VERSION}) +else() + if(NOT Librnnoise_FIND_QUIETLY) + message(AUTHOR_WARNING "Failed to find Librnnoise version.") + endif() + set(Librnnoise_VERSION 0.0.0) +endif() + +find_library( + Librnnoise_LIBRARY + NAMES rnnoise librnnoise + HINTS ${PC_Librnnoise_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "Librnnoise location") + +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows") + set(Librnnoise_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.") +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + set(Librnnoise_ERROR_REASON "Ensure librnnoise libraries are available in local libary paths.") +endif() + +find_package_handle_standard_args( + Librnnoise + REQUIRED_VARS Librnnoise_LIBRARY Librnnoise_INCLUDE_DIR + VERSION_VAR Librnnoise_VERSION REASON_FAILURE_MESSAGE "${Librnnoise_ERROR_REASON}") +mark_as_advanced(Librnnoise_INCLUDE_DIR Librnnoise_LIBRARY) +unset(Librnnoise_ERROR_REASON) + +if(Librnnoise_FOUND) + if(NOT TARGET Librnnoise::Librnnoise) + if(IS_ABSOLUTE "${Librnnoise_LIBRARY}") + add_library(Librnnoise::Librnnoise UNKNOWN IMPORTED) + librnnoise_set_soname() + set_property(TARGET Librnnoise::Librnnoise PROPERTY IMPORTED_LOCATION "${Librnnoise_LIBRARY}") + else() + add_library(Librnnoise::Librnnoise INTERFACE IMPORTED) + set_property(TARGET Librnnoise::Librnnoise PROPERTY IMPORTED_LIBNAME "${Librnnoise_LIBRARY}") + endif() + + set_target_properties( + Librnnoise::Librnnoise + PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_Librnnoise_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${Librnnoise_INCLUDE_DIR}" + VERSION ${Librnnoise_VERSION}) + endif() +endif() + +include(FeatureSummary) +set_package_properties( + Librnnoise PROPERTIES + URL "https://gitlab.xiph.org/xiph/rnnoise" + DESCRIPTION "Recurrent neural network for audio noise reduction.") diff --git a/cmake/finders/FindLibspeexdsp.cmake b/cmake/finders/FindLibspeexdsp.cmake new file mode 100644 index 000000000..14981f7d9 --- /dev/null +++ b/cmake/finders/FindLibspeexdsp.cmake @@ -0,0 +1,137 @@ +#[=======================================================================[.rst +FindLibspeexdsp +---------- + +FindModule for Libspeexdsp and associated libraries + +.. versionchanged:: 3.0 + Updated FindModule to CMake standards + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 2.0 + +This module defines the :prop_tgt:`IMPORTED` target ``SpeexDSP::Libspeexdsp``. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module sets the following variables: + +``Libspeexdsp_FOUND`` + True, if all required components and the core library were found. +``Libspeexdsp_VERSION`` + Detected version of found Libspeexdsp libraries. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``Libspeexdsp_LIBRARY`` + Path to the library component of Libspeexdsp. +``Libspeexdsp_INCLUDE_DIR`` + Directory containing ``speex/speex_preprocess.h``. + +#]=======================================================================] + +# cmake-format: off +# cmake-lint: disable=C0103 +# cmake-lint: disable=C0307 +# cmake-format: on + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_Libspeexdsp QUIET speexdsp) +endif() + +# libspeexdsp_set_soname: Set SONAME on imported library target +macro(libspeexdsp_set_soname) + if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") + execute_process( + COMMAND sh -c "otool -D '${Libspeexdsp_LIBRARY}' | grep -v '${Libspeexdsp_LIBRARY}'" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0 AND _output MATCHES "^@rpath/") + set_property(TARGET SpeexDSP::Libspeexdsp PROPERTY IMPORTED_SONAME "${_output}") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + execute_process( + COMMAND sh -c "objdump -p '${Libspeexdsp_LIBRARY}' | grep SONAME" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0) + string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}") + set_property(TARGET SpeexDSP::Libspeexdsp PROPERTY IMPORTED_SONAME "${_soname}") + unset(_soname) + endif() + endif() + unset(_output) + unset(_result) +endmacro() + +find_path( + Libspeexdsp_INCLUDE_DIR + NAMES speex/speex_preprocess.h + HINTS ${PC_Libspeexdsp_INCLUDE_DIRS} + PATHS /usr/include /usr/local/include + DOC "Libspeexdsp include directory") + +if(PC_Libspeexdsp_VERSION VERSION_GREATER 0) + set(Libspeexdsp_VERSION ${PC_Libspeexdsp_VERSION}) +else() + if(NOT Libspeexdsp_FIND_QUIETLY) + message(AUTHOR_WARNING "Failed to find Libspeexdsp version.") + endif() + set(Libspeexdsp_VERSION 0.0.0) +endif() + +find_library( + Libspeexdsp_LIBRARY + NAMES speexdsp libspeexdsp + HINTS ${PC_Libspeexdsp_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "Libspeexdsp location") + +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows") + set(Libspeexdsp_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.") +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + set(Libspeexdsp_ERROR_REASON "Ensure that libspeexdsp is installed on the system.") +endif() + +find_package_handle_standard_args( + Libspeexdsp + REQUIRED_VARS Libspeexdsp_LIBRARY Libspeexdsp_INCLUDE_DIR + VERSION_VAR Libspeexdsp_VERSION REASON_FAILURE_MESSAGE "${Libspeexdsp_ERROR_REASON}") +mark_as_advanced(Libspeexdsp_INCLUDE_DIR Libspeexdsp_LIBRARY) +unset(Libspeexdsp_ERROR_REASON) + +if(Libspeexdsp_FOUND) + if(NOT TARGET SpeexDSP::Libspeexdsp) + if(IS_ABSOLUTE "${Libspeexdsp_LIBRARY}") + add_library(SpeexDSP::Libspeexdsp UNKNOWN IMPORTED) + set_property(TARGET SpeexDSP::Libspeexdsp PROPERTY IMPORTED_LOCATION "${Libspeexdsp_LIBRARY}") + else() + add_library(SpeexDSP::Libspeexdsp INTERFACE IMPORTED) + set_property(TARGET SpeexDSP::Libspeexdsp PROPERTY IMPORTED_LIBNAME "${Libspeexdsp_LIBRARY}") + endif() + + libspeexdsp_set_soname() + set_target_properties( + SpeexDSP::Libspeexdsp + PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_Libspeexdsp_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${Libspeexdsp_INCLUDE_DIR}" + VERSION ${Libspeexdsp_VERSION}) + endif() +endif() + +include(FeatureSummary) +set_package_properties( + Libspeexdsp PROPERTIES + URL "https://gitlab.xiph.org/xiph/speexdsp" + DESCRIPTION "DSP library derived from speex.") diff --git a/cmake/finders/FindLibsrt.cmake b/cmake/finders/FindLibsrt.cmake new file mode 100644 index 000000000..51413cf50 --- /dev/null +++ b/cmake/finders/FindLibsrt.cmake @@ -0,0 +1,139 @@ +#[=======================================================================[.rst +FindLibsrt +---------- + +FindModule for Libsrt and associated libraries + +.. versionchanged:: 3.0 + Updated FindModule to CMake standards + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 2.0 + +This module defines the :prop_tgt:`IMPORTED` target ``Libsrt::Libsrt``. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module sets the following variables: + +``Libsrt_FOUND`` + True, if all required components and the core library were found. +``Libsrt_VERSION`` + Detected version of found Libsrt libraries. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``Libsrt_LIBRARY`` + Path to the library component of Libsrt. +``Libsrt_INCLUDE_DIR`` + Directory containing ``srt.h``. + +#]=======================================================================] + +# cmake-format: off +# cmake-lint: disable=C0103 +# cmake-lint: disable=C0301 +# cmake-format: on + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_Libsrt QUIET libsrt) +endif() + +# libsrt_set_soname: Set SONAME on imported library target +macro(libsrt_set_soname) + if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") + execute_process( + COMMAND sh -c "otool -D '${Libsrt_LIBRARY}' | grep -v '${Libsrt_LIBRARY}'" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0 AND _output MATCHES "^@rpath/") + set_property(TARGET Libsrt::Libsrt PROPERTY IMPORTED_SONAME "${_output}") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + execute_process( + COMMAND sh -c "objdump -p '${Libsrt_LIBRARY}' | grep SONAME" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0) + string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}") + set_property(TARGET Libsrt::Libsrt PROPERTY IMPORTED_SONAME "${_soname}") + unset(_soname) + endif() + endif() + unset(_output) + unset(_result) +endmacro() + +find_path( + Libsrt_INCLUDE_DIR + NAMES srt.h srt/srt.h + HINTS ${PC_Libsrt_INCLUDE_DIRS} + PATHS /usr/include /usr/local/include + DOC "Libsrt include directory") + +if(PC_Libsrt_VERSION VERSION_GREATER 0) + set(Libsrt_VERSION ${PC_Libsrt_VERSION}) +elseif(EXISTS "${Libsrt_INCLUDE_DIR}/version.h") + file(STRINGS "${Libsrt_INCLUDE_DIR}/version.h" _VERSION_STRING REGEX "#define[ \t]+SRT_VERSION_STRING[ \t]+.+") + string(REGEX REPLACE ".*#define[ \t]+SRT_VERSION_STRING[ \t]+\"(.+)\".*" "\\1" Libsrt_VERSION "${_VERSION_STRING}") +else() + if(NOT Libsrt_FIND_QUIETLY) + message(AUTHOR_WARNING "Failed to find Libsrt version.") + endif() + set(Libsrt_VERSION 0.0.0) +endif() + +find_library( + Libsrt_LIBRARY + NAMES srt libsrt + HINTS ${PC_Libsrt_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "Libsrt location") + +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows") + set(Libsrt_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.") +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + set(Libsrt_ERROR_REASON "Ensure libsrt libraries are available in local library paths.") +endif() + +find_package_handle_standard_args( + Libsrt + REQUIRED_VARS Libsrt_LIBRARY Libsrt_INCLUDE_DIR + VERSION_VAR Libsrt_VERSION REASON_FAILURE_MESSAGE "${Libsrt_ERROR_REASON}") +mark_as_advanced(Libsrt_INCLUDE_DIR Libsrt_LIBRARY) +unset(Libsrt_ERROR_REASON) + +if(Libsrt_FOUND) + if(NOT TARGET Libsrt::Libsrt) + if(IS_ABSOLUTE "${Libsrt_LIBRARY}") + add_library(Libsrt::Libsrt UNKNOWN IMPORTED) + libsrt_set_soname() + set_property(TARGET Libsrt::Libsrt PROPERTY IMPORTED_LOCATION "${Libsrt_LIBRARY}") + else() + add_library(Libsrt::Libsrt INTERFACE IMPORTED) + set_property(TARGET Libsrt::Libsrt PROPERTY IMPORTED_LIBNAME "${Libsrt_LIBRARY}") + endif() + + set_target_properties(Libsrt::Libsrt PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_Libsrt_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${Libsrt_INCLUDE_DIR}") + endif() +endif() + +include(FeatureSummary) +set_package_properties( + Libsrt PROPERTIES + URL "https://www.srtalliance.org" + DESCRIPTION + "Secure Reliable Transport (SRT) is a transport protocol for ultra low (sub-second) latency live video and audio streaming, as well as for generic bulk data transfer." +) diff --git a/cmake/finders/FindLibx264.cmake b/cmake/finders/FindLibx264.cmake new file mode 100644 index 000000000..123a32653 --- /dev/null +++ b/cmake/finders/FindLibx264.cmake @@ -0,0 +1,182 @@ +#[=======================================================================[.rst +FindLibx264 +---------- + +FindModule for Libx264 and associated libraries + +.. versionchanged:: 3.0 + Updated FindModule to CMake standards + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 2.0 + +This module defines the :prop_tgt:`IMPORTED` target ``Libx264::Libx264``. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module sets the following variables: + +``Libx264_FOUND`` + True, if all required components and the core library were found. +``Libx264_VERSION`` + Detected version of found Libx264 libraries. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``Libx264_LIBRARY`` + Path to the library component of Libx264. +``Libx264_INCLUDE_DIR`` + Directory containing ``x264.h``. + +#]=======================================================================] + +# cmake-format: off +# cmake-lint: disable=C0103 +# cmake-lint: disable=C0301 +# cmake-format: on + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_Libx264 QUIET x264) +endif() + +# Libx264_set_soname: Set SONAME on imported library target +macro(Libx264_set_soname) + if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") + execute_process( + COMMAND sh -c "otool -D '${Libx264_LIBRARY}' | grep -v '${Libx264_LIBRARY}'" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0 AND _output MATCHES "^@rpath/") + set_property(TARGET Libx264::Libx264 PROPERTY IMPORTED_SONAME "${_output}") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + execute_process( + COMMAND sh -c "objdump -p '${Libx264_LIBRARY}' | grep SONAME" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0) + string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}") + set_property(TARGET Libx264::Libx264 PROPERTY IMPORTED_SONAME "${_soname}") + unset(_soname) + endif() + endif() + unset(_output) + unset(_result) +endmacro() + +# Libx264_find_dll: Find DLL for corresponding import library +macro(Libx264_find_dll) + cmake_path(GET Libx264_IMPLIB PARENT_PATH _implib_path) + cmake_path(SET _bin_path NORMALIZE "${_implib_path}/../bin") + + string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" _dll_version "${Libx264_VERSION}") + + find_program( + Libx264_LIBRARY + NAMES libx264-${_dll_version}.dll x264-${_dll_version}.dll libx264.dll x264.dll + HINTS ${_implib_path} ${_bin_path} + DOC "Libx264 DLL location") + + if(NOT Libx264_LIBRARY) + set(Libx264_LIBRARY "${Libx264_IMPLIB}") + endif() + unset(_implib_path) + unset(_bin_path) + unset(_dll_version) +endmacro() + +find_path( + Libx264_INCLUDE_DIR + NAMES x264.h + HINTS ${PC_Libx264_INCLUDE_DIRS} + PATHS /usr/include /usr/local/include + DOC "Libx264 include directory") + +if(PC_Libx264_VERSION VERSION_GREATER 0) + set(Libx264_VERSION ${PC_Libx264_VERSION}) +elseif(EXISTS "${Libx264_INCLUDE_DIR}/x264_config.h") + file(STRINGS "${Libx264_INCLUDE_DIR}/x264_config.h" _VERSION_STRING REGEX "#define[ \t]+X264_POINTVER[ \t]+.+") + string(REGEX REPLACE ".*#define[ \t]+X264_POINTVER[ \t]+\"(.+)[ \t]+.+\".*" "\\1" Libx264_VERSION + "${_VERSION_STRING}") +else() + if(NOT Libx264_FIND_QUIETLY) + message(AUTHOR_WARNING "Failed to find Libx264 version.") + endif() + set(Libx264_VERSION 0.0.0) +endif() + +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") + find_library( + Libx264_IMPLIB + NAMES x264 libx264 + DOC "Libx264 import library location") + + libx264_find_dll() +else() + find_library( + Libx264_LIBRARY + NAMES x264 libx264 + HINTS ${PC_Libx264_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "Libx264 location") +endif() + +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows") + set(Libx264_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.") +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + set(Libx264_ERROR_REASON "Ensure that x264 is installed on the system.") +endif() + +find_package_handle_standard_args( + Libx264 + REQUIRED_VARS Libx264_LIBRARY Libx264_INCLUDE_DIR + VERSION_VAR Libx264_VERSION REASON_FAILURE_MESSAGE "${Libx264_ERROR_REASON}") +mark_as_advanced(Libx264_INCLUDE_DIR Libx264_LIBRARY Libx264_IMPLIB) +unset(Libx264_ERROR_REASON) + +if(Libx264_FOUND) + if(NOT TARGET Libx264::Libx264) + if(IS_ABSOLUTE "${Libx264_LIBRARY}") + if(DEFINED Libx264_IMPLIB) + if(Libx264_IMPLIB STREQUAL Libx264_LIBRARY) + add_library(Libx264::Libx264 STATIC IMPORTED) + else() + add_library(Libx264::Libx264 SHARED IMPORTED) + set_property(TARGET Libx264::Libx264 PROPERTY IMPORTED_IMPLIB "${Libx264_IMPLIB}") + endif() + else() + add_library(Libx264::Libx264 UNKNOWN IMPORTED) + endif() + set_property(TARGET Libx264::Libx264 PROPERTY IMPORTED_LOCATION "${Libx264_LIBRARY}") + else() + add_library(Libx264::Libx264 INTERFACE IMPORTED) + set_property(TARGET Libx264::Libx264 PROPERTY IMPORTED_LIBNAME "${Libx264_LIBRARY}") + endif() + + libx264_set_soname() + set_target_properties( + Libx264::Libx264 + PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_Libx264_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${Libx264_INCLUDE_DIR}" + VERSION ${Libx264_VERSION}) + endif() +endif() + +include(FeatureSummary) +set_package_properties( + Libx264 PROPERTIES + URL "https://www.videolan.org/developers/x264.html" + DESCRIPTION + "x264 is a free software library and application for encoding video streams into the H.264/MPEG-4 AVC compression format." +) diff --git a/cmake/finders/FindLuajit.cmake b/cmake/finders/FindLuajit.cmake new file mode 100644 index 000000000..a329dddb3 --- /dev/null +++ b/cmake/finders/FindLuajit.cmake @@ -0,0 +1,139 @@ +#[=======================================================================[.rst +FindLuajit +---------- + +FindModule for Luajit and associated libraries + +.. versionchanged:: 3.0 + Updated FindModule to CMake standards + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 2.0 + +This module defines the :prop_tgt:`IMPORTED` target ``Luajit::Luajit``. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module sets the following variables: + +``Luajit_FOUND`` + True, if all required components and the core library were found. +``Luajit_VERSION`` + Detected version of found Luajit libraries. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``Luajit_LIBRARY`` + Path to the library component of Luajit. +``Luajit_INCLUDE_DIR`` + Directory containing ``luajit.h`` or ``lua.h``. + +#]=======================================================================] + +# cmake-format: off +# cmake-lint: disable=C0103 +# cmake-format: on + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_Luajit QUIET luajit) +endif() + +# Luajit_set_soname: Set SONAME on imported library target +macro(Luajit_set_soname) + if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") + execute_process( + COMMAND sh -c "otool -D '${Luajit_LIBRARY}' | grep -v '${Luajit_LIBRARY}'" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0 AND _output MATCHES "^@rpath/") + set_property(TARGET Luajit::Luajit PROPERTY IMPORTED_SONAME "${_output}") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + execute_process( + COMMAND sh -c "objdump -p '${Luajit_LIBRARY}' | grep SONAME" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0) + string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}") + set_property(TARGET Luajit::Luajit PROPERTY IMPORTED_SONAME "${_soname}") + unset(_soname) + endif() + endif() + unset(_output) + unset(_result) +endmacro() + +find_path( + Luajit_INCLUDE_DIR + NAMES lua.h luajit.h + HINTS ${PC_Luajit_INCLUDE_DIRS} + PATHS /usr/include /usr/local/include + PATH_SUFFIXES luajit-2.1 luajit + DOC "Luajit include directory") + +if(PC_Luajit_VERSION VERSION_GREATER 0) + set(Luajit_VERSION ${PC_Luajit_VERSION}) +elseif(EXISTS "${Luajit_INCLUDE_DIR}/lua.h") + file(STRINGS "${Luajit_INCLUDE_DIR}/lua.h" _VERSION_STRING REGEX "#define[ \t]+LUA_RELEASE[ \t]+.+") + string(REGEX REPLACE ".*#define[ \t]+LUA_RELEASE[ \t]+\"Lua (.+)\".*" "\\1" Luajit_VERSION "${_VERSION_STRING}") +else() + if(NOT Luajit_FIND_QUIETLY) + message(AUTHOR_WARNING "Failed to find Luajit version.") + endif() +endif() + +find_library( + Luajit_LIBRARY + NAMES luajit luajit-51 luajit-5.1 lua51 + HINTS ${PC_Luajit_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "Luajit location") + +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows") + set(Luajit_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.") +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + set(Luajit_ERROR_REASON "Ensure that LuaJIT is installed on the system.") +endif() + +find_package_handle_standard_args( + Luajit + REQUIRED_VARS Luajit_LIBRARY Luajit_INCLUDE_DIR + VERSION_VAR Luajit_VERSION REASON_FAILURE_MESSAGE "${Luajit_ERROR_REASON}") +mark_as_advanced(Luajit_INCLUDE_DIR Luajit_LIBRARY) +unset(Luajit_ERROR_REASON) + +if(Luajit_FOUND) + if(NOT TARGET Luajit::Luajit) + if(IS_ABSOLUTE "${Luajit_LIBRARY}") + add_library(Luajit::Luajit UNKNOWN IMPORTED) + set_property(TARGET Luajit::Luajit PROPERTY IMPORTED_LOCATION "${Luajit_LIBRARY}") + else() + add_library(Luajit::Luajit INTERFACE IMPORTED) + set_property(TARGET Luajit::Luajit PROPERTY IMPORTED_LIBNAME "${Luajit_LIBRARY}") + endif() + + luajit_set_soname() + set_target_properties( + Luajit::Luajit + PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_Luajit_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${Luajit_INCLUDE_DIR}" + VERSION ${Luajit_VERSION}) + endif() +endif() + +include(FeatureSummary) +set_package_properties( + Luajit PROPERTIES + URL "https://luajit.org/luajit.html" + DESCRIPTION "LuaJIT is a Just-In-Time Compiler (JIT) for the Lua programming language.") diff --git a/cmake/finders/FindMbedTLS.cmake b/cmake/finders/FindMbedTLS.cmake new file mode 100644 index 000000000..26a2a17e0 --- /dev/null +++ b/cmake/finders/FindMbedTLS.cmake @@ -0,0 +1,215 @@ +#[=======================================================================[.rst +FindMbedTLS +----------- + +FindModule for MbedTLS and associated libraries + +.. versionchanged:: 3.0 + Updated FindModule to CMake standards + +Components +^^^^^^^^^^ + +.. versionadded:: 1.0 + +This module contains provides several components: + +``MbedCrypto`` +``MbedTLS`` +``MbedX509`` + +Import targets exist for each component. + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 2.0 + +This module defines the :prop_tgt:`IMPORTED` targets: + +``MbedTLS::MbedCrypto`` + Crypto component + +``MbedTLS::MbedTLS`` + TLS component + +``MbedTLS::MbedX509`` + X509 component + +Result Variables +^^^^^^^^^^^^^^^^ + +This module sets the following variables: + +``MbedTLS_FOUND`` + True, if all required components and the core library were found. +``MbedTLS_VERSION`` + Detected version of found MbedTLS libraries. + +``MbedTLS__VERSION`` + Detected version of found MbedTLS component library. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``MbedTLS__LIBRARY`` + Path to the library component of MbedTLS. +``MbedTLS__INCLUDE_DIR`` + Directory containing ``.h``. + +#]=======================================================================] + +# cmake-format: off +# cmake-lint: disable=C0103 +# cmake-lint: disable=C0301 +# cmake-lint: disable=C0307 +# cmake-format: on + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_MbedTLS QUIET mbedtls mbedcrypto mbedx509) +endif() + +# MbedTLS_set_soname: Set SONAME on imported library targets +macro(MbedTLS_set_soname component) + if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") + execute_process( + COMMAND sh -c "otool -D '${Mbed${component}_LIBRARY}' | grep -v '${Mbed${component}_LIBRARY}'" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0 AND _output MATCHES "^@rpath/") + set_property(TARGET MbedTLS::Mbed${component} PROPERTY IMPORTED_SONAME "${_output}") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + execute_process( + COMMAND sh -c "objdump -p '${Mbed${component}_LIBRARY}' | grep SONAME" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0) + string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}") + set_property(TARGET MbedTLS::Mbed${component} PROPERTY IMPORTED_SONAME "${_soname}") + unset(_soname) + endif() + endif() + unset(_output) + unset(_result) +endmacro() + +find_path( + MbedTLS_INCLUDE_DIR + NAMES mbedtls/ssl.h + HINTS "${PC_MbedTLS_INCLUDE_DIRS}" + PATHS /usr/include /usr/local/include + DOC "MbedTLS include directory") + +if(PC_MbedTLS_VERSION VERSION_GREATER 0) + set(MbedTLS_VERSION ${PC_MbedTLS_VERSION}) +elseif(EXISTS "${MbedTLS_INCLUDE_DIR}/mbedtls/build_info.h") + file(STRINGS "${MbedTLS_INCLUDE_DIR}/mbedtls/build_info.h" _VERSION_STRING + REGEX "#define[ \t]+MBEDTLS_VERSION_STRING[ \t]+.+") + string(REGEX REPLACE ".*#define[ \t]+MBEDTLS_VERSION_STRING[ \t]+\"(.+)\".*" "\\1" MbedTLS_VERSION + "${_VERSION_STRING}") +else() + if(NOT MbedTLS_FIND_QUIETLY) + message(AUTHOR_WARNING "Failed to find MbedTLS version.") + endif() + set(MbedTLS_VERSION 0.0.0) +endif() + +find_library( + MbedTLS_LIBRARY + NAMES libmbedtls mbedtls + HINTS "${PC_MbedTLS_LIBRARY_DIRS}" + PATHS /usr/lib /usr/local/lib + DOC "MbedTLS location") + +find_library( + MbedCrypto_LIBRARY + NAMES libmbedcrypto mbedcrypto + HINTS "${PC_MbedTLS_LIBRARY_DIRS}" + PATHS /usr/lib /usr/local/lib + DOC "MbedCrypto location") + +find_library( + MbedX509_LIBRARY + NAMES libmbedx509 mbedx509 + HINTS "${PC_MbedTLS_LIBRARY_DIRS}" + PATHS /usr/lib /usr/local/lib + DOC "MbedX509 location") + +if(MbedTLS_LIBRARY + AND NOT MbedCrypto_LIBRARY + AND NOT MbedX509_LIBRARY) + set(CMAKE_REQUIRED_LIBRARIES "${MbedTLS_LIBRARY}") + set(CMAKE_REQUIRED_INCLUDES "${MbedTLS_INCLUDE_DIR}") + + check_symbol_exists(mbedtls_x509_crt_init "mbedtls/x590_crt.h" MbedTLS_INCLUDES_X509) + check_symbol_exists(mbedtls_sha256_init "mbedtls/sha256.h" MbedTLS_INCLUDES_CRYPTO) + unset(CMAKE_REQUIRED_LIBRARIES) + unset(CMAKE_REQUIRED_INCLUDES) +endif() + +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows") + set(MbedTLS_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.") +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + set(MbedTLS_ERROR_REASON "Ensure that MbedTLS is installed on the system.") +endif() + +if(MbedTLS_INCLUDES_X509 AND MbedTLS_INCLUDES_CRYPTO) + find_package_handle_standard_args( + MbedTLS + REQUIRED_VARS MbedTLS_LIBRARY MbedTLS_INCLUDE_DIR + VERSION_VAR MbedTLS_VERSION REASON_FAILURE_MESSAGE "${MbedTLS_ERROR_REASON}") + mark_as_advanced(MbedTLS_LIBRARY MbedTLS_INCLUDE_DIR) + list(APPEND _COMPONENTS TLS) +else() + find_package_handle_standard_args( + MbedTLS + REQUIRED_VARS MbedTLS_LIBRARY MbedCrypto_LIBRARY MbedX509_LIBRARY MbedTLS_INCLUDE_DIR + VERSION_VAR MbedTLS_VERSION REASON_FAILURE_MESSAGE "${MbedTLS_ERROR_REASON}") + mark_as_advanced(MbedTLS_LIBRARY MbedCrypto_LIBRARY MbedX509_LIBRARY MbedTLS_INCLUDE_DIR) + list(APPEND _COMPONENTS TLS Crypto X509) +endif() +unset(MbedTLS_ERROR_REASON) + +if(MbedTLS_FOUND) + foreach(component IN LISTS _COMPONENTS) + if(NOT TARGET MbedTLS::Mbed${component}) + if(IS_ABSOLUTE "${Mbed${component}_LIBRARY}") + add_library(MbedTLS::Mbed${component} UNKNOWN IMPORTED) + set_property(TARGET MbedTLS::Mbed${component} PROPERTY IMPORTED_LOCATION "${Mbed${component}_LIBRARY}") + else() + add_library(MbedTLS::Mbed${component} INTERFACE IMPORTED) + set_property(TARGET MbedTLS::Mbed${component} PROPERTY IMPORTED_LIBNAME "${Mbed${component}_LIBRARY}") + endif() + + mbedtls_set_soname(${component}) + set_target_properties( + MbedTLS::MbedTLS + PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_MbedTLS_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${MbedTLS_INCLUDE_DIR}" + VERSION ${MbedTLS_VERSION}) + endif() + endforeach() + + if(MbedTLS_INCLUDES_X509 AND MbedTLS_INCLUDES_CRYPTO) + set(MbedTLS_LIBRARIES ${MbedTLS_LIBRARY}) + else() + set(MbedTLS_LIBRARIES ${MbedTLS_LIBRARY} ${MbedCrypto_LIBRARY} ${MbedX509_LIBRARY}) + set_property(TARGET MbedTLS::MbedTLS PROPERTY INTERFACE_LINK_LIBRARIES MbedTLS::MbedCrypto MbedTLS::MbedX509) + endif() +endif() + +include(FeatureSummary) +set_package_properties( + MbedTLS PROPERTIES + URL "https://www.trustedfirmware.org/projects/mbed-tls" + DESCRIPTION + "A C library implementing cryptographic primitives, X.509 certificate manipulation, and the SSL/TLS and DTLS protocols." +) diff --git a/cmake/finders/Findjansson.cmake b/cmake/finders/Findjansson.cmake new file mode 100644 index 000000000..07d6c8918 --- /dev/null +++ b/cmake/finders/Findjansson.cmake @@ -0,0 +1,140 @@ +#[=======================================================================[.rst +Findjansson +---------- + +FindModule for jansson and associated libraries + +.. versionchanged:: 3.0 + Updated FindModule to CMake standards + +Imported Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 2.0 + +This module defines the :prop_tgt:`IMPORTED` target ``jansson::jansson``. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module sets the following variables: + +``jansson_FOUND`` + True, if all required components and the core library were found. +``jansson_VERSION`` + Detected version of found jansson libraries. + +Cache variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``jansson_LIBRARY`` + Path to the library component of jansson. +``jansson_INCLUDE_DIR`` + Directory containing ``jansson.h``. + +#]=======================================================================] + +# cmake-format: off +# cmake-lint: disable=C0103 +# cmake-format: on + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +if(PKG_CONFIG_FOUND) + pkg_search_module(PC_jansson QUIET jansson) +endif() + +# jansson_set_soname: Set SONAME on imported library targets +macro(jansson_set_soname) + if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") + execute_process( + COMMAND sh -c "otool -D '${jansson_LIBRARY}' | grep -v '${jansson_LIBRARY}'" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0 AND _output MATCHES "^@rpath/") + set_property(TARGET jansson::jansson PROPERTY IMPORTED_SONAME "${_output}") + endif() + elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + execute_process( + COMMAND sh -c "objdump -p '${jansson_LIBRARY}' | grep SONAME" + OUTPUT_VARIABLE _output + RESULT_VARIABLE _result) + + if(_result EQUAL 0) + string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}") + set_property(TARGET jansson::jansson PROPERTY IMPORTED_SONAME "${_soname}") + unset(_soname) + endif() + endif() + unset(_output) + unset(_result) +endmacro() + +find_path( + jansson_INCLUDE_DIR + NAMES jansson.h + HINTS ${PC_jansson_INCLUDE_DIR} + PATHS /usr/include /usr/local/include + PATH_SUFFIXES jansson-2.1 + DOC "jansson include directory") + +if(PC_jansson_VERSION VERSION_GREATER 0) + set(jansson_VERSION ${PC_jansson_VERSION}) +elseif(EXISTS "${jansson_INCLUDE_DIR}/jansson.h") + file(STRINGS "${jansson_INCLUDE_DIR}/jansson.h" _VERSION_STRING REGEX "#define[ \t]+JANSSON_VERSION[ \t]+.+") + string(REGEX REPLACE ".*#define[ \t]+JANSSON_VERSION[ \t]+\"(.+)\".*" "\\1" jansson_VERSION "${_VERSION_STRING}") +else() + if(NOT jansson_FIND_QUIETLY) + message(AUTHOR_WARNING "Failed to find jansson version.") + endif() + set(jansson_VERSION 0.0.0) +endif() + +find_library( + jansson_LIBRARY + NAMES jansson + HINTS ${PC_jansson_LIBRARY_DIRS} + PATHS /usr/lib /usr/local/lib + DOC "jansson location") + +if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows") + set(jansson_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.") +elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD") + set(jansson_ERROR_REASON "Ensure that jansson is installed on the system.") +endif() + +find_package_handle_standard_args( + jansson + REQUIRED_VARS jansson_LIBRARY jansson_INCLUDE_DIR + VERSION_VAR jansson_VERSION REASON_FAILURE_MESSAGE "${jansson_ERROR_REASON}") +mark_as_advanced(jansson_INCLUDE_DIR jansson_LIBRARY) +unset(jansson_ERROR_REASON) + +if(jansson_FOUND) + if(NOT TARGET jansson::jansson) + if(IS_ABSOLUTE "${jansson_LIBRARY}") + add_library(jansson::jansson UNKNOWN IMPORTED) + set_property(TARGET jansson::jansson PROPERTY IMPORTED_LOCATION "${jansson_LIBRARY}") + else() + add_library(jansson::jansson INTERFACE IMPORTED) + set_property(TARGET jansson::jansson PROPERTY IMPORTED_LIBNAME "${jansson_LIBRARY}") + endif() + + jansson_set_soname() + set_target_properties( + jansson::jansson + PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_jansson_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${jansson_INCLUDE_DIR}" + VERSION ${jansson_VERSION}) + endif() +endif() + +include(FeatureSummary) +set_package_properties( + jansson PROPERTIES + URL "https://www.digip.org/jansson/" + DESCRIPTION "A C library for encoding, decoding, and manipulating JSON data.")