diff options
author | Brad King <brad.king@kitware.com> | 2019-06-04 12:32:11 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-06-04 12:32:19 (GMT) |
commit | 4b68baa776bf8ccc2911057fc79b558515438900 (patch) | |
tree | f82f327d1e6e06e2e3cc7241aef4d783cb7b5299 /Source | |
parent | d4108f5585ae4e0ab79c9b192f9d6a0614f868cd (diff) | |
parent | 162555d7ecd510a84fb26a2ebc90f0a3e9eabc1a (diff) | |
download | CMake-4b68baa776bf8ccc2911057fc79b558515438900.zip CMake-4b68baa776bf8ccc2911057fc79b558515438900.tar.gz CMake-4b68baa776bf8ccc2911057fc79b558515438900.tar.bz2 |
Merge topic 'compiler_id_gen_exp_supports_multiple_ids'
162555d7ec Help: Add release notes for updated generator expressions
808b818063 Genex: CompileLang and CompileLangAndId now match against a list of ids
9fd602bfd3 Genex: PlatformId now can match against a list of ids.
ec66af2026 Genex: CompilerId now can match against a list of ids.
2d4787fc4d Genex: Add more extensive support for an unbounded number of parameters
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3405
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratorExpressionEvaluator.cxx | 10 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 76 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionNode.h | 4 |
3 files changed, 54 insertions, 36 deletions
diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 268de6f..7442018 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -166,9 +166,13 @@ std::string GeneratorExpressionContent::EvaluateParameters( reportError(context, this->GetOriginalExpression(), "$<" + identifier + "> expression requires at least one parameter."); - } - if (numExpected == cmGeneratorExpressionNode::OneOrZeroParameters && - parameters.size() > 1) { + } else if (numExpected == cmGeneratorExpressionNode::TwoOrMoreParameters && + parameters.size() < 2) { + reportError(context, this->GetOriginalExpression(), + "$<" + identifier + + "> expression requires at least two parameters."); + } else if (numExpected == cmGeneratorExpressionNode::OneOrZeroParameters && + parameters.size() > 1) { reportError(context, this->GetOriginalExpression(), "$<" + identifier + "> expression requires one or zero parameters."); diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 68ef170..a60c75c 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -632,7 +632,7 @@ struct CompilerIdNode : public cmGeneratorExpressionNode { } - int NumExpectedParameters() const override { return OneOrZeroParameters; } + int NumExpectedParameters() const override { return ZeroOrMoreParameters; } std::string Evaluate( const std::vector<std::string>& parameters, @@ -664,36 +664,39 @@ struct CompilerIdNode : public cmGeneratorExpressionNode if (parameters.empty()) { return compilerId; } - static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$"); - if (!compilerIdValidator.find(parameters.front())) { - reportError(context, content->GetOriginalExpression(), - "Expression syntax not recognized."); - return std::string(); - } if (compilerId.empty()) { return parameters.front().empty() ? "1" : "0"; } + static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$"); - if (strcmp(parameters.front().c_str(), compilerId.c_str()) == 0) { - return "1"; - } + for (auto& param : parameters) { - if (cmsysString_strcasecmp(parameters.front().c_str(), - compilerId.c_str()) == 0) { - switch (context->LG->GetPolicyStatus(cmPolicies::CMP0044)) { - case cmPolicies::WARN: { - std::ostringstream e; - e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0044); - context->LG->GetCMakeInstance()->IssueMessage( - MessageType::AUTHOR_WARNING, e.str(), context->Backtrace); - CM_FALLTHROUGH; + if (!compilerIdValidator.find(param)) { + reportError(context, content->GetOriginalExpression(), + "Expression syntax not recognized."); + return std::string(); + } + + if (strcmp(param.c_str(), compilerId.c_str()) == 0) { + return "1"; + } + + if (cmsysString_strcasecmp(param.c_str(), compilerId.c_str()) == 0) { + switch (context->LG->GetPolicyStatus(cmPolicies::CMP0044)) { + case cmPolicies::WARN: { + std::ostringstream e; + e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0044); + context->LG->GetCMakeInstance()->IssueMessage( + MessageType::AUTHOR_WARNING, e.str(), context->Backtrace); + CM_FALLTHROUGH; + } + case cmPolicies::OLD: + return "1"; + case cmPolicies::NEW: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + break; } - case cmPolicies::OLD: - return "1"; - case cmPolicies::NEW: - case cmPolicies::REQUIRED_ALWAYS: - case cmPolicies::REQUIRED_IF_USED: - break; } } return "0"; @@ -773,7 +776,7 @@ struct PlatformIdNode : public cmGeneratorExpressionNode { PlatformIdNode() {} // NOLINT(modernize-use-equals-default) - int NumExpectedParameters() const override { return OneOrZeroParameters; } + int NumExpectedParameters() const override { return ZeroOrMoreParameters; } std::string Evaluate( const std::vector<std::string>& parameters, @@ -791,8 +794,10 @@ struct PlatformIdNode : public cmGeneratorExpressionNode return parameters.front().empty() ? "1" : "0"; } - if (parameters.front() == platformId) { - return "1"; + for (auto& param : parameters) { + if (param == platformId) { + return "1"; + } } return "0"; } @@ -946,7 +951,7 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode { CompileLanguageNode() {} // NOLINT(modernize-use-equals-default) - int NumExpectedParameters() const override { return OneOrZeroParameters; } + int NumExpectedParameters() const override { return ZeroOrMoreParameters; } std::string Evaluate( const std::vector<std::string>& parameters, @@ -977,7 +982,13 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode if (parameters.empty()) { return context->Language; } - return context->Language == parameters.front() ? "1" : "0"; + + for (auto& param : parameters) { + if (context->Language == param) { + return "1"; + } + } + return "0"; } } languageNode; @@ -985,7 +996,7 @@ static const struct CompileLanguageAndIdNode : public cmGeneratorExpressionNode { CompileLanguageAndIdNode() {} // NOLINT(modernize-use-equals-default) - int NumExpectedParameters() const override { return 2; } + int NumExpectedParameters() const override { return TwoOrMoreParameters; } std::string Evaluate( const std::vector<std::string>& parameters, @@ -1018,7 +1029,8 @@ static const struct CompileLanguageAndIdNode : public cmGeneratorExpressionNode const std::string& lang = context->Language; if (lang == parameters.front()) { - std::vector<std::string> idParameter = { parameters[1] }; + std::vector<std::string> idParameter((parameters.cbegin() + 1), + parameters.cend()); return CompilerIdNode{ lang.c_str() }.EvaluateWithLanguage( idParameter, context, content, dagChecker, lang); } diff --git a/Source/cmGeneratorExpressionNode.h b/Source/cmGeneratorExpressionNode.h index 3dbfc6e..7a36924 100644 --- a/Source/cmGeneratorExpressionNode.h +++ b/Source/cmGeneratorExpressionNode.h @@ -20,7 +20,9 @@ struct cmGeneratorExpressionNode { DynamicParameters = 0, OneOrMoreParameters = -1, - OneOrZeroParameters = -2 + TwoOrMoreParameters = -2, + ZeroOrMoreParameters = -3, + OneOrZeroParameters = -4 }; virtual ~cmGeneratorExpressionNode() = default; |