Genex: Add a nullary form for CONFIG

This is consistent with other similar expressions such as PLATFORM_ID,
and makes the CONFIGURATION expression obsolete.

Fix an off-by-one error in
GeneratorExpressionContent::EvaluateParameters exposed by a unit test.

Remove the test for 'bad' nullary use of $<CONFIG>.

Add a unit test to verify that $<CONFIG> and $<CONFIGURATION> have
the same value.
This commit is contained in:
Stephen Kelly 2013-12-31 15:57:25 +01:00 committed by Brad King
parent 5169130539
commit 3917d86b26
6 changed files with 11 additions and 13 deletions

View File

@ -104,6 +104,8 @@ expands to ``OLD_COMPILER`` if the
than 4.2.0. than 4.2.0.
``$<CONFIGURATION>`` ``$<CONFIGURATION>``
Configuration name. Deprecated. Use ``CONFIG`` instead.
``$<CONFIG>``
Configuration name Configuration name
``$<PLATFORM_ID>`` ``$<PLATFORM_ID>``
The CMake-id of the platform The CMake-id of the platform

View File

@ -676,13 +676,17 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
{ {
ConfigurationTestNode() {} ConfigurationTestNode() {}
virtual int NumExpectedParameters() const { return 1; } virtual int NumExpectedParameters() const { return OneOrZeroParameters; }
std::string Evaluate(const std::vector<std::string> &parameters, std::string Evaluate(const std::vector<std::string> &parameters,
cmGeneratorExpressionContext *context, cmGeneratorExpressionContext *context,
const GeneratorExpressionContent *content, const GeneratorExpressionContent *content,
cmGeneratorExpressionDAGChecker *) const cmGeneratorExpressionDAGChecker *) const
{ {
if (parameters.empty())
{
return configurationNode.Evaluate(parameters, context, content, 0);
}
cmsys::RegularExpression configValidator; cmsys::RegularExpression configValidator;
configValidator.compile("^[A-Za-z0-9_]*$"); configValidator.compile("^[A-Za-z0-9_]*$");
if (!configValidator.find(parameters.begin()->c_str())) if (!configValidator.find(parameters.begin()->c_str()))
@ -1801,7 +1805,7 @@ std::string GeneratorExpressionContent::EvaluateParameters(
+ "> expression requires at least one parameter."); + "> expression requires at least one parameter.");
} }
if (numExpected == cmGeneratorExpressionNode::OneOrZeroParameters if (numExpected == cmGeneratorExpressionNode::OneOrZeroParameters
&& parameters.size() > 2) && parameters.size() > 1)
{ {
reportError(context, this->GetOriginalExpression(), "$<" + identifier reportError(context, this->GetOriginalExpression(), "$<" + identifier
+ "> expression requires one or zero parameters."); + "> expression requires one or zero parameters.");

View File

@ -13,6 +13,7 @@ add_custom_target(check-part1 ALL
-Dtest_1=$<1:content> -Dtest_1=$<1:content>
-Dtest_1_with_comma=$<1:-Wl,--no-undefined> -Dtest_1_with_comma=$<1:-Wl,--no-undefined>
-Dconfig=$<CONFIGURATION> -Dconfig=$<CONFIGURATION>
-Dshort_config=$<CONFIG>
-Dtest_and_0=$<AND:0> -Dtest_and_0=$<AND:0>
-Dtest_and_0_0=$<AND:0,0> -Dtest_and_0_0=$<AND:0,0>
-Dtest_and_0_1=$<AND:0,1> -Dtest_and_0_1=$<AND:0,1>

View File

@ -2,6 +2,7 @@
include(${CMAKE_CURRENT_LIST_DIR}/check-common.cmake) include(${CMAKE_CURRENT_LIST_DIR}/check-common.cmake)
message(STATUS "config=[${config}]") message(STATUS "config=[${config}]")
check(config "${short_config}")
check(test_0 "") check(test_0 "")
check(test_0_with_comma "") check(test_0_with_comma "")
check(test_1 "content") check(test_1 "content")

View File

@ -1,12 +1,3 @@
CMake Error at BadCONFIG.cmake:1 \(add_custom_target\):
Error evaluating generator expression:
\$<CONFIG>
\$<CONFIG> expression requires exactly one parameter.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
+
CMake Error at BadCONFIG.cmake:1 \(add_custom_target\): CMake Error at BadCONFIG.cmake:1 \(add_custom_target\):
Error evaluating generator expression: Error evaluating generator expression:
@ -21,7 +12,7 @@ CMake Error at BadCONFIG.cmake:1 \(add_custom_target\):
\$<CONFIG:Foo,Bar> \$<CONFIG:Foo,Bar>
\$<CONFIG> expression requires exactly one parameter. \$<CONFIG> expression requires one or zero parameters.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) CMakeLists.txt:3 \(include\)
+ +

View File

@ -1,5 +1,4 @@
add_custom_target(check ALL COMMAND check add_custom_target(check ALL COMMAND check
$<CONFIG>
$<CONFIG:.> $<CONFIG:.>
$<CONFIG:Foo,Bar> $<CONFIG:Foo,Bar>
$<CONFIG:Foo-Bar> $<CONFIG:Foo-Bar>