浏览代码

Merge topic 'pch-single-arch'

ef006ebd9b PCH: Use per-arch .pch files only when building multiple Apple architectures
99bfb430ee cmNinjaTargetGenerator: Remove unused Apple architecture list

Acked-by: Kitware Robot <[email protected]>
Tested-by: buildbot <[email protected]>
Merge-request: !9483
Brad King 1 年之前
父节点
当前提交
721b86c02b

+ 3 - 6
Source/cmFileAPICodemodel.cxx

@@ -1384,14 +1384,11 @@ CompileData Target::BuildCompileData(cmSourceFile* sf)
   }
 
   // Add precompile headers compile options.
-  std::vector<std::string> architectures =
-    this->GT->GetAppleArchs(this->Config, fd.Language);
-  if (architectures.empty()) {
-    architectures.emplace_back();
-  }
+  std::vector<std::string> pchArchs =
+    this->GT->GetPchArchs(this->Config, fd.Language);
 
   std::unordered_map<std::string, std::string> pchSources;
-  for (const std::string& arch : architectures) {
+  for (const std::string& arch : pchArchs) {
     const std::string pchSource =
       this->GT->GetPchSource(this->Config, fd.Language, arch);
     if (!pchSource.empty()) {

+ 14 - 0
Source/cmGeneratorTarget.cxx

@@ -4370,6 +4370,20 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetPrecompileHeaders(
   return list;
 }
 
+std::vector<std::string> cmGeneratorTarget::GetPchArchs(
+  std::string const& config, std::string const& lang) const
+{
+  std::vector<std::string> pchArchs;
+  if (!this->GetGlobalGenerator()->IsXcode()) {
+    pchArchs = this->GetAppleArchs(config, lang);
+  }
+  if (pchArchs.size() < 2) {
+    // We do not need per-arch PCH files when building for one architecture.
+    pchArchs = { {} };
+  }
+  return pchArchs;
+}
+
 std::string cmGeneratorTarget::GetPchHeader(const std::string& config,
                                             const std::string& language,
                                             const std::string& arch) const

+ 2 - 0
Source/cmGeneratorTarget.h

@@ -599,6 +599,8 @@ public:
   std::vector<BT<std::string>> GetPrecompileHeaders(
     const std::string& config, const std::string& language) const;
 
+  std::vector<std::string> GetPchArchs(std::string const& config,
+                                       std::string const& lang) const;
   std::string GetPchHeader(const std::string& config,
                            const std::string& language,
                            const std::string& arch = std::string()) const;

+ 4 - 9
Source/cmLocalGenerator.cxx

@@ -2721,15 +2721,10 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
         continue;
       }
 
-      std::vector<std::string> architectures;
-      if (!this->GetGlobalGenerator()->IsXcode()) {
-        architectures = target->GetAppleArchs(config, lang);
-      }
-      if (architectures.empty()) {
-        architectures.emplace_back();
-      } else {
+      std::vector<std::string> pchArchs = target->GetPchArchs(config, lang);
+      if (pchArchs.size() > 1) {
         std::string useMultiArchPch;
-        for (const std::string& arch : architectures) {
+        for (const std::string& arch : pchArchs) {
           const std::string pchHeader =
             target->GetPchHeader(config, lang, arch);
           if (!pchHeader.empty()) {
@@ -2746,7 +2741,7 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
         }
       }
 
-      for (const std::string& arch : architectures) {
+      for (const std::string& arch : pchArchs) {
         const std::string pchSource = target->GetPchSource(config, lang, arch);
         const std::string pchHeader = target->GetPchHeader(config, lang, arch);
 

+ 4 - 7
Source/cmMakefileTargetGenerator.cxx

@@ -672,15 +672,12 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
   std::string const configUpper = cmSystemTools::UpperCase(config);
 
   // Add precompile headers dependencies
-  std::vector<std::string> architectures =
-    this->GeneratorTarget->GetAppleArchs(config, lang);
-  if (architectures.empty()) {
-    architectures.emplace_back();
-  }
+  std::vector<std::string> pchArchs =
+    this->GeneratorTarget->GetPchArchs(config, lang);
 
   std::string filterArch;
   std::unordered_map<std::string, std::string> pchSources;
-  for (const std::string& arch : architectures) {
+  for (const std::string& arch : pchArchs) {
     const std::string pchSource =
       this->GeneratorTarget->GetPchSource(config, lang, arch);
     if (pchSource == source.GetFullPath()) {
@@ -692,7 +689,7 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
   }
 
   if (!pchSources.empty() && !source.GetProperty("SKIP_PRECOMPILE_HEADERS")) {
-    for (const std::string& arch : architectures) {
+    for (const std::string& arch : pchArchs) {
       std::string const& pchHeader =
         this->GeneratorTarget->GetPchHeader(config, lang, arch);
       depends.push_back(pchHeader);

+ 7 - 19
Source/cmNinjaTargetGenerator.cxx

@@ -189,14 +189,11 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
   const std::string& config, const std::string& objectFileName)
 {
   std::unordered_map<std::string, std::string> pchSources;
-  std::vector<std::string> architectures =
-    this->GeneratorTarget->GetAppleArchs(config, language);
-  if (architectures.empty()) {
-    architectures.emplace_back();
-  }
+  std::vector<std::string> pchArchs =
+    this->GeneratorTarget->GetPchArchs(config, language);
 
   std::string filterArch;
-  for (const std::string& arch : architectures) {
+  for (const std::string& arch : pchArchs) {
     const std::string pchSource =
       this->GeneratorTarget->GetPchSource(config, language, arch);
     if (pchSource == source->GetFullPath()) {
@@ -1500,14 +1497,11 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
   // Add precompile headers dependencies
   std::vector<std::string> depList;
 
-  std::vector<std::string> architectures =
-    this->GeneratorTarget->GetAppleArchs(config, language);
-  if (architectures.empty()) {
-    architectures.emplace_back();
-  }
+  std::vector<std::string> pchArchs =
+    this->GeneratorTarget->GetPchArchs(config, language);
 
   std::unordered_set<std::string> pchSources;
-  for (const std::string& arch : architectures) {
+  for (const std::string& arch : pchArchs) {
     const std::string pchSource =
       this->GeneratorTarget->GetPchSource(config, language, arch);
 
@@ -1517,7 +1511,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
   }
 
   if (!pchSources.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
-    for (const std::string& arch : architectures) {
+    for (const std::string& arch : pchArchs) {
       depList.push_back(
         this->GeneratorTarget->GetPchHeader(config, language, arch));
       if (pchSources.find(source->GetFullPath()) == pchSources.end()) {
@@ -1841,12 +1835,6 @@ void cmNinjaTargetGenerator::WriteCxxModuleBmiBuildStatement(
 
   std::vector<std::string> depList;
 
-  std::vector<std::string> architectures =
-    this->GeneratorTarget->GetAppleArchs(config, language);
-  if (architectures.empty()) {
-    architectures.emplace_back();
-  }
-
   bmiBuild.OrderOnlyDeps.push_back(this->OrderDependsTargetForTarget(config));
 
   // For some cases we scan to dynamically discover dependencies.