Selaa lähdekoodia

Merge topic 'restore-pch-with-unity' into release-3.28

30829da506 Unity: Clarify source comments on unity build transformation
87bf1c6c33 Merge branch 'unity-after-compile-features' into restore-pch-with-unity
df08c37a42 cmGlobalGenerator: Add unity/pch sources after computing compile features
004c3c3986 Tests: Add case covering PCH in a unity build

Acked-by: Kitware Robot <[email protected]>
Tested-by: buildbot <[email protected]>
Acked-by: Ben Boeckel <[email protected]>
Merge-request: !9215
Brad King 1 vuosi sitten
vanhempi
sitoutus
292d808a3a

+ 11 - 29
Source/cmGlobalGenerator.cxx

@@ -1543,10 +1543,7 @@ bool cmGlobalGenerator::Compute()
   // so create the map from project name to vector of local generators
   this->FillProjectMap();
 
-  // Add automatically generated sources (e.g. unity build).
-  if (!this->AddAutomaticSources()) {
-    return false;
-  }
+  this->CreateFileGenerateOutputs();
 
   // Iterate through all targets and add verification targets for header sets
   if (!this->AddHeaderSetVerification()) {
@@ -1587,10 +1584,11 @@ bool cmGlobalGenerator::Compute()
     }
   }
 
+  // Add automatically generated sources (e.g. unity build).
   // Add unity sources after computing compile features.  Unity sources do
   // not change the set of languages or features, but we need to know them
   // to filter out sources that are scanned for C++ module dependencies.
-  if (!this->AddUnitySources()) {
+  if (!this->AddAutomaticSources()) {
     return false;
   }
 
@@ -1860,16 +1858,21 @@ bool cmGlobalGenerator::AddHeaderSetVerification()
   return true;
 }
 
-bool cmGlobalGenerator::AddAutomaticSources()
+void cmGlobalGenerator::CreateFileGenerateOutputs()
 {
   for (const auto& lg : this->LocalGenerators) {
     lg->CreateEvaluationFileOutputs();
   }
+}
+
+bool cmGlobalGenerator::AddAutomaticSources()
+{
   for (const auto& lg : this->LocalGenerators) {
     for (const auto& gt : lg->GetGeneratorTargets()) {
       if (!gt->CanCompileSources()) {
         continue;
       }
+      lg->AddUnityBuild(gt.get());
       lg->AddISPCDependencies(gt.get());
       // Targets that reuse a PCH are handled below.
       if (!gt->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM")) {
@@ -1889,29 +1892,8 @@ bool cmGlobalGenerator::AddAutomaticSources()
       }
     }
   }
-  // The above transformations may have changed the classification of sources.
-  // Clear the source list and classification cache (KindedSources) of all
-  // targets so that it will be recomputed correctly by the generators later
-  // now that the above transformations are done for all targets.
-  for (const auto& lg : this->LocalGenerators) {
-    for (const auto& gt : lg->GetGeneratorTargets()) {
-      gt->ClearSourcesCache();
-    }
-  }
-  return true;
-}
-
-bool cmGlobalGenerator::AddUnitySources()
-{
-  for (const auto& lg : this->LocalGenerators) {
-    for (const auto& gt : lg->GetGeneratorTargets()) {
-      if (!gt->CanCompileSources()) {
-        continue;
-      }
-      lg->AddUnityBuild(gt.get());
-    }
-  }
-  // The above transformation may have changed the classification of sources.
+  // The above transformations may have changed the classification of sources,
+  // e.g., sources that go into unity builds become SourceKindUnityBatched.
   // Clear the source list and classification cache (KindedSources) of all
   // targets so that it will be recomputed correctly by the generators later
   // now that the above transformations are done for all targets.

+ 1 - 1
Source/cmGlobalGenerator.h

@@ -676,8 +676,8 @@ protected:
 
   bool AddHeaderSetVerification();
 
+  void CreateFileGenerateOutputs();
   bool AddAutomaticSources();
-  bool AddUnitySources();
 
   std::string SelectMakeProgram(const std::string& makeProgram,
                                 const std::string& makeDefault = "") const;

+ 1 - 0
Source/cmLocalGenerator.cxx

@@ -3131,6 +3131,7 @@ void cmLocalGenerator::AddUnityBuild(cmGeneratorTarget* target)
 
   for (size_t ci = 0; ci < configs.size(); ++ci) {
     // FIXME: Refactor collection of sources to not evaluate object libraries.
+    // Their final set of object files might be transformed by unity builds.
     std::vector<cmSourceFile*> sources;
     target->GetSourceFiles(sources, configs[ci]);
     for (cmSourceFile* sf : sources) {

+ 1 - 0
Tests/RunCMake/PrecompileHeaders/PchInterfaceUnity-check.cmake

@@ -0,0 +1 @@
+include(${CMAKE_CURRENT_LIST_DIR}/PchInterface-check.cmake)

+ 2 - 0
Tests/RunCMake/PrecompileHeaders/PchInterfaceUnity.cmake

@@ -0,0 +1,2 @@
+set(CMAKE_UNITY_BUILD 1)
+include(PchInterface.cmake)

+ 1 - 0
Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake

@@ -12,6 +12,7 @@ endfunction()
 run_cmake(DisabledPch)
 run_cmake(PchDebugGenex)
 run_test(PchInterface)
+run_test(PchInterfaceUnity)
 run_cmake(PchPrologueEpilogue)
 run_test(SkipPrecompileHeaders)
 run_test(CXXnotC)