Pārlūkot izejas kodu

Unity build: Generate sources during Compute step

The unity build sources need to be added for all generators.  Create
them during `cmGlobalGenerator::Compute` to avoid duplicating the calls
in every generator.  We already handle Qt autogen there too.

Issue: #19789
Brad King 6 gadi atpakaļ
vecāks
revīzija
83c1657ff7

+ 18 - 0
Source/cmGlobalGenerator.cxx

@@ -1381,6 +1381,11 @@ bool cmGlobalGenerator::Compute()
     return false;
   }
 
+  // Add automatically generated sources (e.g. unity build).
+  if (!this->AddAutomaticSources()) {
+    return false;
+  }
+
   // Add generator specific helper commands
   for (cmLocalGenerator* localGen : this->LocalGenerators) {
     localGen->AddHelperCommands();
@@ -1548,6 +1553,19 @@ bool cmGlobalGenerator::QtAutoGen()
 #endif
 }
 
+bool cmGlobalGenerator::AddAutomaticSources()
+{
+  for (cmLocalGenerator* lg : this->LocalGenerators) {
+    for (cmGeneratorTarget* gt : lg->GetGeneratorTargets()) {
+      if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+        continue;
+      }
+      lg->AddUnityBuild(gt);
+    }
+  }
+  return true;
+}
+
 cmLinkLineComputer* cmGlobalGenerator::CreateLinkLineComputer(
   cmOutputConverter* outputConverter, cmStateDirectory const& stateDir) const
 {

+ 2 - 0
Source/cmGlobalGenerator.h

@@ -503,6 +503,8 @@ protected:
   /// @return true on success
   bool QtAutoGen();
 
+  bool AddAutomaticSources();
+
   std::string SelectMakeProgram(const std::string& makeProgram,
                                 const std::string& makeDefault = "") const;
 

+ 0 - 1
Source/cmGlobalXCodeGenerator.cxx

@@ -2827,7 +2827,6 @@ bool cmGlobalXCodeGenerator::CreateGroups(
         continue;
       }
 
-      generator->AddUnityBuild(gtgt, "");
       generator->AddPchDependencies(gtgt, "");
 
       auto addSourceToGroup = [this, mf, gtgt,

+ 7 - 2
Source/cmLocalGenerator.cxx

@@ -2437,13 +2437,18 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target,
   }
 }
 
-void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target,
-                                     const std::string& config)
+void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
 {
   if (!target->GetPropertyAsBool("UNITY_BUILD")) {
     return;
   }
 
+  // FIXME: Handle all configurations in multi-config generators.
+  std::string config;
+  if (!this->GetGlobalGenerator()->IsMultiConfig()) {
+    config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+  }
+
   const std::string buildType = cmSystemTools::UpperCase(config);
 
   std::string filename_base =

+ 1 - 1
Source/cmLocalGenerator.h

@@ -128,7 +128,7 @@ public:
                                 const std::string& rawFlag) const;
   void AddPchDependencies(cmGeneratorTarget* target,
                           const std::string& config);
-  void AddUnityBuild(cmGeneratorTarget* target, const std::string& config);
+  void AddUnityBuild(cmGeneratorTarget* target);
   void AppendIPOLinkerFlags(std::string& flags, cmGeneratorTarget* target,
                             const std::string& config,
                             const std::string& lang);

+ 0 - 1
Source/cmLocalVisualStudio7Generator.cxx

@@ -1313,7 +1313,6 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
                                                     const std::string& libName,
                                                     cmGeneratorTarget* target)
 {
-  this->AddUnityBuild(target, "");
   this->AddPchDependencies(target, "");
 
   std::vector<std::string> configs;

+ 0 - 1
Source/cmMakefileExecutableTargetGenerator.cxx

@@ -41,7 +41,6 @@ cmMakefileExecutableTargetGenerator::cmMakefileExecutableTargetGenerator(
     cm::make_unique<cmOSXBundleGenerator>(target, this->ConfigName);
   this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
 
-  this->LocalGenerator->AddUnityBuild(target, this->ConfigName);
   this->LocalGenerator->AddPchDependencies(target, this->ConfigName);
 }
 

+ 0 - 1
Source/cmMakefileLibraryTargetGenerator.cxx

@@ -43,7 +43,6 @@ cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator(
     cm::make_unique<cmOSXBundleGenerator>(target, this->ConfigName);
   this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
 
-  this->LocalGenerator->AddUnityBuild(target, this->ConfigName);
   this->LocalGenerator->AddPchDependencies(target, this->ConfigName);
 }
 

+ 0 - 1
Source/cmMakefileUtilityTargetGenerator.cxx

@@ -26,7 +26,6 @@ cmMakefileUtilityTargetGenerator::cmMakefileUtilityTargetGenerator(
     cm::make_unique<cmOSXBundleGenerator>(target, this->ConfigName);
   this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
 
-  this->LocalGenerator->AddUnityBuild(target, this->ConfigName);
   this->LocalGenerator->AddPchDependencies(target, this->ConfigName);
 }
 

+ 0 - 1
Source/cmNinjaNormalTargetGenerator.cxx

@@ -62,7 +62,6 @@ cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator(
     cm::make_unique<cmOSXBundleGenerator>(target, this->GetConfigName());
   this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
 
-  GetLocalGenerator()->AddUnityBuild(target, this->GetConfigName());
   GetLocalGenerator()->AddPchDependencies(target, this->GetConfigName());
 }
 

+ 0 - 1
Source/cmVisualStudio10TargetGenerator.cxx

@@ -251,7 +251,6 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator(
   this->InSourceBuild = (this->Makefile->GetCurrentSourceDirectory() ==
                          this->Makefile->GetCurrentBinaryDirectory());
 
-  this->LocalGenerator->AddUnityBuild(target, "");
   this->LocalGenerator->AddPchDependencies(target, "");
 }