diff options
author | Brad King <brad.king@kitware.com> | 2023-10-04 19:47:15 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-10-05 17:16:24 (GMT) |
commit | 68fca3eafeaf244c37843f186bd4af8a314df08c (patch) | |
tree | 6d71e6a0c4a3a4a729ecdfc273e3ffe76710a79b | |
parent | da36e0638b1adfdbdb75fb0228268b30f5832544 (diff) | |
download | CMake-68fca3eafeaf244c37843f186bd4af8a314df08c.zip CMake-68fca3eafeaf244c37843f186bd4af8a314df08c.tar.gz CMake-68fca3eafeaf244c37843f186bd4af8a314df08c.tar.bz2 |
cmGeneratorTarget: Track explicitly enabled language standard levels
Previously we only tracked when an explicit setting requires the
standard level to be higher than the compiler's default.
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 40 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.h | 8 |
2 files changed, 47 insertions, 1 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index bbd5789..1c339de 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5025,10 +5025,44 @@ void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const } } +cm::optional<cmStandardLevel> cmGeneratorTarget::GetExplicitStandardLevel( + std::string const& lang, std::string const& config) const +{ + cm::optional<cmStandardLevel> level; + std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang); + auto i = this->ExplicitStandardLevel.find(key); + if (i != this->ExplicitStandardLevel.end()) { + level = i->second; + } + return level; +} + +void cmGeneratorTarget::UpdateExplicitStandardLevel(std::string const& lang, + std::string const& config, + cmStandardLevel level) +{ + auto e = this->ExplicitStandardLevel.emplace( + cmStrCat(cmSystemTools::UpperCase(config), '-', lang), level); + if (!e.second && e.first->second < level) { + e.first->second = level; + } +} + bool cmGeneratorTarget::ComputeCompileFeatures(std::string const& config) { - // Compute the language standard based on the compile features. cmStandardLevelResolver standardResolver(this->Makefile); + + for (std::string const& lang : + this->Makefile->GetState()->GetEnabledLanguages()) { + if (cmValue languageStd = this->GetLanguageStandard(lang, config)) { + if (cm::optional<cmStandardLevel> langLevel = + standardResolver.LanguageStandardLevel(lang, *languageStd)) { + this->UpdateExplicitStandardLevel(lang, config, *langLevel); + } + } + } + + // Compute the language standard based on the compile features. std::vector<BT<std::string>> features = this->GetCompileFeatures(config); for (BT<std::string> const& f : features) { std::string lang; @@ -5048,6 +5082,10 @@ bool cmGeneratorTarget::ComputeCompileFeatures(std::string const& config) return false; } + if (featureLevel) { + this->UpdateExplicitStandardLevel(lang, config, *featureLevel); + } + if (!newRequiredStandard.empty()) { BTs<std::string>& languageStandardProperty = this->LanguageStandardMap[key]; diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 6bdb7ff..bf49914 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -21,6 +21,7 @@ #include "cmLinkItem.h" #include "cmListFileCache.h" #include "cmPolicies.h" +#include "cmStandardLevel.h" #include "cmStateTypes.h" #include "cmValue.h" @@ -1242,6 +1243,13 @@ private: std::map<std::string, BTs<std::string>> LanguageStandardMap; + cm::optional<cmStandardLevel> GetExplicitStandardLevel( + std::string const& lang, std::string const& config) const; + void UpdateExplicitStandardLevel(std::string const& lang, + std::string const& config, + cmStandardLevel level); + std::map<std::string, cmStandardLevel> ExplicitStandardLevel; + cmValue GetPropertyWithPairedLanguageSupport(std::string const& lang, const char* suffix) const; |