diff options
author | Brad King <brad.king@kitware.com> | 2018-03-29 14:21:36 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-03-29 14:21:48 (GMT) |
commit | 3272677e634629628a6293614fd169ff66d72e0d (patch) | |
tree | d98a0edb3ee4258c5926307bdb8f2e9d400f60e6 /Source | |
parent | a03105ac8c821bd8a2fe269671b49862ae354db8 (diff) | |
parent | 7b173a29332af37eb285d8cf5924a44be3a944dd (diff) | |
download | CMake-3272677e634629628a6293614fd169ff66d72e0d.zip CMake-3272677e634629628a6293614fd169ff66d72e0d.tar.gz CMake-3272677e634629628a6293614fd169ff66d72e0d.tar.bz2 |
Merge topic 'genex-TARGET_NAME_IF_EXISTS'
7b173a2933 genex: Add TARGET_NAME_IF_EXISTS expression
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1890
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index f444113..09b7faf 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -331,6 +331,40 @@ static const struct TargetExistsNode : public cmGeneratorExpressionNode } } targetExistsNode; +static const struct TargetNameIfExistsNode : public cmGeneratorExpressionNode +{ + TargetNameIfExistsNode() {} + + 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_NAME_IF_EXISTS:...> expression requires one " + "parameter"); + return std::string(); + } + + std::string targetName = parameters.front(); + if (targetName.empty() || + !cmGeneratorExpression::IsValidTargetName(targetName)) { + reportError(context, content->GetOriginalExpression(), + "$<TARGET_NAME_IF_EXISTS:tgt> expression requires a " + "non-empty valid target name."); + return std::string(); + } + + return context->LG->GetMakefile()->FindTargetToUse(targetName) + ? targetName + : std::string(); + } +} targetNameIfExistsNode; + static const struct LowerCaseNode : public cmGeneratorExpressionNode { LowerCaseNode() {} @@ -1897,6 +1931,7 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode( nodeMap["TARGET_OBJECTS"] = &targetObjectsNode; nodeMap["TARGET_POLICY"] = &targetPolicyNode; nodeMap["TARGET_EXISTS"] = &targetExistsNode; + nodeMap["TARGET_NAME_IF_EXISTS"] = &targetNameIfExistsNode; nodeMap["BUILD_INTERFACE"] = &buildInterfaceNode; nodeMap["INSTALL_INTERFACE"] = &installInterfaceNode; nodeMap["INSTALL_PREFIX"] = &installPrefixNode; |