Commit 83c1657f authored by Brad King's avatar Brad King

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
parent d918b4a5
......@@ -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
{
......
......@@ -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;
......
......@@ -2827,7 +2827,6 @@ bool cmGlobalXCodeGenerator::CreateGroups(
continue;
}
generator->AddUnityBuild(gtgt, "");
generator->AddPchDependencies(gtgt, "");
auto addSourceToGroup = [this, mf, gtgt,
......
......@@ -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 =
......
......@@ -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);
......
......@@ -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;
......
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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());
}
......
......@@ -251,7 +251,6 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator(
this->InSourceBuild = (this->Makefile->GetCurrentSourceDirectory() ==
this->Makefile->GetCurrentBinaryDirectory());
this->LocalGenerator->AddUnityBuild(target, "");
this->LocalGenerator->AddPchDependencies(target, "");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment