cmGlobalGenerator: add unity sources after computing target compile features

We need to know which sources will be scanned for C++ module
dependencies in order to exclude them from unity builds.  The
addition of unity sources will not change the set of features.
This commit is contained in:
Ben Boeckel
2024-01-01 10:58:42 -05:00
committed by Brad King
parent 7fc2a83fe6
commit 76b5383123
2 changed files with 30 additions and 1 deletions

View File

@@ -1587,6 +1587,13 @@ bool cmGlobalGenerator::Compute()
}
}
// 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()) {
return false;
}
for (const auto& localGen : this->LocalGenerators) {
cmMakefile* mf = localGen->GetMakefile();
for (const auto& g : mf->GetInstallGenerators()) {
@@ -1863,7 +1870,6 @@ bool cmGlobalGenerator::AddAutomaticSources()
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")) {
@@ -1895,6 +1901,28 @@ bool cmGlobalGenerator::AddAutomaticSources()
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.
// 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;
}
std::unique_ptr<cmLinkLineComputer> cmGlobalGenerator::CreateLinkLineComputer(
cmOutputConverter* outputConverter, cmStateDirectory const& stateDir) const
{

View File

@@ -677,6 +677,7 @@ protected:
bool AddHeaderSetVerification();
bool AddAutomaticSources();
bool AddUnitySources();
std::string SelectMakeProgram(const std::string& makeProgram,
const std::string& makeDefault = "") const;