diff options
author | Brad King <brad.king@kitware.com> | 2021-10-04 16:42:40 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-10-04 16:43:24 (GMT) |
commit | c55a41c9b2fea1617ad2a0a50760e4f8b6e42a47 (patch) | |
tree | 12616c224f1302c14cb8a8c893f89b4e89b18fbb /Source | |
parent | b2726f13bdd2caffcd27dd5c7ebf3211169a40e4 (diff) | |
parent | 4a0485be7f4ab06201c478f5a46111ab1e8e773e (diff) | |
download | CMake-c55a41c9b2fea1617ad2a0a50760e4f8b6e42a47.zip CMake-c55a41c9b2fea1617ad2a0a50760e4f8b6e42a47.tar.gz CMake-c55a41c9b2fea1617ad2a0a50760e4f8b6e42a47.tar.bz2 |
Merge topic 'default_extensions'
4a0485be7f cmStandardLevelResolver: Avoid unnecessary flags, fix unset level logic
29e2b85171 Tests: Simplify RunCMake.CompileFeatures introspection
fc3a1cbdd8 CompilerID: Compiler extensions default detection
2adfd95d79 CompilerID: Rename language_dialect to language_standard
00055d7779 Help: Document CMAKE_<LANG>_STANDARD_DEFAULT
a65bee4cfc Help: Document HIP standard/extensions properties and variables
a40ff1bb5a Help: Make language standard/extensions variable pages less wordy
3feff8379b Help: Generic language standard and extension variables documentation
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6177
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmPolicies.h | 5 | ||||
-rw-r--r-- | Source/cmStandardLevelResolver.cxx | 87 |
2 files changed, 76 insertions, 16 deletions
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index a98e6c6..ce04117 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -382,7 +382,10 @@ class cmMakefile; 21, 0, cmPolicies::WARN) \ SELECT(POLICY, CMP0127, \ "cmake_dependent_option() supports full Condition Syntax.", 3, 22, \ - 0, cmPolicies::WARN) + 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0128, \ + "Selection of language standard and extension flags improved.", 3, \ + 22, 0, cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ diff --git a/Source/cmStandardLevelResolver.cxx b/Source/cmStandardLevelResolver.cxx index c73f53a..957f4ca 100644 --- a/Source/cmStandardLevelResolver.cxx +++ b/Source/cmStandardLevelResolver.cxx @@ -20,6 +20,7 @@ #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmPolicies.h" #include "cmStringAlgorithms.h" #include "cmTarget.h" #include "cmValue.h" @@ -83,25 +84,62 @@ struct StandardLevelComputer return std::string{}; } + cmPolicies::PolicyStatus const cmp0128{ makefile->GetPolicyStatus( + cmPolicies::CMP0128) }; + bool const defaultExt{ cmIsOn(*makefile->GetDefinition( + cmStrCat("CMAKE_", this->Language, "_EXTENSIONS_DEFAULT"))) }; bool ext = true; + + if (cmp0128 == cmPolicies::NEW) { + ext = defaultExt; + } + if (cmValue extPropValue = target->GetLanguageExtensions(this->Language)) { - if (cmIsOff(*extPropValue)) { - ext = false; - } + ext = cmIsOn(*extPropValue); } + std::string const type{ ext ? "EXTENSION" : "STANDARD" }; + cmValue standardProp = target->GetLanguageStandard(this->Language, config); if (!standardProp) { - if (ext) { - // No language standard is specified and extensions are not disabled. - // Check if this compiler needs a flag to enable extensions. - return cmStrCat("CMAKE_", this->Language, "_EXTENSION_COMPILE_OPTION"); + if (cmp0128 == cmPolicies::NEW) { + // Add extension flag if compiler's default doesn't match. + if (ext != defaultExt) { + return cmStrCat("CMAKE_", this->Language, *defaultStd, "_", type, + "_COMPILE_OPTION"); + } + } else { + if (cmp0128 == cmPolicies::WARN && + makefile->PolicyOptionalWarningEnabled( + "CMAKE_POLICY_WARNING_CMP0128") && + ext != defaultExt) { + const char* state{}; + if (ext) { + if (!makefile->GetDefinition(cmStrCat( + "CMAKE_", this->Language, "_EXTENSION_COMPILE_OPTION"))) { + state = "enabled"; + } + } else { + state = "disabled"; + } + if (state) { + makefile->IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0128), + "\nFor compatibility with older versions of CMake, " + "compiler extensions won't be ", + state, ".")); + } + } + + if (ext) { + return cmStrCat("CMAKE_", this->Language, + "_EXTENSION_COMPILE_OPTION"); + } } return std::string{}; } - std::string const type = ext ? "EXTENSION" : "STANDARD"; - if (target->GetLanguageStandardRequired(this->Language)) { std::string option_flag = cmStrCat( "CMAKE_", this->Language, *standardProp, "_", type, "_COMPILE_OPTION"); @@ -121,6 +159,25 @@ struct StandardLevelComputer return option_flag; } + // If the request matches the compiler's defaults we don't need to add + // anything. + if (*standardProp == *defaultStd && ext == defaultExt) { + if (cmp0128 == cmPolicies::NEW) { + return std::string{}; + } + + if (cmp0128 == cmPolicies::WARN && + makefile->PolicyOptionalWarningEnabled( + "CMAKE_POLICY_WARNING_CMP0128")) { + makefile->IssueMessage( + MessageType::AUTHOR_WARNING, + cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0128), + "\nFor compatibility with older versions of CMake, " + "unnecessary flags for language standard or compiler " + "extensions may be added.")); + } + } + std::string standardStr(*standardProp); if (this->Language == "CUDA" && standardStr == "98") { standardStr = "03"; @@ -147,17 +204,17 @@ struct StandardLevelComputer return std::string{}; } - // If the standard requested is older than the compiler's default - // then we need to use a flag to change it. - if (stdIt <= defaultStdIt) { + // If the standard requested is older than the compiler's default or the + // extension mode doesn't match then we need to use a flag. + if (stdIt < defaultStdIt) { auto offset = std::distance(cm::cbegin(stds), stdIt); return cmStrCat("CMAKE_", this->Language, stdsStrings[offset], "_", type, "_COMPILE_OPTION"); } - // The standard requested is at least as new as the compiler's default, - // and the standard request is not required. Decay to the newest standard - // for which a flag is defined. + // The compiler's default is at least as new as the requested standard, + // and the requested standard is not required. Decay to the newest + // standard for which a flag is defined. for (; defaultStdIt < stdIt; --stdIt) { auto offset = std::distance(cm::cbegin(stds), stdIt); std::string option_flag = |