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 <ben.boeckel@kitware.com>
This commit is contained in:
Brad King 2024-02-02 07:50:49 -05:00
parent 004c3c3986
commit df08c37a42
2 changed files with 15 additions and 5 deletions

View File

@ -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()) {

View File

@ -676,6 +676,7 @@ protected:
bool AddHeaderSetVerification();
void CreateFileGenerateOutputs();
bool AddAutomaticSources();
std::string SelectMakeProgram(const std::string& makeProgram,