summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-08-13 13:49:53 (GMT)
committerBrad King <brad.king@kitware.com>2012-08-15 15:44:49 (GMT)
commitebf05abda15967f8f50dcf132f7bf84472ca6337 (patch)
tree8f519862ee05d0f2b7d2ef34cfb281841a673461 /Source
parentcd3bd23266a4a6c00595134a17a8bdaea9e28af5 (diff)
downloadCMake-ebf05abda15967f8f50dcf132f7bf84472ca6337.zip
CMake-ebf05abda15967f8f50dcf132f7bf84472ca6337.tar.gz
CMake-ebf05abda15967f8f50dcf132f7bf84472ca6337.tar.bz2
Add boolean generator expressions
Add generator expressions that combine and use boolean test results: $<0:...> = empty string (ignores "...") $<1:...> = content of "..." $<AND:?[,?]...> = '1' if all '?' are '1', else '0' $<OR:?[,?]...> = '0' if all '?' are '0', else '1' $<NOT:?> = '0' if '?' is '1', else '1' These will be useful to evaluate (future) boolean query expressions and condition content on the results. Include tests and documentation.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmDocumentGeneratorExpressions.h10
-rw-r--r--Source/cmGeneratorExpression.cxx46
2 files changed, 55 insertions, 1 deletions
diff --git a/Source/cmDocumentGeneratorExpressions.h b/Source/cmDocumentGeneratorExpressions.h
index 5359013..5d6553d 100644
--- a/Source/cmDocumentGeneratorExpressions.h
+++ b/Source/cmDocumentGeneratorExpressions.h
@@ -16,6 +16,8 @@
"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" \
" $<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 +27,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..ed33c7e 100644
--- a/Source/cmGeneratorExpression.cxx
+++ b/Source/cmGeneratorExpression.cxx
@@ -103,6 +103,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 +136,32 @@ 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
{
result = "Expression syntax not recognized.";