diff options
author | Brad King <brad.king@kitware.com> | 2024-05-24 14:31:40 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-05-24 14:31:52 (GMT) |
commit | 7b38a1dee7f4bd43115bbb179e7e4715ff3bbdc1 (patch) | |
tree | d014ef4658e5a2dc125863c92f347205da0d8023 /Source | |
parent | 88f30da5a047d428c5356826fd9bf2aab85ab489 (diff) | |
parent | af81b8667e627457550cc26ab5696d1e46293162 (diff) | |
download | CMake-7b38a1dee7f4bd43115bbb179e7e4715ff3bbdc1.zip CMake-7b38a1dee7f4bd43115bbb179e7e4715ff3bbdc1.tar.gz CMake-7b38a1dee7f4bd43115bbb179e7e4715ff3bbdc1.tar.bz2 |
Merge topic 'genex-compiler-frontend-variant'
af81b8667e GenEx: Add generator expr. for CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT
8a11a39c51 Help: Use correct programming language names in docs of generator expr.
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9538
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 01cd18d..84521ca 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -2013,6 +2013,76 @@ static const CompilerVersionNode cCompilerVersionNode("C"), fortranCompilerVersionNode("Fortran"), ispcCompilerVersionNode("ISPC"), hipCompilerVersionNode("HIP"); +struct CompilerFrontendVariantNode : public cmGeneratorExpressionNode +{ + CompilerFrontendVariantNode(const char* compilerLang) + : CompilerLanguage(compilerLang) + { + } + + int NumExpectedParameters() const override { return ZeroOrMoreParameters; } + + 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_FRONTEND_VARIANT> 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, + cmGeneratorExpressionDAGChecker* /*unused*/, + const std::string& lang) const + { + std::string const& compilerFrontendVariant = + context->LG->GetMakefile()->GetSafeDefinition( + "CMAKE_" + lang + "_COMPILER_FRONTEND_VARIANT"); + if (parameters.empty()) { + return compilerFrontendVariant; + } + if (compilerFrontendVariant.empty()) { + return parameters.front().empty() ? "1" : "0"; + } + static cmsys::RegularExpression compilerFrontendVariantValidator( + "^[A-Za-z0-9_]*$"); + + for (auto const& param : parameters) { + if (!compilerFrontendVariantValidator.find(param)) { + reportError(context, content->GetOriginalExpression(), + "Expression syntax not recognized."); + return {}; + } + if (strcmp(param.c_str(), compilerFrontendVariant.c_str()) == 0) { + return "1"; + } + } + return "0"; + } + + const char* const CompilerLanguage; +}; + +static const CompilerFrontendVariantNode cCompilerFrontendVariantNode("C"), + cxxCompilerFrontendVariantNode("CXX"), + cudaCompilerFrontendVariantNode("CUDA"), + objcCompilerFrontendVariantNode("OBJC"), + objcxxCompilerFrontendVariantNode("OBJCXX"), + fortranCompilerFrontendVariantNode("Fortran"), + hipCompilerFrontendVariantNode("HIP"), + ispcCompilerFrontendVariantNode("ISPC"); + struct PlatformIdNode : public cmGeneratorExpressionNode { PlatformIdNode() {} // NOLINT(modernize-use-equals-default) @@ -4449,6 +4519,14 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode( { "OBJCXX_COMPILER_VERSION", &objcxxCompilerVersionNode }, { "Fortran_COMPILER_VERSION", &fortranCompilerVersionNode }, { "HIP_COMPILER_VERSION", &hipCompilerVersionNode }, + { "C_COMPILER_FRONTEND_VARIANT", &cCompilerFrontendVariantNode }, + { "CXX_COMPILER_FRONTEND_VARIANT", &cxxCompilerFrontendVariantNode }, + { "CUDA_COMPILER_FRONTEND_VARIANT", &cudaCompilerFrontendVariantNode }, + { "OBJC_COMPILER_FRONTEND_VARIANT", &objcCompilerFrontendVariantNode }, + { "OBJCXX_COMPILER_FRONTEND_VARIANT", &objcxxCompilerFrontendVariantNode }, + { "Fortran_COMPILER_FRONTEND_VARIANT", + &fortranCompilerFrontendVariantNode }, + { "HIP_COMPILER_FRONTEND_VARIANT", &hipCompilerFrontendVariantNode }, { "PLATFORM_ID", &platformIdNode }, { "COMPILE_FEATURES", &compileFeaturesNode }, { "CONFIGURATION", &configurationNode }, |