summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-11-17 15:15:55 (GMT)
committerBrad King <brad.king@kitware.com>2022-11-18 16:44:52 (GMT)
commit914571a04249ee561a30309197d8e1c1cacbe18b (patch)
tree81bcf00395d68dd29fe3099d4ba588ed7701ede1 /Source
parentad16ae5c70778e6bfd6d30b17a3ad9b248b2a569 (diff)
downloadCMake-914571a04249ee561a30309197d8e1c1cacbe18b.zip
CMake-914571a04249ee561a30309197d8e1c1cacbe18b.tar.gz
CMake-914571a04249ee561a30309197d8e1c1cacbe18b.tar.bz2
Place language standard flags just after CMAKE_<LANG>_FLAGS
Previously we added the language standard flag near the end of all options, even after those added by `add_compile_options` and friends. However, on some compilers such as MSVC, the `-std` flag may reset defaults for flags that precede it on the command line. Move the language standard flag to before all other flags that CMake adds for other abstractions, and before those added by `add_compile_options`. `CMAKE_<LANG>_FLAGS` should still precede the language flags though, because they are meant to be treated as language-wide modifications to the compiler defaults, similar to `$CC $CFLAGS`. Fixes: #23860 Fixes: #24170
Diffstat (limited to 'Source')
-rw-r--r--Source/cmLocalGenerator.cxx27
1 files changed, 12 insertions, 15 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 9745142..550141f 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1021,12 +1021,6 @@ void cmLocalGenerator::AddCompileOptions(std::vector<BT<std::string>>& flags,
}
}
- std::string compReqFlag;
- this->AddCompilerRequirementFlag(compReqFlag, target, lang, config);
- if (!compReqFlag.empty()) {
- flags.emplace_back(std::move(compReqFlag));
- }
-
// Add Warning as errors flags
if (!this->GetCMakeInstance()->GetIgnoreWarningAsError()) {
const cmValue wError = target->GetProperty("COMPILE_WARNING_AS_ERROR");
@@ -1932,6 +1926,18 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
this->AddConfigVariableFlags(flags, cmStrCat("CMAKE_", lang, "_FLAGS"),
config);
+ // Add the language standard flag for compiling, and sometimes linking.
+ if (compileOrLink == cmBuildStep::Compile ||
+ (compileOrLink == cmBuildStep::Link &&
+ // Some toolchains require use of the language standard flag
+ // when linking in order to use the matching standard library.
+ // FIXME: If CMake gains an abstraction for standard library
+ // selection, this will have to be reconciled with it.
+ this->Makefile->IsOn(
+ cmStrCat("CMAKE_", lang, "_LINK_WITH_STANDARD_COMPILE_OPTION")))) {
+ this->AddCompilerRequirementFlag(flags, target, lang, config);
+ }
+
std::string compiler = this->Makefile->GetSafeDefinition(
cmStrCat("CMAKE_", lang, "_COMPILER_ID"));
@@ -2076,15 +2082,6 @@ void cmLocalGenerator::AddLanguageFlagsForLinking(
std::string& flags, cmGeneratorTarget const* target, const std::string& lang,
const std::string& config)
{
- if (this->Makefile->IsOn("CMAKE_" + lang +
- "_LINK_WITH_STANDARD_COMPILE_OPTION")) {
- // This toolchain requires use of the language standard flag
- // when linking in order to use the matching standard library.
- // FIXME: If CMake gains an abstraction for standard library
- // selection, this will have to be reconciled with it.
- this->AddCompilerRequirementFlag(flags, target, lang, config);
- }
-
this->AddLanguageFlags(flags, target, cmBuildStep::Link, lang, config);
if (target->IsIPOEnabled(lang, config)) {