summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2012-09-12 02:20:42 (GMT)
committerBrad King <brad.king@kitware.com>2012-09-28 12:49:21 (GMT)
commite028381bf1c5d1fdf464ed835a549be4a0569adb (patch)
tree4ef5222eba72b5eb1be25b392a3725271bb78644
parentb8e61d687abfacf1d5ed3b10cfe20315a344620c (diff)
downloadCMake-e028381bf1c5d1fdf464ed835a549be4a0569adb.zip
CMake-e028381bf1c5d1fdf464ed835a549be4a0569adb.tar.gz
CMake-e028381bf1c5d1fdf464ed835a549be4a0569adb.tar.bz2
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.
-rw-r--r--Source/cmDocumentGeneratorExpressions.h6
-rw-r--r--Source/cmGeneratorExpressionEvaluator.cxx68
-rw-r--r--Tests/GeneratorExpression/CMakeLists.txt17
-rw-r--r--Tests/GeneratorExpression/check.cmake17
4 files changed, 108 insertions, 0 deletions
diff --git a/Source/cmDocumentGeneratorExpressions.h b/Source/cmDocumentGeneratorExpressions.h
index 74c673a..5622da0 100644
--- a/Source/cmDocumentGeneratorExpressions.h
+++ b/Source/cmDocumentGeneratorExpressions.h
@@ -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" \
diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx
index acc844a..8573273 100644
--- a/Source/cmGeneratorExpressionEvaluator.cxx
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -138,6 +138,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
{
ConfigurationNode() {}
@@ -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;
}
diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt
index 2b135dc..79a8abb 100644
--- a/Tests/GeneratorExpression/CMakeLists.txt
+++ b/Tests/GeneratorExpression/CMakeLists.txt
@@ -22,6 +22,23 @@ add_custom_target(check ALL
-Dtest_or_1=$<OR:1>
-Dtest_or_1_0=$<OR:1,0>
-Dtest_or_1_1=$<OR:1,1>
+ -Dtest_bool_notfound=$<BOOL:NOTFOUND>
+ -Dtest_bool_foo_notfound=$<BOOL:Foo-NOTFOUND>
+ -Dtest_bool_true=$<BOOL:True>
+ -Dtest_bool_false=$<BOOL:False>
+ -Dtest_bool_on=$<BOOL:On>
+ -Dtest_bool_off=$<BOOL:Off>
+ -Dtest_bool_no=$<BOOL:No>
+ -Dtest_bool_n=$<BOOL:N>
+ -Dtest_strequal_yes_yes=$<STREQUAL:Yes,Yes>
+ -Dtest_strequal_yes_yes_cs=$<STREQUAL:Yes,yes>
+ -Dtest_strequal_yes_no=$<STREQUAL:Yes,No>
+ -Dtest_strequal_no_yes=$<STREQUAL:No,Yes>
+ -Dtest_strequal_angle_r=$<STREQUAL:$<ANGLE-R>,$<ANGLE-R>>
+ -Dtest_strequal_comma=$<STREQUAL:$<COMMA>,$<COMMA>>
+ -Dtest_strequal_angle_r_comma=$<STREQUAL:$<ANGLE-R>,$<COMMA>>
+ -Dtest_angle_r=$<ANGLE-R>
+ -Dtest_comma=$<COMMA>
-P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake
COMMAND ${CMAKE_COMMAND} -E echo "check done"
VERBATIM
diff --git a/Tests/GeneratorExpression/check.cmake b/Tests/GeneratorExpression/check.cmake
index e243d85..6fb87a2 100644
--- a/Tests/GeneratorExpression/check.cmake
+++ b/Tests/GeneratorExpression/check.cmake
@@ -23,3 +23,20 @@ check(test_or_0_1 "1")
check(test_or_1 "1")
check(test_or_1_0 "1")
check(test_or_1_1 "1")
+check(test_bool_notfound "0")
+check(test_bool_foo_notfound "0")
+check(test_bool_true "1")
+check(test_bool_false "0")
+check(test_bool_on "1")
+check(test_bool_off "0")
+check(test_bool_no "0")
+check(test_bool_n "0")
+check(test_strequal_yes_yes "1")
+check(test_strequal_yes_yes_cs "0")
+check(test_strequal_yes_no "0")
+check(test_strequal_no_yes "0")
+check(test_strequal_angle_r "1")
+check(test_strequal_comma "1")
+check(test_strequal_angle_r_comma "0")
+check(test_angle_r ">")
+check(test_comma ",")