Browse Source

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.
Stephen Kelly 12 years ago
parent
commit
3917d86b26

+ 2 - 0
Help/manual/cmake-generator-expressions.7.rst

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

+ 6 - 2
Source/cmGeneratorExpressionEvaluator.cxx

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

+ 1 - 0
Tests/GeneratorExpression/CMakeLists.txt

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

+ 1 - 0
Tests/GeneratorExpression/check-part1.cmake

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

+ 1 - 10
Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt

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

+ 0 - 1
Tests/RunCMake/GeneratorExpression/BadCONFIG.cmake

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