diff --git a/CMakeLists.txt b/CMakeLists.txt index 909f35a12..39dc6eaa7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.16...3.25) if(OBS_CMAKE_VERSION VERSION_GREATER_EQUAL 3.0.0) - include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/bootstrap.cmake") + include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/bootstrap.cmake" NO_POLICY_SCOPE) project(obs-studio VERSION ${OBS_VERSION_CANONICAL}) diff --git a/cmake/common/bootstrap.cmake b/cmake/common/bootstrap.cmake index c17ef91c6..38985d28a 100644 --- a/cmake/common/bootstrap.cmake +++ b/cmake/common/bootstrap.cmake @@ -1,21 +1,40 @@ # OBS CMake bootstrap module +include_guard(GLOBAL) + # 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." - ) +# Enable distinction between Clang and AppleClang +if(POLICY CMP0025) + cmake_policy(SET CMP0025 NEW) +endif() + +# Enable strict checking of "break()" usage +if(POLICY CMP0055) + cmake_policy(SET CMP0055 NEW) +endif() + +# Honor visibility presets for all target types (executable, shared, module, static) +if(POLICY CMP0063) + cmake_policy(SET CMP0063 NEW) +endif() + +# Disable export function calls to populate package registry by default +if(POLICY CMP0090) + cmake_policy(SET CMP0090 NEW) +endif() +# Prohibit in-source builds +if("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") + message(FATAL_ERROR "In-source builds of OBS are not supported. " + "Specify a build directory via 'cmake -S -B ' instead.") + file(REMOVE_RECURSE "${CMAKE_CURRENT_SOURCE_DIR}/CMakeCache.txt" "${CMAKE_CURRENT_SOURCE_DIR}/CMakeFiles") 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_property(GLOBAL PROPERTY USE_FOLDERS TRUE) # Set default global project variables set(OBS_COMPANY_NAME "OBS Project") @@ -23,9 +42,9 @@ 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) Lain Bailey") +set(OBS_CMAKE_VERSION 3.0.0) # 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") @@ -38,7 +57,7 @@ include(buildnumber) include(osconfig) # Allow selection of common build types via UI -if(NOT CMAKE_BUILD_TYPE) +if(NOT CMAKE_GENERATOR MATCHES "(Xcode|Visual Studio .+)") set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "OBS build type [Release, RelWithDebInfo, Debug, MinSizeRel]" FORCE) diff --git a/cmake/common/buildnumber.cmake b/cmake/common/buildnumber.cmake index e20ac5b80..5f1bee564 100644 --- a/cmake/common/buildnumber.cmake +++ b/cmake/common/buildnumber.cmake @@ -1,8 +1,10 @@ # OBS CMake build number module +include_guard(GLOBAL) + # Define build number cache file set(_BUILD_NUMBER_CACHE - "${CMAKE_SOURCE_DIR}/cmake/.CMakeBuildNumber" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/.CMakeBuildNumber" CACHE INTERNAL "OBS build number cache file") # Read build number from cache file or manual override diff --git a/cmake/common/ccache.cmake b/cmake/common/ccache.cmake index f63f2ab83..f3d1eb57f 100644 --- a/cmake/common/ccache.cmake +++ b/cmake/common/ccache.cmake @@ -1,5 +1,7 @@ # OBS CMake ccache module +include_guard(GLOBAL) + if(NOT DEFINED CCACHE_PROGRAM) message(DEBUG "Trying to find ccache on build host...") find_program(CCACHE_PROGRAM "ccache") @@ -7,7 +9,7 @@ if(NOT DEFINED CCACHE_PROGRAM) endif() if(CCACHE_PROGRAM) - message(DEBUG "CCache found as ${CCACHE_PROGRAM}...") + message(DEBUG "Ccache found as ${CCACHE_PROGRAM}...") option(ENABLE_CCACHE "Enable compiler acceleration with ccache" ON) if(ENABLE_CCACHE) diff --git a/cmake/common/compiler_common.cmake b/cmake/common/compiler_common.cmake index def41575a..171342a75 100644 --- a/cmake/common/compiler_common.cmake +++ b/cmake/common/compiler_common.cmake @@ -1 +1,3 @@ # OBS CMake common compiler options module + +include_guard(GLOBAL) diff --git a/cmake/common/cpackconfig_common.cmake b/cmake/common/cpackconfig_common.cmake index e68bbedb0..a8bf55ca9 100644 --- a/cmake/common/cpackconfig_common.cmake +++ b/cmake/common/cpackconfig_common.cmake @@ -1,5 +1,7 @@ # OBS CMake common CPack module +include_guard(GLOBAL) + # Set default global CPack variables set(CPACK_PACKAGE_NAME obs-studio) set(CPACK_PACKAGE_VENDOR "${OBS_WEBSITE}") diff --git a/cmake/common/helpers_common.cmake b/cmake/common/helpers_common.cmake index ea2365a5a..db423731b 100644 --- a/cmake/common/helpers_common.cmake +++ b/cmake/common/helpers_common.cmake @@ -8,6 +8,8 @@ # cmake-lint: disable=R0915 # cmake-format: on +include_guard(GLOBAL) + # message_configuration: Function to print configuration outcome function(message_configuration) include(FeatureSummary) @@ -31,6 +33,7 @@ function(message_configuration) COMPARE NATURAL CASE SENSITIVE ORDER ASCENDING) + if(OBS_FEATURES_ENABLED) message(NOTICE "------------------------ Enabled Features ------------------------") foreach(feature IN LISTS OBS_FEATURES_ENABLED) @@ -44,6 +47,7 @@ function(message_configuration) COMPARE NATURAL CASE SENSITIVE ORDER ASCENDING) + if(OBS_FEATURES_DISABLED) message(NOTICE "------------------------ Disabled Features ------------------------") foreach(feature IN LISTS OBS_FEATURES_DISABLED) @@ -58,6 +62,7 @@ function(message_configuration) COMPARE NATURAL CASE SENSITIVE ORDER ASCENDING) + if(OBS_MODULES_ENABLED) message(NOTICE "------------------------ Enabled Modules ------------------------") foreach(feature IN LISTS OBS_MODULES_ENABLED) @@ -71,6 +76,7 @@ function(message_configuration) COMPARE NATURAL CASE SENSITIVE ORDER ASCENDING) + if(OBS_MODULES_DISABLED) message(NOTICE "------------------------ Disabled Modules ------------------------") foreach(feature IN LISTS OBS_MODULES_DISABLED) diff --git a/cmake/common/osconfig.cmake b/cmake/common/osconfig.cmake index 6b692fcfc..7fbb21016 100644 --- a/cmake/common/osconfig.cmake +++ b/cmake/common/osconfig.cmake @@ -1,5 +1,7 @@ # OBS CMake operating system bootstrap module +include_guard(GLOBAL) + # 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") diff --git a/cmake/common/versionconfig.cmake b/cmake/common/versionconfig.cmake index 43a92f9f7..17640fc3c 100644 --- a/cmake/common/versionconfig.cmake +++ b/cmake/common/versionconfig.cmake @@ -4,6 +4,8 @@ # cmake-lint: disable=C0301 # cmake-format: on +include_guard(GLOBAL) + # Attempt to automatically discover expected OBS version if(NOT DEFINED OBS_VERSION_OVERRIDE) if(DEFINED RELEASE_CANDIDATE) @@ -23,7 +25,7 @@ if(NOT DEFINED OBS_VERSION_OVERRIDE) else() message(FATAL_ERROR "Invalid beta version supplied - must be ..-beta.") endif() - elseif(EXISTS "${CMAKE_SOURCE_DIR}/.git") + elseif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") execute_process( COMMAND git describe --always --tags --dirty=-modified OUTPUT_VARIABLE _obs_version diff --git a/cmake/macos/compilerconfig.cmake b/cmake/macos/compilerconfig.cmake index 6ec013621..2e5bfedaa 100644 --- a/cmake/macos/compilerconfig.cmake +++ b/cmake/macos/compilerconfig.cmake @@ -1,14 +1,6 @@ # OBS CMake macOS compiler configuration module -# Enable distinction between Clang and AppleClang -if(POLICY CMP0025) - cmake_policy(SET CMP0025 NEW) -endif() - -# Honor visibility presets for all target types (executable, shared, module, static) -if(POLICY CMP0063) - cmake_policy(SET CMP0063 NEW) -endif() +include_guard(GLOBAL) include(ccache) include(compiler_common) diff --git a/cmake/macos/defaults.cmake b/cmake/macos/defaults.cmake index 581572198..36f9b2a73 100644 --- a/cmake/macos/defaults.cmake +++ b/cmake/macos/defaults.cmake @@ -1,12 +1,6 @@ # OBS CMake macOS defaults module -# Enable selection between arm64 and x86_64 targets -if(NOT CMAKE_OSX_ARCHITECTURES) - set(CMAKE_OSX_ARCHITECTURES - arm64 - CACHE STRING "Build architectures for macOS" FORCE) -endif() -set_property(CACHE CMAKE_OSX_ARCHITECTURES PROPERTY STRINGS arm64 x86_64) +include_guard(GLOBAL) # Set empty codesigning team if not specified as cache variable if(NOT OBS_CODESIGN_TEAM) diff --git a/cmake/macos/helpers.cmake b/cmake/macos/helpers.cmake index 957087049..a04f1167e 100644 --- a/cmake/macos/helpers.cmake +++ b/cmake/macos/helpers.cmake @@ -7,6 +7,8 @@ # cmake-lint: disable=E1126 # cmake-format: on +include_guard(GLOBAL) + include(helpers_common) # set_target_properties_obs: Set target properties for use in obs-studio diff --git a/cmake/macos/xcode.cmake b/cmake/macos/xcode.cmake index dd304a2b4..c397f2702 100644 --- a/cmake/macos/xcode.cmake +++ b/cmake/macos/xcode.cmake @@ -1,5 +1,7 @@ # OBS CMake macOS Xcode module +include_guard(GLOBAL) + # Use a compiler wrapper to enable ccache in Xcode projects if(ENABLE_CCACHE AND CCACHE_PROGRAM) configure_file("${CMAKE_SOURCE_DIR}/cmake/macos/resources/ccache-launcher-c.in" ccache-launcher-c)