summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorDavid Cole <david.cole@kitware.com>2012-08-20 19:38:42 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2012-08-20 19:38:42 (GMT)
commit3574bb484209f3becbb78d1cd3a97ed480d361e2 (patch)
tree87b137f5b631fecf33096dcedbad54557558f824 /Source
parent5cf828c028daa6f6f22ba2ce4a480a7714eda4cf (diff)
parent9d9f616792ee07a460af9f0a6dc036d81b852e66 (diff)
downloadCMake-3574bb484209f3becbb78d1cd3a97ed480d361e2.zip
CMake-3574bb484209f3becbb78d1cd3a97ed480d361e2.tar.gz
CMake-3574bb484209f3becbb78d1cd3a97ed480d361e2.tar.bz2
Merge topic 'generator-expression-conditions'
9d9f616 Add $<CONFIG:...> boolean query generator expression ebf05ab Add boolean generator expressions
Diffstat (limited to 'Source')
-rw-r--r--Source/cmDocumentGeneratorExpressions.h11
-rw-r--r--Source/cmGeneratorExpression.cxx55
-rw-r--r--Source/cmGeneratorExpression.h1
3 files changed, 66 insertions, 1 deletions
diff --git a/Source/cmDocumentGeneratorExpressions.h b/Source/cmDocumentGeneratorExpressions.h
index 5359013..74c673a 100644
--- a/Source/cmDocumentGeneratorExpressions.h
+++ b/Source/cmDocumentGeneratorExpressions.h
@@ -16,6 +16,9 @@
"Generator expressions are evaluted during build system generation " \
"to produce information specific to each build configuration. " \
"Valid expressions are:\n" \
+ " $<0:...> = empty string (ignores \"...\")\n" \
+ " $<1:...> = content of \"...\"\n" \
+ " $<CONFIG:cfg> = '1' if config is \"cfg\", else '0'\n" \
" $<CONFIGURATION> = configuration name\n" \
" $<TARGET_FILE:tgt> = main file (.exe, .so.1.2, .a)\n" \
" $<TARGET_LINKER_FILE:tgt> = file used to link (.a, .lib, .so)\n" \
@@ -25,6 +28,12 @@
"versions can produce the directory and file name components:\n" \
" $<TARGET_FILE_DIR:tgt>/$<TARGET_FILE_NAME:tgt>\n" \
" $<TARGET_LINKER_FILE_DIR:tgt>/$<TARGET_LINKER_FILE_NAME:tgt>\n" \
- " $<TARGET_SONAME_FILE_DIR:tgt>/$<TARGET_SONAME_FILE_NAME:tgt>\n"
+ " $<TARGET_SONAME_FILE_DIR:tgt>/$<TARGET_SONAME_FILE_NAME:tgt>\n" \
+ "Boolean expressions:\n" \
+ " $<AND:?[,?]...> = '1' if all '?' are '1', else '0'\n" \
+ " $<OR:?[,?]...> = '0' if all '?' are '0', else '1'\n" \
+ " $<NOT:?> = '0' if '?' is '1', else '1'\n" \
+ "where '?' is always either '0' or '1'.\n" \
+ ""
#endif
diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx
index f88ab0b..92bbf1d 100644
--- a/Source/cmGeneratorExpression.cxx
+++ b/Source/cmGeneratorExpression.cxx
@@ -14,6 +14,8 @@
#include "cmMakefile.h"
#include "cmTarget.h"
+#include <cmsys/String.h>
+
//----------------------------------------------------------------------------
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("^\\$<CONFIG:([A-Za-z0-9_]*)>$");
}
//----------------------------------------------------------------------------
@@ -103,6 +106,26 @@ bool cmGeneratorExpression::Evaluate()
}
//----------------------------------------------------------------------------
+static bool cmGeneratorExpressionBool(const char* c, std::string& result,
+ const char* name,
+ const char* a, const char* b)
+{
+ result = a;
+ while((c[0] == '0' || c[0] == '1') && (c[1] == ',' || c[1] == '>'))
+ {
+ if(c[0] == b[0]) { result = b; }
+ c += 2;
+ }
+ if(c[0])
+ {
+ result = name;
+ result += " requires one or more comma-separated '0' or '1' values.";
+ return false;
+ }
+ return true;
+}
+
+//----------------------------------------------------------------------------
bool cmGeneratorExpression::Evaluate(const char* expr, std::string& result)
{
if(this->TargetInfo.find(expr))
@@ -116,6 +139,38 @@ bool cmGeneratorExpression::Evaluate(const char* expr, std::string& result)
{
result = this->Config? this->Config : "";
}
+ else if(strncmp(expr, "$<0:",4) == 0)
+ {
+ result = "";
+ }
+ else if(strncmp(expr, "$<1:",4) == 0)
+ {
+ result = std::string(expr+4, strlen(expr)-5);
+ }
+ else if(strncmp(expr, "$<NOT:",6) == 0)
+ {
+ const char* c = expr+6;
+ if((c[0] != '0' && c[0] != '1') || c[1] != '>' || c[2])
+ {
+ result = "NOT requires exactly one '0' or '1' value.";
+ return false;
+ }
+ result = c[0] == '1'? "0" : "1";
+ }
+ else if(strncmp(expr, "$<AND:",6) == 0)
+ {
+ return cmGeneratorExpressionBool(expr+6, result, "AND", "1", "0");
+ }
+ else if(strncmp(expr, "$<OR:",5) == 0)
+ {
+ 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<char> Data;
std::stack<size_t> Barriers;
cmsys::RegularExpression TargetInfo;
+ cmsys::RegularExpression TestConfig;
std::set<cmTarget*> Targets;
bool Evaluate();
bool Evaluate(const char* expr, std::string& result);