Skip to content

Commit

Permalink
cmake: Add Xcode component to CMake build framework 3.0
Browse files Browse the repository at this point in the history
Adds necessary macOS-specific implementation of the framework, focusing
on native Xcode builds.
  • Loading branch information
PatTheMav authored and RytoEX committed Mar 26, 2023
1 parent ae6e9c8 commit bbeea09
Show file tree
Hide file tree
Showing 15 changed files with 1,135 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"lineLength": 120,
"indentation": {
"spaces": 4
},
"tabWidth": 4,
"maximumBlankLines": 1,
"respectsExistingLineBreaks": true,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": false
}
74 changes: 74 additions & 0 deletions buildspec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"dependencies": {
"prebuilt": {
"version": "2023-03-20",
"baseUrl": "https://github.com/obsproject/obs-deps/releases/download",
"label": "Pre-Built obs-deps",
"hashes": {
"macos-x86_64": "bd4d3866c2e4b630410ff29b3f31a2553844af60b30fa0306d35d80a70f903ba",
"macos-arm64": "90078e2141818a37def7ebdceb3dcde71dc4adc1ce81d6e31ba21916f85c77bf",
"macos-universal": "a1c7f38701e0b6c0bd4224d3ab1a7b54d8eaf592dcee3223ce94404dc6787595",
"windows-x64": "79b259f65a0be9726b80b35ab86c07a1d5dc333bd3ef1391f6a0168ea6d28828",
"linux-x86_64": "36af10f49491193185dc1a115a29de31f9f2f4f7c01e4ebfe8a81b8094cd12f4"
}
},
"qt6": {
"version": "2023-03-20",
"baseUrl": "https://github.com/obsproject/obs-deps/releases/download",
"label": "Pre-Built Qt6",
"hashes": {
"macos-x86_64": "8f5e1a865310898635d34b92e6d93c99c62f39289a17d6db140e776ba9b2e455",
"macos-arm64": "0011e2395afbb02aaa5e8641c4486680e30decc60e063ca5a73d6faf3649e723",
"macos-universal": "5bcbb8fee4b70a26912e04a62960c615153828eac66b9f0bcb0b30529193ca6e",
"windows-x64": "e52feb06203c043929e271acc3a8d1b2e959c26d8426c4a1fb6c7337fee4e5c8"
},
"debugSymbols": {
"windows-x64": "ae16477980e1bc602f244923f6e75c214311df286981211ee29a67ac060d4389"
}
},
"cef": {
"version": "5060",
"baseUrl": "https://cdn-fastly.obsproject.com/downloads",
"label": "Chromium Embedded Framework",
"hashes": {
"macos-x86_64": "7ef71717ff2e4ff4212274c33f0993729f47c109c464e499544fd3f63586a069",
"macos-arm64": "a9da8909202aefc8f35509d03eff9a7c837b5d3b2ed3afb39b67121cb16d457b",
"linux-x86_64": "bf4aa9388bab7e94fa945cc3bba16b6da63b6a30f9c0342d42235468b39d84bf",
"linux-aarch64": "68d915c9ba2639cba762a54cd3430fce2527aa6355d831d3cfcb6157664206b0",
"windows-x64": "c1b47beb7ee42e98f1a41b6d694c26842a4a3d452e44bdf6f758c9785696533d"
},
"revision": {
"macos-x86_64": 2,
"macos-arm64": 2
}
},
"vlc": {
"version": "3.0.8",
"baseUrl": "https://downloads.videolan.org/vlc",
"label": "VLC",
"hashes": {
"windows-x64": "91f589ef69fce51645a3ecbb215b405c98db7b891479474ec3b5ed3b63c25e4a"
}
}
},
"platformConfig": {
"macos-x86_64": {
"qtVersion": 6,
"deploymentTarget": "11.0",
"buildTarget": "11.0"
},
"macos-arm64": {
"qtVersion": 6,
"deploymentTarget": "11.0",
"buildTarget": "11.0"
},
"windows-x64": {
"qtVersion": 6
},
"linux-x86_64": {
"qtVersion": 6,
"generator": "Ninja"
}
},
"name": "obs-studio"
}
41 changes: 41 additions & 0 deletions cmake/macos/.cmake-format.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
}
193 changes: 193 additions & 0 deletions cmake/macos/buildspec.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# OBS CMake macOS build dependencies module

# cmake-format: off
# cmake-lint: disable=E1126
# cmake-lint: disable=R0912
# cmake-lint: disable=R0915
# cmake-format: on

# _check_deps_version: Checks for obs-deps VERSION file in prefix paths
macro(_check_deps_version version)
set(found FALSE)

foreach(path IN LISTS CMAKE_PREFIX_PATH)
if(EXISTS "${path}/share/obs-deps/VERSION")
if(dependency STREQUAL qt6 AND NOT EXISTS "${path}/lib/cmake/Qt6/Qt6Config.cmake")
set(found FALSE)
break()
endif()

file(READ "${path}/share/obs-deps/VERSION" _check_version)
string(REPLACE "\n" "" _check_version "${_check_version}")

if(_check_version VERSION_EQUAL version)
set(found TRUE)
break()
elseif(_check_version VERSION_LESS version)
message(AUTHOR_WARNING "Outdated ${label} version detected in ${path}: \n"
"Found ${_check_version}, require ${version}")
list(REMOVE_ITEM CMAKE_PREFIX_PATH "${path}")
list(APPEND CMAKE_PREFIX_PATH "${path}")
continue()
else()
message(AUTHOR_WARNING "Future ${label} version detected in ${path}: \n"
"Found ${_check_version}, require ${version}")
set(found TRUE)
break()
endif()
endif()
endforeach()
endmacro()

# _check_dependencies: Fetch and extract pre-built OBS build dependencies
function(_check_dependencies)
if(CMAKE_OSX_ARCHITECTURES MATCHES ".+;.+")
set(arch universal)
else()
set(arch ${CMAKE_OSX_ARCHITECTURES})
endif()

file(READ "${CMAKE_CURRENT_SOURCE_DIR}/buildspec.json" buildspec)

# cmake-format: off
string(JSON deployment_target GET ${buildspec} platformConfig macos-${arch} deploymentTarget)
string(JSON dependency_data GET ${buildspec} dependencies)
# cmake-format: on

if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET
${_deployment_target}
CACHE STRING "Minimum macOS version to target for deployment (at runtime). Newer APIs will be weak-linked."
FORCE)
endif()

set(dependencies_dir "${CMAKE_CURRENT_SOURCE_DIR}/.deps")
set(prebuilt_filename "macos-deps-VERSION-ARCH-REVISION.tar.xz")
set(prebuilt_destination "obs-deps-VERSION-ARCH")
set(qt6_filename "macos-deps-qt6-VERSION-ARCH-REVISION.tar.xz")
set(qt6_destination "obs-deps-qt6-VERSION-ARCH")
set(cef_filename "cef_binary_VERSION_macos_ARCH_REVISION.tar.xz")
set(cef_destination "cef_binary_VERSION_macos_ARCH")

foreach(dependency IN ITEMS prebuilt qt6 cef)
# cmake-format: off
string(JSON data GET ${dependency_data} ${dependency})
string(JSON version GET ${data} version)
string(JSON hash GET ${data} hashes macos-${arch})
string(JSON url GET ${data} baseUrl)
string(JSON label GET ${data} label)
string(JSON revision ERROR_VARIABLE error GET ${data} revision macos-${arch})
# cmake-format: on

message(STATUS "Setting up ${label}")

set(file "${${dependency}_filename}")
set(destination "${${dependency}_destination}")
string(REPLACE "VERSION" "${version}" file "${file}")
string(REPLACE "VERSION" "${version}" destination "${destination}")
string(REPLACE "ARCH" "${arch}" file "${file}")
string(REPLACE "ARCH" "${arch}" destination "${destination}")
if(revision)
string(REPLACE "_REVISION" "_v${revision}" file "${file}")
string(REPLACE "-REVISION" "-v${revision}" file "${file}")
else()
string(REPLACE "_REVISION" "" file "${file}")
string(REPLACE "-REVISION" "" file "${file}")
endif()

set(skip FALSE)
if(dependency STREQUAL prebuilt OR dependency STREQUAL qt6)
_check_deps_version(${version})

if(found)
set(skip TRUE)
endif()
elseif(_dependency STREQUAL sparkle)
find_library(SPARKLE Sparkle)

if(NOT ENABLE_SPARKLE OR SPARKLE)
set(skip TRUE)
else()
unset(SPARKLE CACHE)
endif()
elseif(dependency STREQUAL vlc)
if(NOT ENABLE_VLC OR (VLC_PATH AND EXISTS "${VLC_PATH}"))
set(skip TRUE)
endif()
elseif(dependency STREQUAL cef)
if(NOT ENABLE_BROWSER OR (CEF_ROOT_DIR AND EXISTS "${CEF_ROOT_DIR}"))
set(skip TRUE)
endif()
endif()

if(skip)
message(STATUS "Setting up ${label} - skipped")
continue()
endif()

if(dependency STREQUAL qt6 AND "$ENV{CI}")
# cmake-format: off
string(JSON hash GET ${buildspec} dependencies qt6 hashes macos-universal)
# cmake-format: on
string(REPLACE "${arch}" "universal" file "${file}")
endif()

if(dependency STREQUAL cef)
set(url ${url}/${file})
else()
set(url ${url}/${version}/${file})
endif()

if(NOT EXISTS "${dependencies_dir}/${file}")
message(STATUS "Downloading ${url}")
file(
DOWNLOAD "${url}" "${dependencies_dir}/${file}"
STATUS download_status
EXPECTED_HASH SHA256=${hash})

list(GET download_status 0 error_code)
list(GET download_status 1 error_message)
if(error_code GREATER 0)
message(STATUS "Downloading ${url} - Failure")
message(FATAL_ERROR "Unable to download ${url}, failed with error: ${error_message}")
file(REMOVE "${dependencies_dir}/${file}")
else()
message(STATUS "Downloading ${url} - done")
endif()
endif()

if(NOT EXISTS "${dependencies_dir}/${destination}")
file(MAKE_DIRECTORY "${dependencies_dir}/${destination}")
if(dependency STREQUAL vlc)
file(ARCHIVE_EXTRACT INPUT "${dependencies_dir}/${file}" DESTINATION "${dependencies_dir}")
else()
file(ARCHIVE_EXTRACT INPUT "${dependencies_dir}/${file}" DESTINATION "${dependencies_dir}/${destination}")
endif()
execute_process(COMMAND "xattr" -r -d com.apple.quarantine "${dependencies_dir}/${destination}"
RESULT_VARIABLE result COMMAND_ERROR_IS_FATAL ANY)
endif()

if(dependency STREQUAL cef)
set(CEF_ROOT_DIR
"${dependencies_dir}/${destination}"
CACHE PATH "CEF Root directory" FORCE)
elseif(dependency STREQUAL prebuilt)
set(VLC_PATH
"${dependencies_dir}/${destination}"
CACHE PATH "VLC source code directory" FORCE)
list(APPEND CMAKE_PREFIX_PATH "${dependencies_dir}/${destination}")
elseif(dependency STREQUAL qt6)
list(APPEND CMAKE_PREFIX_PATH "${dependencies_dir}/${destination}")
endif()

message(STATUS "Setting up ${label} - done")
endforeach()

list(REMOVE_DUPLICATES CMAKE_PREFIX_PATH)

set(CMAKE_PREFIX_PATH
${CMAKE_PREFIX_PATH}
CACHE PATH "CMake prefix search path" FORCE)
endfunction()

_check_dependencies()
66 changes: 66 additions & 0 deletions cmake/macos/compilerconfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 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(ccache)
include(compiler_common)
include(simd)

# Add default C and C++ compiler options if Xcode generator is not used
if(NOT XCODE)
list(
APPEND
_obs_c_options
-Werror
-Wextra
-Wvla
-Wswitch
-Wformat-security
-Wunused-parameter
-Wno-unused-function
-Wno-missing-field-initializers
-Wformat
-fno-strict-aliasing
-Wno-error=shorten-64-to-32)

# Set symbols to be hidden by default for C and C++
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE)

# Enable stripping of dead symbols when not building for Debug configuration
set(_release_configs RelWithDebInfo Release MinSizeRel)
if(CMAKE_BUILD_TYPE IN_LIST _release_configs)
add_link_options(LINKER:-dead_strip)
endif()

add_compile_options("$<$<COMPILE_LANGUAGE:C>:${_obs_c_options}>" "$<$<COMPILE_LANGUAGE:CXX>:${_obs_c_options}>")

option(ENABLE_COMPILER_TRACE "Enable clang time-trace (requires Ninja)" OFF)
mark_as_advanced(ENABLE_COMPILER_TRACE)

# Add time trace option to compiler, if enabled.
if(ENABLE_COMPILER_TRACE AND CMAKE_GENERATOR STREQUAL "Ninja")
add_compile_options($<$<COMPILE_LANGUAGE:C>:-ftime-trace> $<$<COMPILE_LANGUAGE:CXX>:-ftime-trace>)
else()
set(ENABLE_COMPILER_TRACE
OFF
CACHE STRING "Enable clang time-trace (requires Ninja)" FORCE)
endif()

# Enable color diagnostics for AppleClang
set(CMAKE_COLOR_DIAGNOSTICS ON)
endif()

add_compile_definitions($<$<CONFIG:DEBUG>:DEBUG> $<$<CONFIG:DEBUG>:_DEBUG>)
Loading

0 comments on commit bbeea09

Please sign in to comment.