diff options
author | Colby Pike <vectorofbool@gmail.com> | 2017-01-24 03:14:03 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-01-26 16:18:50 (GMT) |
commit | 895f7f16a79428689a263ba5cd9a72647dc8e912 (patch) | |
tree | 6c3ba32ffb5b9cbfedaf7e61ce45d63b94057c04 /Source/cmGeneratorExpressionNode.cxx | |
parent | 8ea12a8b80c4c3153cc602f1d0735b3db8581ae8 (diff) | |
download | CMake-895f7f16a79428689a263ba5cd9a72647dc8e912.zip CMake-895f7f16a79428689a263ba5cd9a72647dc8e912.tar.gz CMake-895f7f16a79428689a263ba5cd9a72647dc8e912.tar.bz2 |
Genex: Add `IF` generator expression
This allows a single condition to be used to choose between two
alternatives. Without this the condition must be duplicated with
one surrounded by `NOT`.
Closes: #15585
Diffstat (limited to 'Source/cmGeneratorExpressionNode.cxx')
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 398f95b..66202df 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -162,6 +162,27 @@ static const struct BoolNode : public cmGeneratorExpressionNode } } boolNode; +static const struct IfNode : public cmGeneratorExpressionNode +{ + IfNode() {} + + int NumExpectedParameters() const CM_OVERRIDE { return 3; } + + std::string Evaluate(const std::vector<std::string>& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker*) const CM_OVERRIDE + { + if (parameters[0] != "1" && parameters[0] != "0") { + reportError(context, content->GetOriginalExpression(), + "First parameter to $<IF> must resolve to exactly one '0' " + "or '1' value."); + return std::string(); + } + return parameters[0] == "1" ? parameters[1] : parameters[2]; + } +} ifNode; + static const struct StrEqualNode : public cmGeneratorExpressionNode { StrEqualNode() {} @@ -1757,6 +1778,7 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode( nodeMap["UPPER_CASE"] = &upperCaseNode; nodeMap["MAKE_C_IDENTIFIER"] = &makeCIdentifierNode; nodeMap["BOOL"] = &boolNode; + nodeMap["IF"] = &ifNode; nodeMap["ANGLE-R"] = &angle_rNode; nodeMap["COMMA"] = &commaNode; nodeMap["SEMICOLON"] = &semicolonNode; |