浏览代码

Merge topic 'xcode-embed-resources'

e40d2cb3af Xcode: Add embed resources support

Acked-by: Kitware Robot <[email protected]>
Tested-by: buildbot <[email protected]>
Acked-by: Deal <[email protected]>
Merge-request: !8632
Brad King 2 年之前
父节点
当前提交
17dcd9424a

+ 6 - 0
Help/prop_tgt/XCODE_EMBED_type.rst

@@ -37,6 +37,12 @@ The supported values for ``<type>`` are:
   The specified items will be added to the ``Embed PlugIns`` build phase.
   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`,
 :prop_tgt:`XCODE_EMBED_<type>_REMOVE_HEADERS_ON_COPY` and
 :prop_tgt:`XCODE_EMBED_<type>_CODE_SIGN_ON_COPY`.

+ 3 - 0
Help/prop_tgt/XCODE_EMBED_type_PATH.rst

@@ -22,3 +22,6 @@ The supported values for ``<type>`` are:
 
 ``PLUGINS``
   .. versionadded:: 3.23
+
+``RESOURCES``
+  .. versionadded:: 3.28

+ 6 - 0
Help/release/dev/xcode-embed-resources.rst

@@ -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.

+ 30 - 4
Source/cmGlobalXCodeGenerator.cxx

@@ -1272,10 +1272,16 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath(
   fileRef->AddAttribute("sourceTree", this->CreateString(sourceTree));
 
   cmXCodeObject* group = this->GroupMap[key];
-  if (!group && IsLibraryType(fileType)) {
-    group = this->FrameworkGroup;
-    this->GroupMap[key] = group;
+  if (!group) {
+    if (IsLibraryType(fileType)) {
+      group = this->FrameworkGroup;
+    } else if (fileType == "folder") {
+      group = this->ResourcesGroup;
+    }
+    if (group)
+      this->GroupMap[key] = group;
   }
+
   if (!group) {
     cmSystemTools::Error(cmStrCat("Could not find a PBX group for ", key));
     return nullptr;
@@ -4108,7 +4114,8 @@ void cmGlobalXCodeGenerator::AddEmbeddedObjects(
         buildFile = it->second;
       }
     } else if (cmSystemTools::IsPathToFramework(relFile) ||
-               cmSystemTools::IsPathToMacOSSharedLibrary(relFile)) {
+               cmSystemTools::IsPathToMacOSSharedLibrary(relFile) ||
+               cmSystemTools::FileIsDirectory(filePath)) {
       // This is a regular string path - create file reference
       auto it = this->EmbeddedLibRefs.find(relFile);
       if (it == this->EmbeddedLibRefs.end()) {
@@ -4210,6 +4217,15 @@ void cmGlobalXCodeGenerator::AddEmbeddedExtensionKitExtensions(
                            "$(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(
   std::vector<cmLocalGenerator*>& generators)
 {
@@ -4411,6 +4427,15 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
   this->FrameworkGroup->AddAttribute("children", frameworkGroupChildren);
   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->SetComment("Project object");
 
@@ -4602,6 +4627,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
     this->AddEmbeddedPlugIns(t);
     this->AddEmbeddedAppExtensions(t);
     this->AddEmbeddedExtensionKitExtensions(t);
+    this->AddEmbeddedResources(t);
     // Inherit project-wide values for any target-specific search paths.
     this->InheritBuildSettingAttribute(t, "HEADER_SEARCH_PATHS");
     this->InheritBuildSettingAttribute(t, "SYSTEM_HEADER_SEARCH_PATHS");

+ 2 - 0
Source/cmGlobalXCodeGenerator.h

@@ -224,6 +224,7 @@ private:
   void AddEmbeddedPlugIns(cmXCodeObject* target);
   void AddEmbeddedAppExtensions(cmXCodeObject* target);
   void AddEmbeddedExtensionKitExtensions(cmXCodeObject* target);
+  void AddEmbeddedResources(cmXCodeObject* target);
   void AddPositionIndependentLinkAttribute(cmGeneratorTarget* target,
                                            cmXCodeObject* buildSettings,
                                            const std::string& configName);
@@ -355,6 +356,7 @@ private:
                                   std::string const& configName);
   cmXCodeObject* MainGroupChildren;
   cmXCodeObject* FrameworkGroup;
+  cmXCodeObject* ResourcesGroup;
   cmMakefile* CurrentMakefile;
   cmLocalGenerator* CurrentLocalGenerator;
   cmLocalGenerator* CurrentRootGenerator = nullptr;

+ 0 - 1
Tests/RunCMake/XcodeProject-Embed/EmbedPlugIns-macOS-check.cmake

@@ -1,4 +1,3 @@
 include(${CMAKE_CURRENT_LIST_DIR}/findAttribute.cmake)
 
-findAttribute(${test} "RemoveHeadersOnCopy" TRUE)
 findAttribute(${test} "CodeSignOnCopy" FALSE)

+ 1 - 1
Tests/RunCMake/XcodeProject-Embed/EmbedPlugIns.cmake

@@ -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
   LINKER_LANGUAGE CXX
   XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"

+ 3 - 0
Tests/RunCMake/XcodeProject-Embed/EmbedResources-iOS-check.cmake

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

+ 1 - 0
Tests/RunCMake/XcodeProject-Embed/EmbedResources-iOS.cmake

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

+ 3 - 0
Tests/RunCMake/XcodeProject-Embed/EmbedResources-macOS-check.cmake

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

+ 1 - 0
Tests/RunCMake/XcodeProject-Embed/EmbedResources-macOS.cmake

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

+ 18 - 0
Tests/RunCMake/XcodeProject-Embed/EmbedResources.cmake

@@ -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"
+)

+ 22 - 0
Tests/RunCMake/XcodeProject-Embed/RunCMakeTest.cmake

@@ -83,6 +83,25 @@ function(TestExtensionKitExtension platform)
   )
 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.
 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.
   TestAppExtension(macOS)
   TestAppExtension(iOS)
+  TestEmbedCommon(Resources macOS)
+  TestEmbedCommon(Resources iOS)
+  TestEmbedCommon(PlugIns macOS)
 endif()