diff options
author | Leonid Pospelov <pospelovlm@yandex.ru> | 2019-04-15 00:56:02 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-04-22 14:41:28 (GMT) |
commit | 3f57787dffa629b7c10ca2a02229b7e1a4bfe1f9 (patch) | |
tree | a3d919a2da48396ad04754a92affafb22e0b99d9 /Source/cmGeneratorExpressionNode.cxx | |
parent | 20d7c5631e88d80cb683a5e120c0c1e1f077945a (diff) | |
download | CMake-3f57787dffa629b7c10ca2a02229b7e1a4bfe1f9.zip CMake-3f57787dffa629b7c10ca2a02229b7e1a4bfe1f9.tar.gz CMake-3f57787dffa629b7c10ca2a02229b7e1a4bfe1f9.tar.bz2 |
cmGeneratorExpressionNode: remove structs CompilerId*, CompilerVersion*
Diffstat (limited to 'Source/cmGeneratorExpressionNode.cxx')
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 209 |
1 files changed, 43 insertions, 166 deletions
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index a665974..5db46dd 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -621,10 +621,31 @@ static const CharacterNode<';'> semicolonNode; struct CompilerIdNode : public cmGeneratorExpressionNode { - CompilerIdNode() {} // NOLINT(modernize-use-equals-default) + CompilerIdNode(const char* compilerLang) + : CompilerLanguage(compilerLang) + { + } int NumExpectedParameters() const override { return OneOrZeroParameters; } + std::string Evaluate( + const std::vector<std::string>& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* dagChecker) const override + { + if (!context->HeadTarget) { + std::ostringstream e; + e << "$<" << this->CompilerLanguage + << "_COMPILER_ID> may only be used with binary targets. It may " + "not be used with add_custom_command or add_custom_target."; + reportError(context, content->GetOriginalExpression(), e.str()); + return {}; + } + return this->EvaluateWithLanguage(parameters, context, content, dagChecker, + this->CompilerLanguage); + } + std::string EvaluateWithLanguage(const std::vector<std::string>& parameters, cmGeneratorExpressionContext* context, const GeneratorExpressionContent* content, @@ -671,77 +692,21 @@ struct CompilerIdNode : public cmGeneratorExpressionNode } return "0"; } -}; - -static const struct CCompilerIdNode : public CompilerIdNode -{ - CCompilerIdNode() {} // NOLINT(modernize-use-equals-default) - std::string Evaluate( - const std::vector<std::string>& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const override - { - if (!context->HeadTarget) { - reportError( - context, content->GetOriginalExpression(), - "$<C_COMPILER_ID> may only be used with binary targets. It may " - "not be used with add_custom_command or add_custom_target."); - return std::string(); - } - return this->EvaluateWithLanguage(parameters, context, content, dagChecker, - "C"); - } -} cCompilerIdNode; - -static const struct CXXCompilerIdNode : public CompilerIdNode -{ - CXXCompilerIdNode() {} // NOLINT(modernize-use-equals-default) + const char* const CompilerLanguage; +}; - std::string Evaluate( - const std::vector<std::string>& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const override - { - if (!context->HeadTarget) { - reportError( - context, content->GetOriginalExpression(), - "$<CXX_COMPILER_ID> may only be used with binary targets. It may " - "not be used with add_custom_command or add_custom_target."); - return std::string(); - } - return this->EvaluateWithLanguage(parameters, context, content, dagChecker, - "CXX"); - } -} cxxCompilerIdNode; +static const CompilerIdNode cCompilerIdNode("C"), cxxCompilerIdNode("CXX"), + cudaCompilerIdNode("CUDA"), fortranCompilerIdNode("Fortran"); -static const struct CUDACompilerIdNode : public CompilerIdNode +struct CompilerVersionNode : public cmGeneratorExpressionNode { - CUDACompilerIdNode() {} // NOLINT(modernize-use-equals-default) - - std::string Evaluate( - const std::vector<std::string>& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const override + CompilerVersionNode(const char* compilerLang) + : CompilerLanguage(compilerLang) { - if (!context->HeadTarget) { - reportError( - context, content->GetOriginalExpression(), - "$<CUDA_COMPILER_ID> may only be used with binary targets. It may " - "not be used with add_custom_command or add_custom_target."); - return std::string(); - } - return this->EvaluateWithLanguage(parameters, context, content, dagChecker, - "CUDA"); } -} cudaCompilerIdNode; -static const struct FortranCompilerIdNode : public CompilerIdNode -{ - FortranCompilerIdNode() {} // NOLINT(modernize-use-equals-default) + int NumExpectedParameters() const override { return OneOrZeroParameters; } std::string Evaluate( const std::vector<std::string>& parameters, @@ -750,22 +715,16 @@ static const struct FortranCompilerIdNode : public CompilerIdNode cmGeneratorExpressionDAGChecker* dagChecker) const override { if (!context->HeadTarget) { - reportError( - context, content->GetOriginalExpression(), - "$<Fortran_COMPILER_ID> may only be used with binary targets. It may " - "not be used with add_custom_command or add_custom_target."); - return std::string(); + std::ostringstream e; + e << "$<" << this->CompilerLanguage + << "_COMPILER_VERSION> may only be used with binary targets. It " + "may not be used with add_custom_command or add_custom_target."; + reportError(context, content->GetOriginalExpression(), e.str()); + return {}; } return this->EvaluateWithLanguage(parameters, context, content, dagChecker, - "Fortran"); + this->CompilerLanguage); } -} fortranCompilerIdNode; - -struct CompilerVersionNode : public cmGeneratorExpressionNode -{ - CompilerVersionNode() {} // NOLINT(modernize-use-equals-default) - - int NumExpectedParameters() const override { return OneOrZeroParameters; } std::string EvaluateWithLanguage(const std::vector<std::string>& parameters, cmGeneratorExpressionContext* context, @@ -784,7 +743,7 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode if (!compilerIdValidator.find(parameters.front())) { reportError(context, content->GetOriginalExpression(), "Expression syntax not recognized."); - return std::string(); + return {}; } if (compilerVersion.empty()) { return parameters.front().empty() ? "1" : "0"; @@ -796,95 +755,13 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode ? "1" : "0"; } -}; -static const struct CCompilerVersionNode : public CompilerVersionNode -{ - CCompilerVersionNode() {} // NOLINT(modernize-use-equals-default) - - std::string Evaluate( - const std::vector<std::string>& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const override - { - if (!context->HeadTarget) { - reportError( - context, content->GetOriginalExpression(), - "$<C_COMPILER_VERSION> may only be used with binary targets. It " - "may not be used with add_custom_command or add_custom_target."); - return std::string(); - } - return this->EvaluateWithLanguage(parameters, context, content, dagChecker, - "C"); - } -} cCompilerVersionNode; - -static const struct CXXCompilerVersionNode : public CompilerVersionNode -{ - CXXCompilerVersionNode() {} // NOLINT(modernize-use-equals-default) - - std::string Evaluate( - const std::vector<std::string>& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const override - { - if (!context->HeadTarget) { - reportError( - context, content->GetOriginalExpression(), - "$<CXX_COMPILER_VERSION> may only be used with binary targets. It " - "may not be used with add_custom_command or add_custom_target."); - return std::string(); - } - return this->EvaluateWithLanguage(parameters, context, content, dagChecker, - "CXX"); - } -} cxxCompilerVersionNode; - -static const struct CUDACompilerVersionNode : public CompilerVersionNode -{ - CUDACompilerVersionNode() {} // NOLINT(modernize-use-equals-default) - - std::string Evaluate( - const std::vector<std::string>& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const override - { - if (!context->HeadTarget) { - reportError( - context, content->GetOriginalExpression(), - "$<CUDA_COMPILER_VERSION> may only be used with binary targets. It " - "may not be used with add_custom_command or add_custom_target."); - return std::string(); - } - return this->EvaluateWithLanguage(parameters, context, content, dagChecker, - "CUDA"); - } -} cudaCompilerVersionNode; - -static const struct FortranCompilerVersionNode : public CompilerVersionNode -{ - FortranCompilerVersionNode() {} // NOLINT(modernize-use-equals-default) + const char* const CompilerLanguage; +}; - std::string Evaluate( - const std::vector<std::string>& parameters, - cmGeneratorExpressionContext* context, - const GeneratorExpressionContent* content, - cmGeneratorExpressionDAGChecker* dagChecker) const override - { - if (!context->HeadTarget) { - reportError( - context, content->GetOriginalExpression(), - "$<Fortran_COMPILER_VERSION> may only be used with binary targets. " - "It may not be used with add_custom_command or add_custom_target."); - return std::string(); - } - return this->EvaluateWithLanguage(parameters, context, content, dagChecker, - "Fortran"); - } -} fortranCompilerVersionNode; +static const CompilerVersionNode cCompilerVersionNode("C"), + cxxCompilerVersionNode("CXX"), cudaCompilerVersionNode("CUDA"), + fortranCompilerVersionNode("Fortran"); struct PlatformIdNode : public cmGeneratorExpressionNode { |