diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index c60900034..102927edb 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -66,6 +66,8 @@ static const struct ZeroNode : public cmGeneratorExpressionNode virtual bool GeneratesContent() const { return false; } + virtual bool AcceptsSingleArbitraryContentParameter() const { return true; } + std::string Evaluate(const std::vector &, cmGeneratorExpressionContext *, const GeneratorExpressionContent *, @@ -642,6 +644,20 @@ std::string GeneratorExpressionContent::Evaluate( if (!node->GeneratesContent()) { + if (node->AcceptsSingleArbitraryContentParameter()) + { + if (this->ParamChildren.empty()) + { + reportError(context, this->GetOriginalExpression(), + "$<" + identifier + "> expression requires a parameter."); + } + } + else + { + std::vector parameters; + this->EvaluateParameters(node, identifier, context, dagChecker, + parameters); + } return std::string(); } @@ -677,6 +693,23 @@ std::string GeneratorExpressionContent::Evaluate( } std::vector parameters; + this->EvaluateParameters(node, identifier, context, dagChecker, parameters); + if (context->HadError) + { + return std::string(); + } + + return node->Evaluate(parameters, context, this, dagChecker); +} + +//---------------------------------------------------------------------------- +std::string GeneratorExpressionContent::EvaluateParameters( + const cmGeneratorExpressionNode *node, + const std::string &identifier, + cmGeneratorExpressionContext *context, + cmGeneratorExpressionDAGChecker *dagChecker, + std::vector ¶meters) const +{ { std::vector >::const_iterator pit = this->ParamChildren.begin(); @@ -732,10 +765,8 @@ std::string GeneratorExpressionContent::Evaluate( { reportError(context, this->GetOriginalExpression(), "$<" + identifier + "> expression requires at least one parameter."); - return std::string(); } - - return node->Evaluate(parameters, context, this, dagChecker); + return std::string(); } //---------------------------------------------------------------------------- diff --git a/Source/cmGeneratorExpressionEvaluator.h b/Source/cmGeneratorExpressionEvaluator.h index d37337ef5..d904b027f 100644 --- a/Source/cmGeneratorExpressionEvaluator.h +++ b/Source/cmGeneratorExpressionEvaluator.h @@ -32,6 +32,7 @@ struct cmGeneratorExpressionContext }; struct cmGeneratorExpressionDAGChecker; +struct cmGeneratorExpressionNode; //---------------------------------------------------------------------------- struct cmGeneratorExpressionEvaluator @@ -116,6 +117,13 @@ struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator ~GeneratorExpressionContent(); +private: + std::string EvaluateParameters(const cmGeneratorExpressionNode *node, + const std::string &identifier, + cmGeneratorExpressionContext *context, + cmGeneratorExpressionDAGChecker *dagChecker, + std::vector ¶meters) const; + private: std::vector IdentifierChildren; std::vector > ParamChildren; diff --git a/Source/cmGeneratorExpressionParser.cxx b/Source/cmGeneratorExpressionParser.cxx index 7a8fc510d..a619cecd0 100644 --- a/Source/cmGeneratorExpressionParser.cxx +++ b/Source/cmGeneratorExpressionParser.cxx @@ -88,7 +88,15 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression( while(this->it->TokenType != cmGeneratorExpressionToken::EndExpression && this->it->TokenType != cmGeneratorExpressionToken::ColonSeparator) { - this->ParseContent(identifier); + if (this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator) + { + extendText(identifier, this->it); + ++this->it; + } + else + { + this->ParseContent(identifier); + } if (this->it == this->Tokens.end()) { break; diff --git a/Tests/RunCMake/GeneratorExpression/BadZero-result.txt b/Tests/RunCMake/GeneratorExpression/BadZero-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/BadZero-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/BadZero-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadZero-stderr.txt new file mode 100644 index 000000000..40db4ae88 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/BadZero-stderr.txt @@ -0,0 +1,17 @@ +CMake Error at BadZero.cmake:2 \(add_custom_target\): + Error evaluating generator expression: + + \$<0> + + \$<0> expression requires a parameter. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) ++ +CMake Error at BadZero.cmake:2 \(add_custom_target\): + Error evaluating generator expression: + + \$<0,> + + Expression did not evaluate to a known generator expression +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/BadZero.cmake b/Tests/RunCMake/GeneratorExpression/BadZero.cmake new file mode 100644 index 000000000..559a9fa3d --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/BadZero.cmake @@ -0,0 +1,5 @@ + +add_custom_target(check ALL COMMAND check + $<0> + $<0,> + VERBATIM) diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake index 18a47ae00..992ba792f 100644 --- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake @@ -5,3 +5,4 @@ run_cmake(BadOR) run_cmake(BadAND) run_cmake(BadNOT) run_cmake(BadStrEqual) +run_cmake(BadZero)