From 9d9f616792ee07a460af9f0a6dc036d81b852e66 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 13 Aug 2012 10:00:32 -0400 Subject: Add $ boolean query generator expression This expression evaluates to '1' or '0' to indicate whether the build configuration for which the expression is evaluated matches tha named configuration. In combination with the "$<0:...>" and "$<1:...>" expressions this allows per-configuration content to be generated. --- Source/cmDocumentGeneratorExpressions.h | 1 + Source/cmGeneratorExpression.cxx | 9 +++++++++ Source/cmGeneratorExpression.h | 1 + Tests/GeneratorExpression/CMakeLists.txt | 2 ++ Tests/GeneratorExpression/check.cmake | 2 ++ Tests/RunCMake/GeneratorExpression/BadCONFIG-result.txt | 1 + Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt | 8 ++++++++ Tests/RunCMake/GeneratorExpression/BadCONFIG.cmake | 3 +++ Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake | 1 + 9 files changed, 28 insertions(+) create mode 100644 Tests/RunCMake/GeneratorExpression/BadCONFIG-result.txt create mode 100644 Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt create mode 100644 Tests/RunCMake/GeneratorExpression/BadCONFIG.cmake diff --git a/Source/cmDocumentGeneratorExpressions.h b/Source/cmDocumentGeneratorExpressions.h index 5d6553d..74c673a 100644 --- a/Source/cmDocumentGeneratorExpressions.h +++ b/Source/cmDocumentGeneratorExpressions.h @@ -18,6 +18,7 @@ "Valid expressions are:\n" \ " $<0:...> = empty string (ignores \"...\")\n" \ " $<1:...> = content of \"...\"\n" \ + " $ = '1' if config is \"cfg\", else '0'\n" \ " $ = configuration name\n" \ " $ = main file (.exe, .so.1.2, .a)\n" \ " $ = file used to link (.a, .lib, .so)\n" \ diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index ed33c7e..92bbf1d 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -14,6 +14,8 @@ #include "cmMakefile.h" #include "cmTarget.h" +#include + //---------------------------------------------------------------------------- cmGeneratorExpression::cmGeneratorExpression( cmMakefile* mf, const char* config, @@ -25,6 +27,7 @@ cmGeneratorExpression::cmGeneratorExpression( "_FILE(|_NAME|_DIR):" // Filename component. "([A-Za-z0-9_.-]+)" // Target name. ">$"); + this->TestConfig.compile("^\\$$"); } //---------------------------------------------------------------------------- @@ -162,6 +165,12 @@ bool cmGeneratorExpression::Evaluate(const char* expr, std::string& result) { return cmGeneratorExpressionBool(expr+5, result, "OR", "0", "1"); } + else if(this->TestConfig.find(expr)) + { + result = cmsysString_strcasecmp(this->TestConfig.match(1).c_str(), + this->Config? this->Config:"") == 0 + ? "1":"0"; + } else { result = "Expression syntax not recognized."; diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index 1a9d4c6..a023eb0 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -51,6 +51,7 @@ private: std::vector Data; std::stack Barriers; cmsys::RegularExpression TargetInfo; + cmsys::RegularExpression TestConfig; std::set Targets; bool Evaluate(); bool Evaluate(const char* expr, std::string& result); diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt index 8d7d87d..2b135dc 100644 --- a/Tests/GeneratorExpression/CMakeLists.txt +++ b/Tests/GeneratorExpression/CMakeLists.txt @@ -12,6 +12,8 @@ add_custom_target(check ALL -Dtest_and_1=$ -Dtest_and_1_0=$ -Dtest_and_1_1=$ + -Dtest_config_0=$x> + -Dtest_config_1=$> -Dtest_not_0=$ -Dtest_not_1=$ -Dtest_or_0=$ diff --git a/Tests/GeneratorExpression/check.cmake b/Tests/GeneratorExpression/check.cmake index c40b847..e243d85 100644 --- a/Tests/GeneratorExpression/check.cmake +++ b/Tests/GeneratorExpression/check.cmake @@ -13,6 +13,8 @@ check(test_and_0_1 "0") check(test_and_1 "1") check(test_and_1_0 "0") check(test_and_1_1 "1") +check(test_config_0 "0") +check(test_config_1 "1") check(test_not_0 "1") check(test_not_1 "0") check(test_or_0 "0") diff --git a/Tests/RunCMake/GeneratorExpression/BadCONFIG-result.txt b/Tests/RunCMake/GeneratorExpression/BadCONFIG-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/BadCONFIG-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt new file mode 100644 index 0000000..7c86b25 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at BadCONFIG.cmake:1 \(add_custom_target\): + Error evaluating generator expression: + + \$ + + Expression syntax not recognized. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/GeneratorExpression/BadCONFIG.cmake b/Tests/RunCMake/GeneratorExpression/BadCONFIG.cmake new file mode 100644 index 0000000..0c13f89 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/BadCONFIG.cmake @@ -0,0 +1,3 @@ +add_custom_target(check ALL COMMAND check + $ + VERBATIM) diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake index 95b16b3..ed18f25 100644 --- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake @@ -1,5 +1,6 @@ include(RunCMake) +run_cmake(BadCONFIG) run_cmake(BadOR) run_cmake(BadAND) run_cmake(BadNOT) -- cgit v0.12