Browse Source

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.
Brad King 2 năm trước cách đây
mục cha
commit
68fca3eafe
2 tập tin đã thay đổi với 47 bổ sung1 xóa
  1. 39 1
      Source/cmGeneratorTarget.cxx
  2. 8 0
      Source/cmGeneratorTarget.h

+ 39 - 1
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];

+ 8 - 0
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;