Xcode: Add support to embed XPC Services

This commit is contained in:
Jonathan Earnshaw
2023-11-28 14:51:45 +13:00
parent 245e111269
commit 2b4bb43ed3
10 changed files with 72 additions and 0 deletions

View File

@@ -43,6 +43,12 @@ The supported values for ``<type>`` are:
The specified items will be added to the ``Embed Resources`` build phase.
They must be CMake target names or folder paths.
``XPC_SERVICES``
.. versionadded:: 3.29
The specified items will be added to the ``Embed XPC Services`` build phase.
They must be CMake target names.
See also :prop_tgt:`XCODE_EMBED_<type>_PATH`,
:prop_tgt:`XCODE_EMBED_<type>_REMOVE_HEADERS_ON_COPY` and
:prop_tgt:`XCODE_EMBED_<type>_CODE_SIGN_ON_COPY`.

View File

@@ -25,3 +25,6 @@ The supported values for ``<type>`` are:
``RESOURCES``
.. versionadded:: 3.28
``XPC_SERVICES``
.. versionadded:: 3.29

View File

@@ -0,0 +1,6 @@
xcode-embed-xpc-services
------------------------
* The :prop_tgt:`XCODE_EMBED_XPC_SERVICES <XCODE_EMBED_<type>>` target property
was added to tell the :generator:`Xcode` generator what targets to put in
the ``Embed XPC Resources`` build phase.

View File

@@ -4299,6 +4299,15 @@ void cmGlobalXCodeGenerator::AddEmbeddedResources(cmXCodeObject* target)
dstSubfolderSpec, NoActionOnCopyByDefault);
}
void cmGlobalXCodeGenerator::AddEmbeddedXPCServices(cmXCodeObject* target)
{
static const auto dstSubfolderSpec = "16";
this->AddEmbeddedObjects(
target, "Embed XPC Services", "XCODE_EMBED_XPC_SERVICES", dstSubfolderSpec,
NoActionOnCopyByDefault, "$(CONTENTS_FOLDER_PATH)/XPCServices");
}
bool cmGlobalXCodeGenerator::CreateGroups(
std::vector<cmLocalGenerator*>& generators)
{
@@ -4712,6 +4721,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
this->AddEmbeddedAppExtensions(t);
this->AddEmbeddedExtensionKitExtensions(t);
this->AddEmbeddedResources(t);
this->AddEmbeddedXPCServices(t);
// Inherit project-wide values for any target-specific search paths.
this->InheritBuildSettingAttribute(t, "HEADER_SEARCH_PATHS");
this->InheritBuildSettingAttribute(t, "SYSTEM_HEADER_SEARCH_PATHS");

View File

@@ -225,6 +225,7 @@ private:
void AddEmbeddedAppExtensions(cmXCodeObject* target);
void AddEmbeddedExtensionKitExtensions(cmXCodeObject* target);
void AddEmbeddedResources(cmXCodeObject* target);
void AddEmbeddedXPCServices(cmXCodeObject* target);
void AddPositionIndependentLinkAttribute(cmGeneratorTarget* target,
cmXCodeObject* buildSettings,
const std::string& configName);

View File

@@ -0,0 +1,3 @@
include(${CMAKE_CURRENT_LIST_DIR}/findAttribute.cmake)
findAttribute(${test} "Embed XPC Services" TRUE)

View File

@@ -0,0 +1 @@
include(${CMAKE_CURRENT_LIST_DIR}/EmbedXPCServices.cmake)

View File

@@ -0,0 +1,17 @@
add_executable(xpc_service MACOSX_BUNDLE main.m)
set_target_properties(xpc_service PROPERTIES
BUNDLE_EXTENSION "xpc"
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/XPCService.Info.plist.in"
MACOSX_BUNDLE_GUI_IDENTIFIER "com.example.app.xpc_service"
)
add_executable(app MACOSX_BUNDLE main.m)
add_dependencies(app xpc_service)
set_target_properties(app PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
XCODE_EMBED_XPC_SERVICES xpc_service
MACOSX_BUNDLE_GUI_IDENTIFIER "com.example.app"
)

View File

@@ -122,4 +122,5 @@ if(XCODE_VERSION VERSION_GREATER_EQUAL 14.1)
TestEmbedCommon(Resources macOS)
TestEmbedCommon(Resources iOS)
TestEmbedCommon(PlugIns macOS)
TestEmbedCommon(XPCServices macOS)
endif()

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>SomeExtension</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.example.app.xpc_service</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>example_app_xpc_service</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
</dict>
</plist>