mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 14:08:35 +08:00
Xcode: Add embed resources support
This commit is contained in:
@@ -37,6 +37,12 @@ The supported values for ``<type>`` are:
|
|||||||
The specified items will be added to the ``Embed PlugIns`` build phase.
|
The specified items will be added to the ``Embed PlugIns`` build phase.
|
||||||
They must be CMake target names.
|
They must be CMake target names.
|
||||||
|
|
||||||
|
``RESOURCES``
|
||||||
|
.. versionadded:: 3.28
|
||||||
|
|
||||||
|
The specified items will be added to the ``Embed Resources`` build phase.
|
||||||
|
They must be CMake target names.
|
||||||
|
|
||||||
See also :prop_tgt:`XCODE_EMBED_<type>_PATH`,
|
See also :prop_tgt:`XCODE_EMBED_<type>_PATH`,
|
||||||
:prop_tgt:`XCODE_EMBED_<type>_REMOVE_HEADERS_ON_COPY` and
|
:prop_tgt:`XCODE_EMBED_<type>_REMOVE_HEADERS_ON_COPY` and
|
||||||
:prop_tgt:`XCODE_EMBED_<type>_CODE_SIGN_ON_COPY`.
|
:prop_tgt:`XCODE_EMBED_<type>_CODE_SIGN_ON_COPY`.
|
||||||
|
@@ -22,3 +22,6 @@ The supported values for ``<type>`` are:
|
|||||||
|
|
||||||
``PLUGINS``
|
``PLUGINS``
|
||||||
.. versionadded:: 3.23
|
.. versionadded:: 3.23
|
||||||
|
|
||||||
|
``RESOURCES``
|
||||||
|
.. versionadded:: 3.28
|
||||||
|
6
Help/release/dev/xcode-embed-resources.rst
Normal file
6
Help/release/dev/xcode-embed-resources.rst
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
xcode-embed-resources
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
* The :prop_tgt:`XCODE_EMBED_RESOURCES <XCODE_EMBED_<type>>` target property
|
||||||
|
was added to tell the :generator:`Xcode` generator what targets to put in
|
||||||
|
the ``Embed Resources`` build phase.
|
@@ -1267,10 +1267,16 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath(
|
|||||||
fileRef->AddAttribute("sourceTree", this->CreateString(sourceTree));
|
fileRef->AddAttribute("sourceTree", this->CreateString(sourceTree));
|
||||||
|
|
||||||
cmXCodeObject* group = this->GroupMap[key];
|
cmXCodeObject* group = this->GroupMap[key];
|
||||||
if (!group && IsLibraryType(fileType)) {
|
if (!group) {
|
||||||
group = this->FrameworkGroup;
|
if (IsLibraryType(fileType)) {
|
||||||
this->GroupMap[key] = group;
|
group = this->FrameworkGroup;
|
||||||
|
} else if (fileType == "folder") {
|
||||||
|
group = this->ResourcesGroup;
|
||||||
|
}
|
||||||
|
if (group)
|
||||||
|
this->GroupMap[key] = group;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!group) {
|
if (!group) {
|
||||||
cmSystemTools::Error("Could not find a PBX group for " + key);
|
cmSystemTools::Error("Could not find a PBX group for " + key);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -4056,7 +4062,8 @@ void cmGlobalXCodeGenerator::AddEmbeddedObjects(
|
|||||||
buildFile = it->second;
|
buildFile = it->second;
|
||||||
}
|
}
|
||||||
} else if (cmSystemTools::IsPathToFramework(relFile) ||
|
} else if (cmSystemTools::IsPathToFramework(relFile) ||
|
||||||
cmSystemTools::IsPathToMacOSSharedLibrary(relFile)) {
|
cmSystemTools::IsPathToMacOSSharedLibrary(relFile) ||
|
||||||
|
cmSystemTools::FileIsDirectory(filePath)) {
|
||||||
// This is a regular string path - create file reference
|
// This is a regular string path - create file reference
|
||||||
auto it = this->EmbeddedLibRefs.find(relFile);
|
auto it = this->EmbeddedLibRefs.find(relFile);
|
||||||
if (it == this->EmbeddedLibRefs.end()) {
|
if (it == this->EmbeddedLibRefs.end()) {
|
||||||
@@ -4157,6 +4164,15 @@ void cmGlobalXCodeGenerator::AddEmbeddedExtensionKitExtensions(
|
|||||||
"$(EXTENSIONS_FOLDER_PATH)");
|
"$(EXTENSIONS_FOLDER_PATH)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmGlobalXCodeGenerator::AddEmbeddedResources(cmXCodeObject* target)
|
||||||
|
{
|
||||||
|
static const auto dstSubfolderSpec = "7";
|
||||||
|
|
||||||
|
this->AddEmbeddedObjects(target, "Embed Resources",
|
||||||
|
"XCODE_EMBED_RESOURCES_PATH", dstSubfolderSpec,
|
||||||
|
NoActionOnCopyByDefault);
|
||||||
|
}
|
||||||
|
|
||||||
bool cmGlobalXCodeGenerator::CreateGroups(
|
bool cmGlobalXCodeGenerator::CreateGroups(
|
||||||
std::vector<cmLocalGenerator*>& generators)
|
std::vector<cmLocalGenerator*>& generators)
|
||||||
{
|
{
|
||||||
@@ -4358,6 +4374,15 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
|
|||||||
this->FrameworkGroup->AddAttribute("children", frameworkGroupChildren);
|
this->FrameworkGroup->AddAttribute("children", frameworkGroupChildren);
|
||||||
this->MainGroupChildren->AddObject(this->FrameworkGroup);
|
this->MainGroupChildren->AddObject(this->FrameworkGroup);
|
||||||
|
|
||||||
|
this->ResourcesGroup = this->CreateObject(cmXCodeObject::PBXGroup);
|
||||||
|
this->ResourcesGroup->AddAttribute("name", this->CreateString("Resources"));
|
||||||
|
this->ResourcesGroup->AddAttribute("sourceTree",
|
||||||
|
this->CreateString("<group>"));
|
||||||
|
cmXCodeObject* ResourcesGroupChildren =
|
||||||
|
this->CreateObject(cmXCodeObject::OBJECT_LIST);
|
||||||
|
this->ResourcesGroup->AddAttribute("children", ResourcesGroupChildren);
|
||||||
|
this->MainGroupChildren->AddObject(this->ResourcesGroup);
|
||||||
|
|
||||||
this->RootObject = this->CreateObject(cmXCodeObject::PBXProject);
|
this->RootObject = this->CreateObject(cmXCodeObject::PBXProject);
|
||||||
this->RootObject->SetComment("Project object");
|
this->RootObject->SetComment("Project object");
|
||||||
|
|
||||||
@@ -4549,6 +4574,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
|
|||||||
this->AddEmbeddedPlugIns(t);
|
this->AddEmbeddedPlugIns(t);
|
||||||
this->AddEmbeddedAppExtensions(t);
|
this->AddEmbeddedAppExtensions(t);
|
||||||
this->AddEmbeddedExtensionKitExtensions(t);
|
this->AddEmbeddedExtensionKitExtensions(t);
|
||||||
|
this->AddEmbeddedResources(t);
|
||||||
// Inherit project-wide values for any target-specific search paths.
|
// Inherit project-wide values for any target-specific search paths.
|
||||||
this->InheritBuildSettingAttribute(t, "HEADER_SEARCH_PATHS");
|
this->InheritBuildSettingAttribute(t, "HEADER_SEARCH_PATHS");
|
||||||
this->InheritBuildSettingAttribute(t, "SYSTEM_HEADER_SEARCH_PATHS");
|
this->InheritBuildSettingAttribute(t, "SYSTEM_HEADER_SEARCH_PATHS");
|
||||||
|
@@ -224,6 +224,7 @@ private:
|
|||||||
void AddEmbeddedPlugIns(cmXCodeObject* target);
|
void AddEmbeddedPlugIns(cmXCodeObject* target);
|
||||||
void AddEmbeddedAppExtensions(cmXCodeObject* target);
|
void AddEmbeddedAppExtensions(cmXCodeObject* target);
|
||||||
void AddEmbeddedExtensionKitExtensions(cmXCodeObject* target);
|
void AddEmbeddedExtensionKitExtensions(cmXCodeObject* target);
|
||||||
|
void AddEmbeddedResources(cmXCodeObject* target);
|
||||||
void AddPositionIndependentLinkAttribute(cmGeneratorTarget* target,
|
void AddPositionIndependentLinkAttribute(cmGeneratorTarget* target,
|
||||||
cmXCodeObject* buildSettings,
|
cmXCodeObject* buildSettings,
|
||||||
const std::string& configName);
|
const std::string& configName);
|
||||||
@@ -355,6 +356,7 @@ private:
|
|||||||
std::string const& configName);
|
std::string const& configName);
|
||||||
cmXCodeObject* MainGroupChildren;
|
cmXCodeObject* MainGroupChildren;
|
||||||
cmXCodeObject* FrameworkGroup;
|
cmXCodeObject* FrameworkGroup;
|
||||||
|
cmXCodeObject* ResourcesGroup;
|
||||||
cmMakefile* CurrentMakefile;
|
cmMakefile* CurrentMakefile;
|
||||||
cmLocalGenerator* CurrentLocalGenerator;
|
cmLocalGenerator* CurrentLocalGenerator;
|
||||||
cmLocalGenerator* CurrentRootGenerator = nullptr;
|
cmLocalGenerator* CurrentRootGenerator = nullptr;
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
include(${CMAKE_CURRENT_LIST_DIR}/findAttribute.cmake)
|
include(${CMAKE_CURRENT_LIST_DIR}/findAttribute.cmake)
|
||||||
|
|
||||||
findAttribute(${test} "RemoveHeadersOnCopy" TRUE)
|
|
||||||
findAttribute(${test} "CodeSignOnCopy" FALSE)
|
findAttribute(${test} "CodeSignOnCopy" FALSE)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
add_executable(plug_in MACOS_BUNDLE Empty.txt)
|
add_executable(plug_in MACOSX_BUNDLE Empty.txt)
|
||||||
set_target_properties(plug_in PROPERTIES
|
set_target_properties(plug_in PROPERTIES
|
||||||
LINKER_LANGUAGE CXX
|
LINKER_LANGUAGE CXX
|
||||||
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
|
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
|
||||||
|
@@ -0,0 +1,3 @@
|
|||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/findAttribute.cmake)
|
||||||
|
|
||||||
|
findAttribute(${test} "Embed Resources" TRUE)
|
@@ -0,0 +1 @@
|
|||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/EmbedResources.cmake)
|
@@ -0,0 +1,3 @@
|
|||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/findAttribute.cmake)
|
||||||
|
|
||||||
|
findAttribute(${test} "Embed Resources" TRUE)
|
@@ -0,0 +1 @@
|
|||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/EmbedResources.cmake)
|
18
Tests/RunCMake/XcodeProject-Embed/EmbedResources.cmake
Normal file
18
Tests/RunCMake/XcodeProject-Embed/EmbedResources.cmake
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
add_executable(app MACOSX_BUNDLE main.m)
|
||||||
|
|
||||||
|
set(EMBED_RESOURCES_FOLDER ${CMAKE_BINARY_DIR}/runtime/shaders)
|
||||||
|
|
||||||
|
# ensure embed resources folder exists
|
||||||
|
if (NOT (IS_DIRECTORY ${EMBED_RESOURCES_FOLDER}))
|
||||||
|
file(MAKE_DIRECTORY ${EMBED_RESOURCES_FOLDER})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set_target_properties(app PROPERTIES
|
||||||
|
XCODE_EMBED_RESOURCES_PATH ${EMBED_RESOURCES_FOLDER}
|
||||||
|
)
|
||||||
|
|
||||||
|
set_target_properties(app PROPERTIES
|
||||||
|
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
|
||||||
|
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
|
||||||
|
MACOSX_BUNDLE_GUI_IDENTIFIER "com.example.app"
|
||||||
|
)
|
@@ -83,6 +83,25 @@ function(TestExtensionKitExtension platform)
|
|||||||
)
|
)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(TestEmbedCommon what platform)
|
||||||
|
set(testName Embed${what}-${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.
|
# Isolate device tests from host architecture selection.
|
||||||
unset(ENV{CMAKE_OSX_ARCHITECTURES})
|
unset(ENV{CMAKE_OSX_ARCHITECTURES})
|
||||||
|
|
||||||
@@ -100,4 +119,7 @@ if(XCODE_VERSION VERSION_GREATER_EQUAL 14.1)
|
|||||||
# defaults, which is to remove headers on copy, but not code sign.
|
# defaults, which is to remove headers on copy, but not code sign.
|
||||||
TestAppExtension(macOS)
|
TestAppExtension(macOS)
|
||||||
TestAppExtension(iOS)
|
TestAppExtension(iOS)
|
||||||
|
TestEmbedCommon(Resources macOS)
|
||||||
|
TestEmbedCommon(Resources iOS)
|
||||||
|
TestEmbedCommon(PlugIns macOS)
|
||||||
endif()
|
endif()
|
||||||
|
Reference in New Issue
Block a user