From b99c386122b3e27b3c931c49f26d4afd93580755 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Thu, 10 Nov 2022 14:50:03 -0600 Subject: Xcode: Allow bundling extensionkit extensions Fixes: #24150 --- Help/prop_tgt/XCODE_EMBED_type.rst | 14 ++++++++++- .../XCODE_EMBED_type_CODE_SIGN_ON_COPY.rst | 3 +++ Help/prop_tgt/XCODE_EMBED_type_PATH.rst | 3 +++ .../XCODE_EMBED_type_REMOVE_HEADERS_ON_COPY.rst | 6 +++++ Help/release/dev/xcode-ios-extensionkit.rst | 11 +++++++++ Source/cmGlobalXCodeGenerator.cxx | 17 ++++++++++++-- Source/cmGlobalXCodeGenerator.h | 4 +++- .../EmbedExtensionKitExtensions-iOS-check.cmake | 4 ++++ .../EmbedExtensionKitExtensions-iOS.cmake | 1 + .../EmbedExtensionKitExtensions-macOS-check.cmake | 4 ++++ .../EmbedExtensionKitExtensions-macOS.cmake | 1 + .../EmbedExtensionKitExtensions.cmake | 22 ++++++++++++++++++ .../XcodeProject-Embed/ExtensionKit.Info.plist.in | 13 +++++++++++ .../RunCMake/XcodeProject-Embed/RunCMakeTest.cmake | 27 ++++++++++++++++++++++ 14 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 Help/release/dev/xcode-ios-extensionkit.rst create mode 100644 Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-iOS-check.cmake create mode 100644 Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-iOS.cmake create mode 100644 Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-macOS-check.cmake create mode 100644 Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-macOS.cmake create mode 100644 Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions.cmake create mode 100644 Tests/RunCMake/XcodeProject-Embed/ExtensionKit.Info.plist.in diff --git a/Help/prop_tgt/XCODE_EMBED_type.rst b/Help/prop_tgt/XCODE_EMBED_type.rst index e8383c2..da744c2 100644 --- a/Help/prop_tgt/XCODE_EMBED_type.rst +++ b/Help/prop_tgt/XCODE_EMBED_type.rst @@ -16,9 +16,21 @@ The supported values for ```` are: ``APP_EXTENSIONS`` .. versionadded:: 3.21 - The specified items will be added to the ``Embed App Extensions`` build phase. + The specified items will be added to the ``Embed App Extensions`` build + phase, with ``Destination`` set to ``PlugIns and Foundation Extensions`` They must be CMake target names. +``EXTENSIONKIT_EXTENSIONS`` + .. versionadded:: 3.26 + + The specified items will be added to the ``Embed App Extensions`` build + phase, with ``Destination`` set to ``ExtensionKit Extensions`` + They must be CMake target names, and should likely have the + ``XCODE_PRODUCT_TYPE`` target property set to + ``com.apple.product-type.extensionkit-extension`` + as well as the ``XCODE_EXPLICIT_FILE_TYPE`` to + ``wrapper.extensionkit-extension`` + ``PLUGINS`` .. versionadded:: 3.23 diff --git a/Help/prop_tgt/XCODE_EMBED_type_CODE_SIGN_ON_COPY.rst b/Help/prop_tgt/XCODE_EMBED_type_CODE_SIGN_ON_COPY.rst index cb449ac..ca35c25 100644 --- a/Help/prop_tgt/XCODE_EMBED_type_CODE_SIGN_ON_COPY.rst +++ b/Help/prop_tgt/XCODE_EMBED_type_CODE_SIGN_ON_COPY.rst @@ -14,6 +14,9 @@ The supported values for ```` are: ``APP_EXTENSIONS`` .. versionadded:: 3.21 +``EXTENSIONKIT_EXTENSIONS`` + .. versionadded:: 3.26 + ``PLUGINS`` .. versionadded:: 3.23 diff --git a/Help/prop_tgt/XCODE_EMBED_type_PATH.rst b/Help/prop_tgt/XCODE_EMBED_type_PATH.rst index 160f765..5a5c65f 100644 --- a/Help/prop_tgt/XCODE_EMBED_type_PATH.rst +++ b/Help/prop_tgt/XCODE_EMBED_type_PATH.rst @@ -17,5 +17,8 @@ The supported values for ```` are: ``APP_EXTENSIONS`` .. versionadded:: 3.21 +``EXTENSIONKIT_EXTENSIONS`` + .. versionadded:: 3.26 + ``PLUGINS`` .. versionadded:: 3.23 diff --git a/Help/prop_tgt/XCODE_EMBED_type_REMOVE_HEADERS_ON_COPY.rst b/Help/prop_tgt/XCODE_EMBED_type_REMOVE_HEADERS_ON_COPY.rst index e3a7ced..da8f61b 100644 --- a/Help/prop_tgt/XCODE_EMBED_type_REMOVE_HEADERS_ON_COPY.rst +++ b/Help/prop_tgt/XCODE_EMBED_type_REMOVE_HEADERS_ON_COPY.rst @@ -19,5 +19,11 @@ The supported values for ```` are: If the ``XCODE_EMBED_APP_EXTENSIONS_REMOVE_HEADERS_ON_COPY`` property is not defined, headers WILL be removed on copy by default. +``EXTENSIONKIT_EXTENSIONS`` + .. versionadded:: 3.26 + + If the ``XCODE_EMBED_APP_EXTENSIONS_REMOVE_HEADERS_ON_COPY`` property is not + defined, headers WILL be removed on copy by default. + ``PLUGINS`` .. versionadded:: 3.23 diff --git a/Help/release/dev/xcode-ios-extensionkit.rst b/Help/release/dev/xcode-ios-extensionkit.rst new file mode 100644 index 0000000..b77b4ec --- /dev/null +++ b/Help/release/dev/xcode-ios-extensionkit.rst @@ -0,0 +1,11 @@ +xcode-ios-extensionkit +---------------------- + +* The :prop_tgt:`XCODE_EMBED_EXTENSIONKIT_EXTENSIONS >` target property + was added to tell the :generator:`Xcode` generator to ExtensionKit-based extensions + such as extensions using the Background Assets framework. + Aspects of the embedding can be customized with the + :prop_tgt:`XCODE_EMBED_EXTENSIONKIT_EXTENSIONS_PATH >`, + :prop_tgt:`XCODE_EMBED_EXTENSIONKIT_EXTENSIONS_CODE_SIGN_ON_COPY _CODE_SIGN_ON_COPY>` and + :prop_tgt:`XCODE_EMBED_EXTENSIONKIT_EXTENSIONS_REMOVE_HEADERS_ON_COPY _REMOVE_HEADERS_ON_COPY>` + properties. diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 0e94de5..aeb5074 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3929,7 +3929,7 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target) void cmGlobalXCodeGenerator::AddEmbeddedObjects( cmXCodeObject* target, const std::string& copyFilesBuildPhaseName, const std::string& embedPropertyName, const std::string& dstSubfolderSpec, - int actionsOnByDefault) + int actionsOnByDefault, const std::string& defaultDstPath) { cmGeneratorTarget* gt = target->GetTarget(); if (!gt) { @@ -3965,7 +3965,8 @@ void cmGlobalXCodeGenerator::AddEmbeddedObjects( copyFilesBuildPhase->AddAttribute("dstPath", this->CreateString(*fwEmbedPath)); } else { - copyFilesBuildPhase->AddAttribute("dstPath", this->CreateString("")); + copyFilesBuildPhase->AddAttribute("dstPath", + this->CreateString(defaultDstPath)); } copyFilesBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", this->CreateString("0")); @@ -4091,6 +4092,17 @@ void cmGlobalXCodeGenerator::AddEmbeddedAppExtensions(cmXCodeObject* target) RemoveHeadersOnCopyByDefault); } +void cmGlobalXCodeGenerator::AddEmbeddedExtensionKitExtensions( + cmXCodeObject* target) +{ + static const auto dstSubfolderSpec = "16"; + + this->AddEmbeddedObjects(target, "Embed App Extensions", + "XCODE_EMBED_EXTENSIONKIT_EXTENSIONS", + dstSubfolderSpec, RemoveHeadersOnCopyByDefault, + "$(EXTENSIONS_FOLDER_PATH)"); +} + bool cmGlobalXCodeGenerator::CreateGroups( std::vector& generators) { @@ -4482,6 +4494,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( this->AddEmbeddedFrameworks(t); this->AddEmbeddedPlugIns(t); this->AddEmbeddedAppExtensions(t); + this->AddEmbeddedExtensionKitExtensions(t); // Inherit project-wide values for any target-specific search paths. this->InheritBuildSettingAttribute(t, "HEADER_SEARCH_PATHS"); this->InheritBuildSettingAttribute(t, "SYSTEM_HEADER_SEARCH_PATHS"); diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index 856852b..1fdd189 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -218,10 +218,12 @@ private: const std::string& copyFilesBuildPhaseName, const std::string& embedPropertyName, const std::string& dstSubfolderSpec, - int actionsOnByDefault); + int actionsOnByDefault, + const std::string& defaultDstPath = ""); void AddEmbeddedFrameworks(cmXCodeObject* target); void AddEmbeddedPlugIns(cmXCodeObject* target); void AddEmbeddedAppExtensions(cmXCodeObject* target); + void AddEmbeddedExtensionKitExtensions(cmXCodeObject* target); void AddPositionIndependentLinkAttribute(cmGeneratorTarget* target, cmXCodeObject* buildSettings, const std::string& configName); diff --git a/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-iOS-check.cmake b/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-iOS-check.cmake new file mode 100644 index 0000000..576be11 --- /dev/null +++ b/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-iOS-check.cmake @@ -0,0 +1,4 @@ +include(${CMAKE_CURRENT_LIST_DIR}/findAttribute.cmake) + +findAttribute(${test} "RemoveHeadersOnCopy" TRUE) +findAttribute(${test} "CodeSignOnCopy" FALSE) diff --git a/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-iOS.cmake b/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-iOS.cmake new file mode 100644 index 0000000..839f842 --- /dev/null +++ b/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-iOS.cmake @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/EmbedAppExtensions.cmake) diff --git a/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-macOS-check.cmake b/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-macOS-check.cmake new file mode 100644 index 0000000..576be11 --- /dev/null +++ b/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-macOS-check.cmake @@ -0,0 +1,4 @@ +include(${CMAKE_CURRENT_LIST_DIR}/findAttribute.cmake) + +findAttribute(${test} "RemoveHeadersOnCopy" TRUE) +findAttribute(${test} "CodeSignOnCopy" FALSE) diff --git a/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-macOS.cmake b/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-macOS.cmake new file mode 100644 index 0000000..839f842 --- /dev/null +++ b/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions-macOS.cmake @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/EmbedAppExtensions.cmake) diff --git a/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions.cmake b/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions.cmake new file mode 100644 index 0000000..91d207b --- /dev/null +++ b/Tests/RunCMake/XcodeProject-Embed/EmbedExtensionKitExtensions.cmake @@ -0,0 +1,22 @@ +add_executable(app_extensionkit_extension main.m) +set_target_properties(app_extensionkit_extension PROPERTIES + LINKER_LANGUAGE CXX + BUNDLE YES + XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO" + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" + XCODE_ATTRIBUTE_ENABLE_BITCODE "NO" + XCODE_ATTRIBUTE_GENERATE_INFOPLIST_FILE "YES" + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/ExtensionKit.Info.plist.in" + MACOSX_BUNDLE_GUI_IDENTIFIER "com.example.app.app_extensionkit_extension" + XCODE_PRODUCT_TYPE "com.apple.product-type.extensionkit-extension" + XCODE_EXPLICIT_FILE_TYPE "wrapper.extensionkit-extension" +) + +add_executable(app MACOSX_BUNDLE main.m) +add_dependencies(app app_extension) +set_target_properties(app PROPERTIES + XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO" + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" + XCODE_EMBED_EXTENSIONKIT_EXTENSIONS app_extension + MACOSX_BUNDLE_GUI_IDENTIFIER "com.example.app" +) diff --git a/Tests/RunCMake/XcodeProject-Embed/ExtensionKit.Info.plist.in b/Tests/RunCMake/XcodeProject-Embed/ExtensionKit.Info.plist.in new file mode 100644 index 0000000..573aa22 --- /dev/null +++ b/Tests/RunCMake/XcodeProject-Embed/ExtensionKit.Info.plist.in @@ -0,0 +1,13 @@ + + + + + EXAppExtensionAttributes + + EXExtensionPointIdentifier + com.apple.background-asset-downloader-extension + EXPrincipalClass + BackgroundDownloadHandler + + + diff --git a/Tests/RunCMake/XcodeProject-Embed/RunCMakeTest.cmake b/Tests/RunCMake/XcodeProject-Embed/RunCMakeTest.cmake index f3a6918..a7bccee 100644 --- a/Tests/RunCMake/XcodeProject-Embed/RunCMakeTest.cmake +++ b/Tests/RunCMake/XcodeProject-Embed/RunCMakeTest.cmake @@ -64,6 +64,25 @@ function(TestAppExtension platform) ) endfunction() +function(TestExtensionKitExtension platform) + set(testName EmbedExtensionKitExtensions-${platform}) + if(NOT platform STREQUAL "macOS") + set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=${platform}) + endif() + set(RunCMake_TEST_NO_CLEAN 1) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build) + + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + + run_cmake(${testName}) + run_cmake_command(${testName}-build + ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR} + --config Debug + --target app + ) +endfunction() + # Isolate device tests from host architecture selection. unset(ENV{CMAKE_OSX_ARCHITECTURES}) @@ -74,3 +93,11 @@ if(XCODE_VERSION VERSION_GREATER_EQUAL 8) TestAppExtension(macOS) TestAppExtension(iOS) endif() + +if(XCODE_VERSION VERSION_GREATER_EQUAL 14.1) + # The various flag on/off combinations are tested by the EmbedFrameworks... + # tests, so we don't duplicate all the combinations here. We only verify the + # defaults, which is to remove headers on copy, but not code sign. + TestAppExtension(macOS) + TestAppExtension(iOS) +endif() -- cgit v0.12