Extend the generator expression language with more logic.

Generator expressions for comparing strings, evaluating
strings as booleans, and for creating literal right-angle-brackets
and commas are added. Those may be needed in some cases
where they appear in literals.
This commit is contained in:
Stephen Kelly
2012-09-12 04:20:42 +02:00
committed by Brad King
parent b8e61d687a
commit e028381bf1
4 changed files with 108 additions and 0 deletions
+6
View File
@@ -20,6 +20,12 @@
" $<1:...> = content of \"...\"\n" \
" $<CONFIG:cfg> = '1' if config is \"cfg\", else '0'\n" \
" $<CONFIGURATION> = configuration name\n" \
" $<BOOL:...> = '1' if the '...' is true, else '0'\n" \
" $<STREQUAL:a,b> = '1' if a is STREQUAL b, else '0'\n" \
" $<ANGLE-R> = A literal '>'. Used to compare " \
"strings which contain a '>' for example.\n" \
" $<COMMA> = A literal ','. Used to compare " \
"strings which contain a ',' for example.\n" \
" $<TARGET_FILE:tgt> = main file (.exe, .so.1.2, .a)\n" \
" $<TARGET_LINKER_FILE:tgt> = file used to link (.a, .lib, .so)\n" \
" $<TARGET_SONAME_FILE:tgt> = file with soname (.so.3)\n" \
+68
View File
@@ -137,6 +137,66 @@ static const struct NotNode : public cmGeneratorExpressionNode
}
} notNode;
//----------------------------------------------------------------------------
static const struct BoolNode : public cmGeneratorExpressionNode
{
BoolNode() {}
virtual int NumExpectedParameters() const { return 1; }
std::string Evaluate(const std::vector<std::string> &parameters,
cmGeneratorExpressionContext *,
const GeneratorExpressionContent *) const
{
return !cmSystemTools::IsOff(parameters.begin()->c_str()) ? "1" : "0";
}
} boolNode;
//----------------------------------------------------------------------------
static const struct StrEqualNode : public cmGeneratorExpressionNode
{
StrEqualNode() {}
virtual int NumExpectedParameters() const { return 2; }
std::string Evaluate(const std::vector<std::string> &parameters,
cmGeneratorExpressionContext *,
const GeneratorExpressionContent *) const
{
return *parameters.begin() == parameters.at(1) ? "1" : "0";
}
} strEqualNode;
//----------------------------------------------------------------------------
static const struct Angle_RNode : public cmGeneratorExpressionNode
{
Angle_RNode() {}
virtual int NumExpectedParameters() const { return 0; }
std::string Evaluate(const std::vector<std::string> &,
cmGeneratorExpressionContext *,
const GeneratorExpressionContent *) const
{
return ">";
}
} angle_rNode;
//----------------------------------------------------------------------------
static const struct CommaNode : public cmGeneratorExpressionNode
{
CommaNode() {}
virtual int NumExpectedParameters() const { return 0; }
std::string Evaluate(const std::vector<std::string> &,
cmGeneratorExpressionContext *,
const GeneratorExpressionContent *) const
{
return ",";
}
} commaNode;
//----------------------------------------------------------------------------
static const struct ConfigurationNode : public cmGeneratorExpressionNode
{
@@ -392,6 +452,14 @@ cmGeneratorExpressionNode* GetNode(const std::string &identifier)
return &targetLinkerFileDirNode;
else if (identifier == "TARGET_SONAME_FILE_DIR")
return &targetSoNameFileDirNode;
else if (identifier == "STREQUAL")
return &strEqualNode;
else if (identifier == "BOOL")
return &boolNode;
else if (identifier == "ANGLE-R")
return &angle_rNode;
else if (identifier == "COMMA")
return &commaNode;
return 0;
}