Add $<CONFIG:...> 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.
This commit is contained in:
Brad King 2012-08-13 10:00:32 -04:00
parent ebf05abda1
commit 9d9f616792
9 changed files with 28 additions and 0 deletions

View File

@ -18,6 +18,7 @@
"Valid expressions are:\n" \ "Valid expressions are:\n" \
" $<0:...> = empty string (ignores \"...\")\n" \ " $<0:...> = empty string (ignores \"...\")\n" \
" $<1:...> = content of \"...\"\n" \ " $<1:...> = content of \"...\"\n" \
" $<CONFIG:cfg> = '1' if config is \"cfg\", else '0'\n" \
" $<CONFIGURATION> = configuration name\n" \ " $<CONFIGURATION> = configuration name\n" \
" $<TARGET_FILE:tgt> = main file (.exe, .so.1.2, .a)\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_LINKER_FILE:tgt> = file used to link (.a, .lib, .so)\n" \

View File

@ -14,6 +14,8 @@
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmTarget.h" #include "cmTarget.h"
#include <cmsys/String.h>
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmGeneratorExpression::cmGeneratorExpression( cmGeneratorExpression::cmGeneratorExpression(
cmMakefile* mf, const char* config, cmMakefile* mf, const char* config,
@ -25,6 +27,7 @@ cmGeneratorExpression::cmGeneratorExpression(
"_FILE(|_NAME|_DIR):" // Filename component. "_FILE(|_NAME|_DIR):" // Filename component.
"([A-Za-z0-9_.-]+)" // Target name. "([A-Za-z0-9_.-]+)" // Target name.
">$"); ">$");
this->TestConfig.compile("^\\$<CONFIG:([A-Za-z0-9_]*)>$");
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -162,6 +165,12 @@ bool cmGeneratorExpression::Evaluate(const char* expr, std::string& result)
{ {
return cmGeneratorExpressionBool(expr+5, result, "OR", "0", "1"); 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 else
{ {
result = "Expression syntax not recognized."; result = "Expression syntax not recognized.";

View File

@ -51,6 +51,7 @@ private:
std::vector<char> Data; std::vector<char> Data;
std::stack<size_t> Barriers; std::stack<size_t> Barriers;
cmsys::RegularExpression TargetInfo; cmsys::RegularExpression TargetInfo;
cmsys::RegularExpression TestConfig;
std::set<cmTarget*> Targets; std::set<cmTarget*> Targets;
bool Evaluate(); bool Evaluate();
bool Evaluate(const char* expr, std::string& result); bool Evaluate(const char* expr, std::string& result);

View File

@ -12,6 +12,8 @@ add_custom_target(check ALL
-Dtest_and_1=$<AND:1> -Dtest_and_1=$<AND:1>
-Dtest_and_1_0=$<AND:1,0> -Dtest_and_1_0=$<AND:1,0>
-Dtest_and_1_1=$<AND:1,1> -Dtest_and_1_1=$<AND:1,1>
-Dtest_config_0=$<CONFIG:$<CONFIGURATION>x>
-Dtest_config_1=$<CONFIG:$<CONFIGURATION>>
-Dtest_not_0=$<NOT:0> -Dtest_not_0=$<NOT:0>
-Dtest_not_1=$<NOT:1> -Dtest_not_1=$<NOT:1>
-Dtest_or_0=$<OR:0> -Dtest_or_0=$<OR:0>

View File

@ -13,6 +13,8 @@ check(test_and_0_1 "0")
check(test_and_1 "1") check(test_and_1 "1")
check(test_and_1_0 "0") check(test_and_1_0 "0")
check(test_and_1_1 "1") check(test_and_1_1 "1")
check(test_config_0 "0")
check(test_config_1 "1")
check(test_not_0 "1") check(test_not_0 "1")
check(test_not_1 "0") check(test_not_1 "0")
check(test_or_0 "0") check(test_or_0 "0")

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,8 @@
CMake Error at BadCONFIG.cmake:1 \(add_custom_target\):
Error evaluating generator expression:
\$<CONFIG:.>
Expression syntax not recognized.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)$

View File

@ -0,0 +1,3 @@
add_custom_target(check ALL COMMAND check
$<CONFIG:.>
VERBATIM)

View File

@ -1,5 +1,6 @@
include(RunCMake) include(RunCMake)
run_cmake(BadCONFIG)
run_cmake(BadOR) run_cmake(BadOR)
run_cmake(BadAND) run_cmake(BadAND)
run_cmake(BadNOT) run_cmake(BadNOT)