소스 검색

Merge topic 'target-bundle-dir-name-genex'

997af2e1a6 Genex: Add TARGET_BUNDLE_DIR_NAME
627b2eba6c Help: Make TARGET_BUNDLE[_CONTENT]_DIR examples more precise

Acked-by: Kitware Robot <[email protected]>
Merge-request: !7177
Brad King 3 년 전
부모
커밋
07a54b2bb2

+ 1 - 0
Auxiliary/vim/syntax/cmake.vim

@@ -3781,6 +3781,7 @@ syn keyword cmakeGeneratorExpressions contained
             \ STREQUAL
             \ TARGET_BUNDLE_CONTENT_DIR
             \ TARGET_BUNDLE_DIR
+            \ TARGET_BUNDLE_DIR_NAME
             \ TARGET_EXISTS
             \ TARGET_FILE
             \ TARGET_FILE_BASE_NAME

+ 18 - 6
Help/manual/cmake-generator-expressions.7.rst

@@ -1019,8 +1019,19 @@ which is just the string ``tgt``.
 
   .. versionadded:: 3.9
 
-  Full path to the bundle directory (``my.app``, ``my.framework``, or
-  ``my.bundle``) where ``tgt`` is the name of a target.
+  Full path to the bundle directory (``/path/to/my.app``,
+  ``/path/to/my.framework``, or ``/path/to/my.bundle``),
+  where ``tgt`` is the name of a target.
+
+  Note that ``tgt`` is not added as a dependency of the target this
+  expression is evaluated on (see policy :policy:`CMP0112`).
+
+.. genex:: $<TARGET_BUNDLE_DIR_NAME:tgt>
+
+  .. versionadded:: 3.24
+
+  Name of the bundle directory (``my.app``, ``my.framework``, or
+  ``my.bundle``), where ``tgt`` is the name of a target.
 
   Note that ``tgt`` is not added as a dependency of the target this
   expression is evaluated on (see policy :policy:`CMP0112`).
@@ -1030,10 +1041,11 @@ which is just the string ``tgt``.
   .. versionadded:: 3.9
 
   Full path to the bundle content directory where ``tgt`` is the name of a
-  target. For the macOS SDK it leads to ``my.app/Contents``, ``my.framework``,
-  or ``my.bundle/Contents``. For all other SDKs (e.g. iOS) it leads to
-  ``my.app``, ``my.framework``, or ``my.bundle`` due to the flat bundle
-  structure.
+  target.  For the macOS SDK it leads to ``/path/to/my.app/Contents``,
+  ``/path/to/my.framework``, or ``/path/to/my.bundle/Contents``.
+  For all other SDKs (e.g. iOS) it leads to ``/path/to/my.app``,
+  ``/path/to/my.framework``, or ``/path/to/my.bundle`` due to the flat
+  bundle structure.
 
   Note that ``tgt`` is not added as a dependency of the target this
   expression is evaluated on (see policy :policy:`CMP0112`).

+ 1 - 0
Help/policy/CMP0112.rst

@@ -18,6 +18,7 @@ file name components no longer add a dependency on the evaluated target.
     - ``TARGET_PDB_FILE_NAME``
     - ``TARGET_PDB_FILE_DIR``
     - ``TARGET_BUNDLE_DIR``
+    - ``TARGET_BUNDLE_DIR_NAME``
     - ``TARGET_BUNDLE_CONTENT_DIR``
 
 

+ 6 - 0
Help/release/dev/target-bundle-dir-name-genex.rst

@@ -0,0 +1,6 @@
+target-bundle-dir-name-genex
+----------------------------
+
+* Added the new :genex:`TARGET_BUNDLE_DIR_NAME` generator expression
+  which evaluates to the name of the bundle directory for a given bundle
+  target.

+ 39 - 1
Source/cmGeneratorExpressionNode.cxx

@@ -2098,6 +2098,7 @@ class ArtifactPathTag;
 class ArtifactPdbTag;
 class ArtifactSonameTag;
 class ArtifactBundleDirTag;
+class ArtifactBundleDirNameTag;
 class ArtifactBundleContentDirTag;
 
 template <typename ArtifactT, typename ComponentT>
@@ -2158,6 +2159,12 @@ struct TargetFilesystemArtifactDependency<ArtifactBundleDirTag,
 {
 };
 template <>
+struct TargetFilesystemArtifactDependency<ArtifactBundleDirNameTag,
+                                          ArtifactPathTag>
+  : TargetFilesystemArtifactDependencyCMP0112
+{
+};
+template <>
 struct TargetFilesystemArtifactDependency<ArtifactBundleContentDirTag,
                                           ArtifactPathTag>
   : TargetFilesystemArtifactDependencyCMP0112
@@ -2284,6 +2291,31 @@ struct TargetFilesystemArtifactResultCreator<ArtifactBundleDirTag>
   }
 };
 
+template <>
+struct TargetFilesystemArtifactResultCreator<ArtifactBundleDirNameTag>
+{
+  static std::string Create(cmGeneratorTarget* target,
+                            cmGeneratorExpressionContext* context,
+                            const GeneratorExpressionContent* content)
+  {
+    if (target->IsImported()) {
+      ::reportError(
+        context, content->GetOriginalExpression(),
+        "TARGET_BUNDLE_DIR_NAME not allowed for IMPORTED targets.");
+      return std::string();
+    }
+    if (!target->IsBundleOnApple()) {
+      ::reportError(
+        context, content->GetOriginalExpression(),
+        "TARGET_BUNDLE_DIR_NAME is allowed only for Bundle targets.");
+      return std::string();
+    }
+
+    return target->GetAppBundleDirectory(context->Config,
+                                         cmGeneratorTarget::BundleDirLevel);
+  }
+};
+
 template <>
 struct TargetFilesystemArtifactResultCreator<ArtifactBundleContentDirTag>
 {
@@ -2417,7 +2449,8 @@ struct TargetFilesystemArtifact : public TargetArtifactBase
       return std::string();
     }
     // Not a dependent target if we are querying for ArtifactDirTag,
-    // ArtifactNameTag, ArtifactBundleDirTag, and ArtifactBundleContentDirTag
+    // ArtifactNameTag, ArtifactBundleDirTag, ArtifactBundleDirNameTag,
+    // and ArtifactBundleContentDirTag
     TargetFilesystemArtifactDependency<ArtifactT, ComponentT>::AddDependency(
       target, context);
 
@@ -2458,6 +2491,10 @@ static const TargetFilesystemArtifactNodeGroup<ArtifactPdbTag>
 static const TargetFilesystemArtifact<ArtifactBundleDirTag, ArtifactPathTag>
   targetBundleDirNode;
 
+static const TargetFilesystemArtifact<ArtifactBundleDirNameTag,
+                                      ArtifactNameTag>
+  targetBundleDirNameNode;
+
 static const TargetFilesystemArtifact<ArtifactBundleContentDirTag,
                                       ArtifactPathTag>
   targetBundleContentDirNode;
@@ -2783,6 +2820,7 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
     { "TARGET_SONAME_FILE_DIR", &targetSoNameNodeGroup.FileDir },
     { "TARGET_PDB_FILE_DIR", &targetPdbNodeGroup.FileDir },
     { "TARGET_BUNDLE_DIR", &targetBundleDirNode },
+    { "TARGET_BUNDLE_DIR_NAME", &targetBundleDirNameNode },
     { "TARGET_BUNDLE_CONTENT_DIR", &targetBundleContentDirNode },
     { "STREQUAL", &strEqualNode },
     { "EQUAL", &equalNode },

+ 1 - 0
Tests/RunCMake/GenEx-TARGET_FILE/ImportedTarget-TARGET_BUNDLE_DIR_NAME-result.txt

@@ -0,0 +1 @@
+1

+ 8 - 0
Tests/RunCMake/GenEx-TARGET_FILE/ImportedTarget-TARGET_BUNDLE_DIR_NAME-stderr.txt

@@ -0,0 +1,8 @@
+CMake Error at ImportedTarget-TARGET_BUNDLE_DIR_NAME.cmake:[0-9]* \(add_custom_target\):
+  Error evaluating generator expression:
+
+    \$<TARGET_BUNDLE_DIR_NAME:empty>
+
+  TARGET_BUNDLE_DIR_NAME not allowed for IMPORTED targets.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:[0-9]* \(include\)

+ 2 - 0
Tests/RunCMake/GenEx-TARGET_FILE/ImportedTarget-TARGET_BUNDLE_DIR_NAME.cmake

@@ -0,0 +1,2 @@
+add_library(empty UNKNOWN IMPORTED)
+add_custom_target(custom COMMAND echo $<TARGET_BUNDLE_DIR_NAME:empty>)

+ 1 - 0
Tests/RunCMake/GenEx-TARGET_FILE/NonValidTarget-TARGET_BUNDLE_DIR_NAME-result.txt

@@ -0,0 +1 @@
+1

+ 8 - 0
Tests/RunCMake/GenEx-TARGET_FILE/NonValidTarget-TARGET_BUNDLE_DIR_NAME-stderr.txt

@@ -0,0 +1,8 @@
+CMake Error at NonValidTarget-TARGET_BUNDLE_DIR_NAME.cmake:[0-9]* \(file\):
+  Error evaluating generator expression:
+
+    \$<TARGET_BUNDLE_DIR_NAME:empty>
+
+  TARGET_BUNDLE_DIR_NAME is allowed only for Bundle targets.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:[0-9]* \(include\)

+ 9 - 0
Tests/RunCMake/GenEx-TARGET_FILE/NonValidTarget-TARGET_BUNDLE_DIR_NAME.cmake

@@ -0,0 +1,9 @@
+
+enable_language(C)
+
+add_library(empty STATIC empty.c)
+
+file(GENERATE
+  OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test.txt"
+  CONTENT "[$<TARGET_BUNDLE_DIR_NAME:empty>]"
+)

+ 2 - 0
Tests/RunCMake/GenEx-TARGET_FILE/RunCMakeTest.cmake

@@ -17,8 +17,10 @@ run_cmake_with_options(TARGET_FILE_BASE_NAME-imported-target -DCMAKE_BUILD_TYPE:
 run_cmake(TARGET_FILE_BASE_NAME-non-valid-target)
 run_cmake(TARGET_LINKER_FILE_BASE_NAME-non-valid-target)
 run_cmake(NonValidTarget-TARGET_BUNDLE_DIR)
+run_cmake(NonValidTarget-TARGET_BUNDLE_DIR_NAME)
 run_cmake(NonValidTarget-TARGET_BUNDLE_CONTENT_DIR)
 run_cmake(ImportedTarget-TARGET_BUNDLE_DIR)
+run_cmake(ImportedTarget-TARGET_BUNDLE_DIR_NAME)
 run_cmake(ImportedTarget-TARGET_BUNDLE_CONTENT_DIR)
 run_cmake(ImportedTarget-TARGET_PDB_FILE)
 run_cmake(ImportedTarget-TARGET_PDB_FILE_BASE_NAME)