Add the TARGET_NAME generator expression.

It will be used as a preprocessing marker.
This commit is contained in:
Stephen Kelly 2012-12-10 11:33:23 +01:00
parent 77475fe61d
commit b0c8f73eb6
8 changed files with 45 additions and 0 deletions

View File

@ -26,6 +26,10 @@
"strings which contain a '>' for example.\n" \
" $<COMMA> = A literal ','. Used to compare " \
"strings which contain a ',' for example.\n" \
" $<TARGET_NAME:...> = Marks ... as being the name of a " \
"target. This is required if exporting targets to multiple " \
"dependent export sets. The '...' must be a literal name of a " \
"target- it may not contain generator expressions.\n" \
" $<INSTALL_INTERFACE:...> = content of \"...\" when the property " \
"is exported using install(EXPORT), and empty otherwise.\n" \
" $<BUILD_INTERFACE:...> = content of \"...\" when the property " \

View File

@ -376,6 +376,28 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
}
} targetPropertyNode;
//----------------------------------------------------------------------------
static const struct TargetNameNode : public cmGeneratorExpressionNode
{
TargetNameNode() {}
virtual bool GeneratesContent() const { return true; }
virtual bool AcceptsSingleArbitraryContentParameter() const { return true; }
virtual bool RequiresLiteralInput() const { return true; }
std::string Evaluate(const std::vector<std::string> &parameters,
cmGeneratorExpressionContext *,
const GeneratorExpressionContent *,
cmGeneratorExpressionDAGChecker *) const
{
return parameters.front();
}
virtual int NumExpectedParameters() const { return 1; }
} targetNameNode;
//----------------------------------------------------------------------------
template<bool linker, bool soname>
struct TargetFilesystemArtifactResultCreator
@ -601,6 +623,8 @@ cmGeneratorExpressionNode* GetNode(const std::string &identifier)
return &commaNode;
else if (identifier == "TARGET_PROPERTY")
return &targetPropertyNode;
else if (identifier == "TARGET_NAME")
return &targetNameNode;
else if (identifier == "BUILD_INTERFACE")
return &buildInterfaceNode;
else if (identifier == "INSTALL_INTERFACE")

View File

@ -87,6 +87,8 @@ add_custom_target(check-part2 ALL
-Dtest_incomplete_21=$<BOOL:something$<ANGLE-R>
-Dtest_build_interface=$<BUILD_INTERFACE:build>
-Dtest_install_interface=$<INSTALL_INTERFACE:install>
-Dtest_target_name_1=$<TARGET_NAME:tgt,ok>
-Dtest_target_name_2=$<TARGET_NAME:tgt:ok>
-P ${CMAKE_CURRENT_SOURCE_DIR}/check-part2.cmake
COMMAND ${CMAKE_COMMAND} -E echo "check done (part 2 of 2)"
VERBATIM

View File

@ -24,3 +24,5 @@ check(test_incomplete_20 "$<CONFIGURATION>")
check(test_incomplete_21 "$<BOOL:something>")
check(test_build_interface "build")
check(test_install_interface "")
check(test_target_name_1 "tgt,ok")
check(test_target_name_2 "tgt:ok")

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,8 @@
CMake Error at BadTargetName.cmake:1 \(add_custom_target\):
Error evaluating generator expression:
\$<TARGET_NAME:\$<1:tgt>>
\$<TARGET_NAME> expression requires literal input.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)$

View File

@ -0,0 +1,3 @@
add_custom_target(check ALL COMMAND check
$<TARGET_NAME:$<1:tgt>>
VERBATIM)

View File

@ -6,3 +6,4 @@ run_cmake(BadAND)
run_cmake(BadNOT)
run_cmake(BadStrEqual)
run_cmake(BadZero)
run_cmake(BadTargetName)