From 004c3c3986b0df2272ae2c00a634159425b576ae Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 2 Feb 2024 08:13:22 -0500 Subject: Tests: Add case covering PCH in a unity build Issue: #25650 --- Tests/RunCMake/PrecompileHeaders/PchInterfaceUnity-check.cmake | 1 + Tests/RunCMake/PrecompileHeaders/PchInterfaceUnity.cmake | 2 ++ Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake | 1 + 3 files changed, 4 insertions(+) create mode 100644 Tests/RunCMake/PrecompileHeaders/PchInterfaceUnity-check.cmake create mode 100644 Tests/RunCMake/PrecompileHeaders/PchInterfaceUnity.cmake diff --git a/Tests/RunCMake/PrecompileHeaders/PchInterfaceUnity-check.cmake b/Tests/RunCMake/PrecompileHeaders/PchInterfaceUnity-check.cmake new file mode 100644 index 0000000..c17aaa0 --- /dev/null +++ b/Tests/RunCMake/PrecompileHeaders/PchInterfaceUnity-check.cmake @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/PchInterface-check.cmake) diff --git a/Tests/RunCMake/PrecompileHeaders/PchInterfaceUnity.cmake b/Tests/RunCMake/PrecompileHeaders/PchInterfaceUnity.cmake new file mode 100644 index 0000000..59c2523 --- /dev/null +++ b/Tests/RunCMake/PrecompileHeaders/PchInterfaceUnity.cmake @@ -0,0 +1,2 @@ +set(CMAKE_UNITY_BUILD 1) +include(PchInterface.cmake) diff --git a/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake b/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake index b163369..c8a5c15 100644 --- a/Tests/RunCMake/PrecompileHeaders/RunCMakeTest.cmake +++ b/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) -- cgit v0.12 From df08c37a42379cc73dc2dd610a5b87573b24d12e Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 2 Feb 2024 07:50:49 -0500 Subject: cmGlobalGenerator: Add unity/pch sources after computing compile features Sources that will be scanned for C++ module dependencies need to be excluded from unity builds. We need to compute compile features in order to know which sources will be scanned. Unity build and PCH sources can be added afterward without changing the compile features. This re-implements commit 76b5383123 (cmGlobalGenerator: add unity sources after computing target compile features, 2024-01-01, v3.28.2~17^2~1) using a simpler approach that also preserves support for PCH with Unity builds. Issue: #25650 Co-authored-by: Ben Boeckel --- Source/cmGlobalGenerator.cxx | 19 ++++++++++++++----- Source/cmGlobalGenerator.h | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index c2b972d..493d32d 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/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,6 +1584,14 @@ 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->AddAutomaticSources()) { + return false; + } + for (const auto& localGen : this->LocalGenerators) { cmMakefile* mf = localGen->GetMakefile(); for (const auto& g : mf->GetInstallGenerators()) { @@ -1853,11 +1858,15 @@ 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()) { diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index aa54f69..bc80547 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -676,6 +676,7 @@ protected: bool AddHeaderSetVerification(); + void CreateFileGenerateOutputs(); bool AddAutomaticSources(); std::string SelectMakeProgram(const std::string& makeProgram, -- cgit v0.12 From 30829da50616c18e88e69e8fd6b4508ce28429c3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 2 Feb 2024 07:59:21 -0500 Subject: Unity: Clarify source comments on unity build transformation --- Source/cmGlobalGenerator.cxx | 3 ++- Source/cmLocalGenerator.cxx | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 493d32d..d44863d 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1892,7 +1892,8 @@ bool cmGlobalGenerator::AddAutomaticSources() } } } - // The above transformations 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. diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 7337ea2..3e98341 100644 --- a/Source/cmLocalGenerator.cxx +++ b/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 sources; target->GetSourceFiles(sources, configs[ci]); for (cmSourceFile* sf : sources) { -- cgit v0.12