diff options
author | Brad King <brad.king@kitware.com> | 2018-03-12 17:42:12 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-03-12 17:42:18 (GMT) |
commit | 378a11cdbad6732971e91d5999f5788e26e35438 (patch) | |
tree | 395ba8383558a93a0a1f0e852a88a6427287805a /Source | |
parent | 746ebaf563baa76613d6629a8d53cdeffb6d8a85 (diff) | |
parent | 7fec336bf72684d5b2610e7d6d6041f40c61e833 (diff) | |
download | CMake-378a11cdbad6732971e91d5999f5788e26e35438.zip CMake-378a11cdbad6732971e91d5999f5788e26e35438.tar.gz CMake-378a11cdbad6732971e91d5999f5788e26e35438.tar.bz2 |
Merge topic 'genex-TARGET_EXISTS'
7fec336bf7 genex: Add TARGET_EXISTS to check for target existence
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1829
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 0d22028..f444113 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -300,6 +300,37 @@ static const struct InListNode : public cmGeneratorExpressionNode } } inListNode; +static const struct TargetExistsNode : public cmGeneratorExpressionNode +{ + TargetExistsNode() {} + + int NumExpectedParameters() const override { return 1; } + + std::string Evaluate( + const std::vector<std::string>& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override + { + if (parameters.size() != 1) { + reportError(context, content->GetOriginalExpression(), + "$<TARGET_EXISTS:...> expression requires one parameter"); + return std::string(); + } + + std::string targetName = parameters.front(); + if (targetName.empty() || + !cmGeneratorExpression::IsValidTargetName(targetName)) { + reportError(context, content->GetOriginalExpression(), + "$<TARGET_EXISTS:tgt> expression requires a non-empty " + "valid target name."); + return std::string(); + } + + return context->LG->GetMakefile()->FindTargetToUse(targetName) ? "1" : "0"; + } +} targetExistsNode; + static const struct LowerCaseNode : public cmGeneratorExpressionNode { LowerCaseNode() {} @@ -1865,6 +1896,7 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode( nodeMap["TARGET_NAME"] = &targetNameNode; nodeMap["TARGET_OBJECTS"] = &targetObjectsNode; nodeMap["TARGET_POLICY"] = &targetPolicyNode; + nodeMap["TARGET_EXISTS"] = &targetExistsNode; nodeMap["BUILD_INTERFACE"] = &buildInterfaceNode; nodeMap["INSTALL_INTERFACE"] = &installInterfaceNode; nodeMap["INSTALL_PREFIX"] = &installPrefixNode; |