mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-02 20:00:38 -06:00
Genex: Add TARGET_BUNDLE_[CONTENT_]_DIR generator expressions
Closes #16733
This commit is contained in:
@@ -205,6 +205,15 @@ Available informational expressions are:
|
||||
Name of the linker generated program database file (.pdb).
|
||||
``$<TARGET_PDB_FILE_DIR:tgt>``
|
||||
Directory of the linker generated program database file (.pdb).
|
||||
``$<TARGET_BUNDLE_DIR:tgt>``
|
||||
Full path to the bundle directory (``my.app``, ``my.framework``, or
|
||||
``my.bundle``) where ``tgt`` is the name of a target.
|
||||
``$<TARGET_BUNDLE_CONTENT_DIR:tgt>``
|
||||
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_PROPERTY:tgt,prop>``
|
||||
Value of the property ``prop`` on the target ``tgt``.
|
||||
|
||||
|
||||
12
Help/release/dev/bundle-genex.rst
Normal file
12
Help/release/dev/bundle-genex.rst
Normal file
@@ -0,0 +1,12 @@
|
||||
bundle-genex
|
||||
------------
|
||||
|
||||
* Two new informational generator expressions to retrieve Apple Bundle
|
||||
directories have been added. The first one ``$<TARGET_BUNDLE_DIR:tgt>``
|
||||
outputs the full path to the Bundle directory, the other one
|
||||
``$<TARGET_BUNDLE_CONTENT_DIR:tgt>`` outputs the full path to the
|
||||
``Contents`` directory of macOS Bundles and App Bundles. For all other
|
||||
bundle types and SDKs it is identical with ``$<TARGET_BUNDLE_DIR:tgt>``.
|
||||
|
||||
Those new expressions are helpful to query Bundle locations independent of
|
||||
the different Bundle types and layouts on macOS and iOS.
|
||||
@@ -1504,6 +1504,8 @@ class ArtifactNameTag;
|
||||
class ArtifactPathTag;
|
||||
class ArtifactPdbTag;
|
||||
class ArtifactSonameTag;
|
||||
class ArtifactBundleDirTag;
|
||||
class ArtifactBundleContentDirTag;
|
||||
|
||||
template <typename ArtifactT>
|
||||
struct TargetFilesystemArtifactResultCreator
|
||||
@@ -1599,6 +1601,56 @@ struct TargetFilesystemArtifactResultCreator<ArtifactLinkerTag>
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TargetFilesystemArtifactResultCreator<ArtifactBundleDirTag>
|
||||
{
|
||||
static std::string Create(cmGeneratorTarget* target,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent* content)
|
||||
{
|
||||
if (target->IsImported()) {
|
||||
::reportError(context, content->GetOriginalExpression(),
|
||||
"TARGET_BUNDLE_DIR not allowed for IMPORTED targets.");
|
||||
return std::string();
|
||||
}
|
||||
if (!target->IsBundleOnApple()) {
|
||||
::reportError(context, content->GetOriginalExpression(),
|
||||
"TARGET_BUNDLE_DIR is allowed only for Bundle targets.");
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string outpath = target->GetDirectory(context->Config) + '/';
|
||||
return target->BuildBundleDirectory(outpath, context->Config,
|
||||
cmGeneratorTarget::BundleDirLevel);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TargetFilesystemArtifactResultCreator<ArtifactBundleContentDirTag>
|
||||
{
|
||||
static std::string Create(cmGeneratorTarget* target,
|
||||
cmGeneratorExpressionContext* context,
|
||||
const GeneratorExpressionContent* content)
|
||||
{
|
||||
if (target->IsImported()) {
|
||||
::reportError(
|
||||
context, content->GetOriginalExpression(),
|
||||
"TARGET_BUNDLE_CONTENT_DIR not allowed for IMPORTED targets.");
|
||||
return std::string();
|
||||
}
|
||||
if (!target->IsBundleOnApple()) {
|
||||
::reportError(
|
||||
context, content->GetOriginalExpression(),
|
||||
"TARGET_BUNDLE_CONTENT_DIR is allowed only for Bundle targets.");
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string outpath = target->GetDirectory(context->Config) + '/';
|
||||
return target->BuildBundleDirectory(outpath, context->Config,
|
||||
cmGeneratorTarget::ContentLevel);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct TargetFilesystemArtifactResultCreator<ArtifactNameTag>
|
||||
{
|
||||
@@ -1716,6 +1768,13 @@ static const TargetFilesystemArtifactNodeGroup<ArtifactSonameTag>
|
||||
static const TargetFilesystemArtifactNodeGroup<ArtifactPdbTag>
|
||||
targetPdbNodeGroup;
|
||||
|
||||
static const TargetFilesystemArtifact<ArtifactBundleDirTag, ArtifactPathTag>
|
||||
targetBundleDirNode;
|
||||
|
||||
static const TargetFilesystemArtifact<ArtifactBundleContentDirTag,
|
||||
ArtifactPathTag>
|
||||
targetBundleContentDirNode;
|
||||
|
||||
static const struct ShellPathNode : public cmGeneratorExpressionNode
|
||||
{
|
||||
ShellPathNode() {}
|
||||
@@ -1772,6 +1831,8 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
|
||||
nodeMap["TARGET_LINKER_FILE_DIR"] = &targetLinkerNodeGroup.FileDir;
|
||||
nodeMap["TARGET_SONAME_FILE_DIR"] = &targetSoNameNodeGroup.FileDir;
|
||||
nodeMap["TARGET_PDB_FILE_DIR"] = &targetPdbNodeGroup.FileDir;
|
||||
nodeMap["TARGET_BUNDLE_DIR"] = &targetBundleDirNode;
|
||||
nodeMap["TARGET_BUNDLE_CONTENT_DIR"] = &targetBundleContentDirNode;
|
||||
nodeMap["STREQUAL"] = &strEqualNode;
|
||||
nodeMap["EQUAL"] = &equalNode;
|
||||
nodeMap["LOWER_CASE"] = &lowerCaseNode;
|
||||
|
||||
@@ -1493,6 +1493,12 @@ static bool shouldAddFullLevel(cmGeneratorTarget::BundleDirectoryLevel level)
|
||||
return level == cmGeneratorTarget::FullLevel;
|
||||
}
|
||||
|
||||
static bool shouldAddContentLevel(
|
||||
cmGeneratorTarget::BundleDirectoryLevel level)
|
||||
{
|
||||
return level == cmGeneratorTarget::ContentLevel || shouldAddFullLevel(level);
|
||||
}
|
||||
|
||||
std::string cmGeneratorTarget::GetAppBundleDirectory(
|
||||
const std::string& config, BundleDirectoryLevel level) const
|
||||
{
|
||||
@@ -1503,7 +1509,7 @@ std::string cmGeneratorTarget::GetAppBundleDirectory(
|
||||
ext = "app";
|
||||
}
|
||||
fpath += ext;
|
||||
if (!this->Makefile->PlatformIsAppleIos()) {
|
||||
if (shouldAddContentLevel(level) && !this->Makefile->PlatformIsAppleIos()) {
|
||||
fpath += "/Contents";
|
||||
if (shouldAddFullLevel(level)) {
|
||||
fpath += "/MacOS";
|
||||
@@ -1533,7 +1539,7 @@ std::string cmGeneratorTarget::GetCFBundleDirectory(
|
||||
}
|
||||
}
|
||||
fpath += ext;
|
||||
if (!this->Makefile->PlatformIsAppleIos()) {
|
||||
if (shouldAddContentLevel(level) && !this->Makefile->PlatformIsAppleIos()) {
|
||||
fpath += "/Contents";
|
||||
if (shouldAddFullLevel(level)) {
|
||||
fpath += "/MacOS";
|
||||
|
||||
@@ -163,6 +163,7 @@ public:
|
||||
/** What hierarchy level should the reported directory contain */
|
||||
enum BundleDirectoryLevel
|
||||
{
|
||||
BundleDirLevel,
|
||||
ContentLevel,
|
||||
FullLevel
|
||||
};
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,8 @@
|
||||
CMake Error at ImportedTarget-TARGET_BUNDLE_CONTENT_DIR.cmake:[0-9]* \(add_custom_target\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_BUNDLE_CONTENT_DIR:empty>
|
||||
|
||||
TARGET_BUNDLE_CONTENT_DIR not allowed for IMPORTED targets.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]* \(include\)
|
||||
@@ -0,0 +1,2 @@
|
||||
add_library(empty UNKNOWN IMPORTED)
|
||||
add_custom_target(custom COMMAND echo $<TARGET_BUNDLE_CONTENT_DIR:empty>)
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,8 @@
|
||||
CMake Error at ImportedTarget-TARGET_BUNDLE_DIR.cmake:[0-9]* \(add_custom_target\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_BUNDLE_DIR:empty>
|
||||
|
||||
TARGET_BUNDLE_DIR not allowed for IMPORTED targets.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]* \(include\)
|
||||
@@ -0,0 +1,2 @@
|
||||
add_library(empty UNKNOWN IMPORTED)
|
||||
add_custom_target(custom COMMAND echo $<TARGET_BUNDLE_DIR:empty>)
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,8 @@
|
||||
CMake Error at NonValidTarget-TARGET_BUNDLE_CONTENT_DIR.cmake:[0-9]* \(file\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_BUNDLE_CONTENT_DIR:empty>
|
||||
|
||||
TARGET_BUNDLE_CONTENT_DIR is allowed only for Bundle targets.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]* \(include\)
|
||||
@@ -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_CONTENT_DIR:empty>]"
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,8 @@
|
||||
CMake Error at NonValidTarget-TARGET_BUNDLE_DIR.cmake:[0-9]* \(file\):
|
||||
Error evaluating generator expression:
|
||||
|
||||
\$<TARGET_BUNDLE_DIR:empty>
|
||||
|
||||
TARGET_BUNDLE_DIR is allowed only for Bundle targets.
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]* \(include\)
|
||||
@@ -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:empty>]"
|
||||
)
|
||||
@@ -17,6 +17,8 @@ run_cmake(NonValidTarget-C_COMPILER_ID)
|
||||
run_cmake(NonValidTarget-CXX_COMPILER_ID)
|
||||
run_cmake(NonValidTarget-C_COMPILER_VERSION)
|
||||
run_cmake(NonValidTarget-CXX_COMPILER_VERSION)
|
||||
run_cmake(NonValidTarget-TARGET_BUNDLE_DIR)
|
||||
run_cmake(NonValidTarget-TARGET_BUNDLE_CONTENT_DIR)
|
||||
run_cmake(NonValidTarget-TARGET_PROPERTY)
|
||||
run_cmake(NonValidTarget-TARGET_POLICY)
|
||||
run_cmake(COMPILE_LANGUAGE-add_custom_target)
|
||||
@@ -32,6 +34,8 @@ run_cmake(OUTPUT_NAME-recursion)
|
||||
run_cmake(TARGET_PROPERTY-LOCATION)
|
||||
run_cmake(LINK_ONLY-not-linking)
|
||||
|
||||
run_cmake(ImportedTarget-TARGET_BUNDLE_DIR)
|
||||
run_cmake(ImportedTarget-TARGET_BUNDLE_CONTENT_DIR)
|
||||
run_cmake(ImportedTarget-TARGET_PDB_FILE)
|
||||
if(LINKER_SUPPORTS_PDB)
|
||||
run_cmake(NonValidTarget-TARGET_PDB_FILE)
|
||||
|
||||
@@ -57,6 +57,10 @@ if(NOT TEST_IOS OR NOT XCODE_VERSION VERSION_LESS 6)
|
||||
set_target_properties(SharedFramework PROPERTIES FRAMEWORK TRUE)
|
||||
|
||||
add_custom_target(SharedFrameworkTest ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_BUNDLE_DIR:SharedFramework>" "$<TARGET_BUNDLE_DIR:SharedFramework>.old"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_BUNDLE_CONTENT_DIR:SharedFramework>" "$<TARGET_BUNDLE_CONTENT_DIR:SharedFramework>.old"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_FILE:SharedFramework>" "$<TARGET_FILE:SharedFramework>.old")
|
||||
|
||||
@@ -70,6 +74,10 @@ if(NOT TEST_IOS OR NOT XCODE_VERSION VERSION_LESS 6)
|
||||
install(TARGETS SharedFrameworkExt FRAMEWORK DESTINATION FooExtension)
|
||||
|
||||
add_custom_target(SharedFrameworkExtTest ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_BUNDLE_DIR:SharedFrameworkExt>" "$<TARGET_BUNDLE_DIR:SharedFrameworkExt>.old"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_BUNDLE_CONTENT_DIR:SharedFrameworkExt>" "$<TARGET_BUNDLE_CONTENT_DIR:SharedFrameworkExt>.old"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_FILE:SharedFrameworkExt>" "$<TARGET_FILE:SharedFrameworkExt>.old")
|
||||
|
||||
@@ -83,6 +91,10 @@ if(NOT XCODE_VERSION VERSION_LESS 6)
|
||||
set_target_properties(StaticFramework PROPERTIES FRAMEWORK TRUE)
|
||||
|
||||
add_custom_target(StaticFrameworkTest ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_BUNDLE_DIR:StaticFramework>" "$<TARGET_BUNDLE_DIR:StaticFramework>.old"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_BUNDLE_CONTENT_DIR:StaticFramework>" "$<TARGET_BUNDLE_CONTENT_DIR:StaticFramework>.old"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_FILE:StaticFramework>" "$<TARGET_FILE:StaticFramework>.old")
|
||||
|
||||
@@ -96,6 +108,10 @@ if(NOT XCODE_VERSION VERSION_LESS 6)
|
||||
install(TARGETS StaticFrameworkExt FRAMEWORK DESTINATION StaticFooExtension)
|
||||
|
||||
add_custom_target(StaticFrameworkExtTest ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_BUNDLE_DIR:StaticFrameworkExt>" "$<TARGET_BUNDLE_DIR:StaticFrameworkExt>.old"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_BUNDLE_CONTENT_DIR:StaticFrameworkExt>" "$<TARGET_BUNDLE_CONTENT_DIR:StaticFrameworkExt>.old"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_FILE:StaticFrameworkExt>" "$<TARGET_FILE:StaticFrameworkExt>.old")
|
||||
|
||||
@@ -109,6 +125,10 @@ if(NOT CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE)
|
||||
set_target_properties(Bundle PROPERTIES BUNDLE TRUE)
|
||||
|
||||
add_custom_target(BundleTest ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_BUNDLE_DIR:Bundle>" "$<TARGET_BUNDLE_DIR:Bundle>.old"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_BUNDLE_CONTENT_DIR:Bundle>" "$<TARGET_BUNDLE_CONTENT_DIR:Bundle>.old"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_FILE:Bundle>" "$<TARGET_FILE:Bundle>.old")
|
||||
|
||||
@@ -122,6 +142,10 @@ if(NOT CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE)
|
||||
install(TARGETS BundleExt LIBRARY DESTINATION FooExtension)
|
||||
|
||||
add_custom_target(BundleExtTest ALL
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_BUNDLE_DIR:BundleExt>" "$<TARGET_BUNDLE_DIR:BundleExt>.old"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_BUNDLE_CONTENT_DIR:BundleExt>" "$<TARGET_BUNDLE_CONTENT_DIR:BundleExt>.old"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
"$<TARGET_FILE:BundleExt>" "$<TARGET_FILE:BundleExt>.old")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user