From 3f85e447a84e68f97454171c6a8b70c83edc035f Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Sun, 26 Feb 2023 23:26:01 +0100 Subject: [PATCH] mac-virtualcam: Add Camera Extension to main CMake plugin project Camera Extensions require specific entitlements for the hosting app, which also require a provisioning profile. To avoid breaking local builds that do not require the camera extension, an additional entitlements file that will not trigger the provisioning profile requirement will be used if the virtualcam (but not the Camera Extension) is configured. --- CI/macos/02_build_obs.sh | 2 ++ CMakePresets.json | 2 ++ UI/cmake/macos/entitlements-extension.plist | 20 +++++++++++ cmake/macos/compilerconfig.cmake | 5 +-- cmake/macos/helpers.cmake | 39 ++++++++++++++++++--- cmake/macos/xcode.cmake | 11 +++++- plugins/mac-virtualcam/CMakeLists.txt | 1 + 7 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 UI/cmake/macos/entitlements-extension.plist diff --git a/CI/macos/02_build_obs.sh b/CI/macos/02_build_obs.sh index 81f6f38b9..23587da9d 100755 --- a/CI/macos/02_build_obs.sh +++ b/CI/macos/02_build_obs.sh @@ -118,6 +118,8 @@ _configure_obs() { -DCMAKE_INSTALL_PREFIX=${BUILD_DIR}/install \ -DCMAKE_BUILD_TYPE=${BUILD_CONFIG} \ -DOBS_CODESIGN_IDENTITY="${CODESIGN_IDENT:--}" \ + -DOBS_CODESIGN_TEAM="${CODESIGN_TEAM:-}" \ + -DOBS_PROVISIONING_PROFILE="${PROVISIONING_PROFILE:-}" \ ${YOUTUBE_OPTIONS} \ ${TWITCH_OPTIONS} \ ${RESTREAM_OPTIONS} \ diff --git a/CMakePresets.json b/CMakePresets.json index da0120b3c..af75200c0 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -71,6 +71,7 @@ "ENABLE_SPARKLE": true, "OBS_SPARKLE_KEY": {"type": "STRING", "value": ""}, "OBS_CODESIGN_IDENTITY": "$penv{CODESIGN_IDENT}", + "OBS_CODESIGN_TEAM": "$penv{CODESIGN_TEAM}", "SPARKLE_APPCAST_URL": {"type": "STRING", "value": "https://obsproject.com/osx_update/updates_arm64_v2.xml"}, "SPARKLE_PUBLIC_KEY": {"type": "STRING", "value": "HQ5/Ba9VHOuEWaM0jtVjZzgHKFJX9YTl+HNVpgNF0iM="}, "VIRTUALCAM_DEVICE_UUID": {"type": "STRING", "value": "7626645E-4425-469E-9D8B-97E0FA59AC75"}, @@ -88,6 +89,7 @@ "ENABLE_SPARKLE": true, "OBS_SPARKLE_KEY": {"type": "STRING", "value": ""}, "OBS_CODESIGN_IDENTITY": "$penv{CODESIGN_IDENT}", + "OBS_CODESIGN_TEAM": "$penv{CODESIGN_TEAM}", "SPARKLE_APPCAST_URL": {"type": "STRING", "value": "https://obsproject.com/osx_update/updates_x86_64_v2.xml"}, "SPARKLE_PUBLIC_KEY": {"type": "STRING", "value": "HQ5/Ba9VHOuEWaM0jtVjZzgHKFJX9YTl+HNVpgNF0iM="}, "VIRTUALCAM_DEVICE_UUID": {"type": "STRING", "value": "7626645E-4425-469E-9D8B-97E0FA59AC75"}, diff --git a/UI/cmake/macos/entitlements-extension.plist b/UI/cmake/macos/entitlements-extension.plist new file mode 100644 index 000000000..aad0d6974 --- /dev/null +++ b/UI/cmake/macos/entitlements-extension.plist @@ -0,0 +1,20 @@ + + + + + com.apple.security.cs.allow-unsigned-executable-memory + + com.apple.security.device.camera + + com.apple.security.device.audio-input + + com.apple.security.cs.disable-library-validation + + com.apple.developer.system-extension.install + + com.apple.security.application-groups + + $(TeamIdentifierPrefix)com.obsproject.obs-studio + + + diff --git a/cmake/macos/compilerconfig.cmake b/cmake/macos/compilerconfig.cmake index 29b035baf..987ea0923 100644 --- a/cmake/macos/compilerconfig.cmake +++ b/cmake/macos/compilerconfig.cmake @@ -51,7 +51,8 @@ if(NOT XCODE) add_link_options(LINKER:-dead_strip) endif() - add_compile_options("$<$:${_obs_c_options}>" "$<$:${_obs_c_options}>") + add_compile_options("$<$:${_obs_c_options}>" "$<$:${_obs_c_options}>" + "$<$,$>:-Onone>") option(ENABLE_COMPILER_TRACE "Enable clang time-trace (requires Ninja)" OFF) mark_as_advanced(ENABLE_COMPILER_TRACE) @@ -69,4 +70,4 @@ if(NOT XCODE) set(CMAKE_COLOR_DIAGNOSTICS ON) endif() -add_compile_definitions($<$:DEBUG> $<$:_DEBUG>) +add_compile_definitions("$<$,$>:DEBUG;_DEBUG>") diff --git a/cmake/macos/helpers.cmake b/cmake/macos/helpers.cmake index 53811a61e..0136630d2 100644 --- a/cmake/macos/helpers.cmake +++ b/cmake/macos/helpers.cmake @@ -79,8 +79,27 @@ function(set_target_properties_obs target) COMMENT "Copy ${executable} to application bundle") endforeach() - _check_entitlements() - configure_file(cmake/macos/exportOptions.plist.in ${CMAKE_BINARY_DIR}/exportOptions.plist) + if(VIRTUALCAM_DEVICE_UUID + AND VIRTUALCAM_SOURCE_UUID + AND VIRTUALCAM_SINK_UUID) + set(entitlements_file "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos/entitlements-extension.plist") + else() + set(entitlements_file "${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos/entitlements.plist") + endif() + + if(NOT EXISTS "${entitlements_file}") + message(FATAL_ERROR "Target ${target} is missing an entitlements file in its cmake directory.") + endif() + + set_target_properties(${target} PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${entitlements_file}") + + if(NOT CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE STREQUAL "Automatic") + set_target_properties(${target} PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER + "${OBS_PROVISIONING_PROFILE}") + configure_file(cmake/macos/exportOptions-extension.plist.in ${CMAKE_BINARY_DIR}/exportOptions.plist) + else() + configure_file(cmake/macos/exportOptions.plist.in ${CMAKE_BINARY_DIR}/exportOptions.plist) + endif() add_custom_command( TARGET ${target} @@ -126,16 +145,28 @@ function(set_target_properties_obs target) COMMENT "Add OBS::python import module") endif() + if(TARGET mac-camera-extension) + add_custom_command( + TARGET ${target} + POST_BUILD + COMMAND + "${CMAKE_COMMAND}" -E copy_directory "$" + "$/Library/SystemExtensions/$" + COMMENT "Add Camera Extension to application bundle") + endif() + _bundle_dependencies(${target}) install(TARGETS ${target} BUNDLE DESTINATION "." COMPONENT Application) + elseif(${target} STREQUAL mac-camera-extension) + set_target_properties(${target} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE) + set_property(GLOBAL APPEND PROPERTY _OBS_DEPENDENCIES ${target}) else() set_property(TARGET ${target} PROPERTY XCODE_ATTRIBUTE_SKIP_INSTALL NO) set_property(GLOBAL APPEND PROPERTY _OBS_EXECUTABLES ${target}) set_property(GLOBAL APPEND PROPERTY _OBS_DEPENDENCIES ${target}) + _add_entitlements() endif() - - _add_entitlements() elseif(target_type STREQUAL SHARED_LIBRARY) set_target_properties( ${target} diff --git a/cmake/macos/xcode.cmake b/cmake/macos/xcode.cmake index cb02bc378..651fab452 100644 --- a/cmake/macos/xcode.cmake +++ b/cmake/macos/xcode.cmake @@ -20,18 +20,27 @@ set(CMAKE_XCODE_ATTRIBUTE_MARKETING_VERSION ${OBS_VERSION_CANONICAL}) # Set deployment target set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET}) +if(NOT OBS_PROVISIONING_PROFILE) + set(OBS_PROVISIONING_PROFILE + "" + CACHE STRING "OBS provisioning profile name for macOS" FORCE) +else() + set(CMAKE_XCODE_ATTRIBUTE_PROVISIONING_PROFILE_NAME "${OBS_PROVISIONING_PROFILE}") +endif() + if(NOT OBS_CODESIGN_TEAM) # Switch to manual codesigning if no codesigning team is provided set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE Manual) set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${OBS_CODESIGN_IDENTITY}") else() - if(DEFINED OBS_CODESIGN_IDENTITY AND NOT OBS_CODESIGN_IDENTITY STREQUAL "-") + if(OBS_CODESIGN_IDENTITY AND NOT OBS_CODESIGN_IDENTITY STREQUAL "-") # Switch to manual codesigning if a non-adhoc codesigning identity is provided set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE Manual) set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "${OBS_CODESIGN_IDENTITY}") else() # Switch to automatic codesigning via valid team ID set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_STYLE Automatic) + set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development") endif() set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "${OBS_CODESIGN_TEAM}") endif() diff --git a/plugins/mac-virtualcam/CMakeLists.txt b/plugins/mac-virtualcam/CMakeLists.txt index 1fdca9e4d..05f51700c 100644 --- a/plugins/mac-virtualcam/CMakeLists.txt +++ b/plugins/mac-virtualcam/CMakeLists.txt @@ -19,3 +19,4 @@ target_include_directories(obs-mach-protocol INTERFACE "${CMAKE_CURRENT_SOURCE_D add_subdirectory(src/obs-plugin) add_subdirectory(src/dal-plugin) +add_subdirectory(src/camera-extension)