mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-18 08:51:52 +08:00
cmLocalGenerator: Refactor custom command generator construction
Add support for constructing and using multiple generators for one custom command. cmGeneratorTarget contains a code path that needs this behavior when used with Ninja but not other generators, so use virtual dispatch through cmLocalGenerator.
This commit is contained in:
@@ -3079,8 +3079,8 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc)
|
|||||||
std::set<std::string> depends;
|
std::set<std::string> depends;
|
||||||
for (std::string const& config :
|
for (std::string const& config :
|
||||||
this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig)) {
|
this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig)) {
|
||||||
cmCustomCommandGenerator ccg(cc, config, this->LocalGenerator);
|
for (cmCustomCommandGenerator const& ccg :
|
||||||
|
this->LocalGenerator->MakeCustomCommandGenerators(cc, config)) {
|
||||||
// Collect target-level dependencies referenced in command lines.
|
// Collect target-level dependencies referenced in command lines.
|
||||||
for (auto const& util : ccg.GetUtilities()) {
|
for (auto const& util : ccg.GetUtilities()) {
|
||||||
this->GeneratorTarget->Target->AddUtility(util);
|
this->GeneratorTarget->Target->AddUtility(util);
|
||||||
@@ -3089,6 +3089,7 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc)
|
|||||||
// Collect file-level dependencies referenced in DEPENDS.
|
// Collect file-level dependencies referenced in DEPENDS.
|
||||||
depends.insert(ccg.GetDepends().begin(), ccg.GetDepends().end());
|
depends.insert(ccg.GetDepends().begin(), ccg.GetDepends().end());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Queue file-level dependencies.
|
// Queue file-level dependencies.
|
||||||
for (std::string const& dep : depends) {
|
for (std::string const& dep : depends) {
|
||||||
|
@@ -4232,6 +4232,15 @@ cmSourceFile* cmLocalGenerator::GetSourceFileWithOutput(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<cmCustomCommandGenerator>
|
||||||
|
cmLocalGenerator::MakeCustomCommandGenerators(cmCustomCommand const& cc,
|
||||||
|
std::string const& config)
|
||||||
|
{
|
||||||
|
std::vector<cmCustomCommandGenerator> ccgs;
|
||||||
|
ccgs.emplace_back(cc, config, this);
|
||||||
|
return ccgs;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> cmLocalGenerator::ExpandCustomCommandOutputPaths(
|
std::vector<std::string> cmLocalGenerator::ExpandCustomCommandOutputPaths(
|
||||||
cmCompiledGeneratorExpression const& cge, std::string const& config)
|
cmCompiledGeneratorExpression const& cge, std::string const& config)
|
||||||
{
|
{
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
class cmCompiledGeneratorExpression;
|
class cmCompiledGeneratorExpression;
|
||||||
class cmComputeLinkInformation;
|
class cmComputeLinkInformation;
|
||||||
|
class cmCustomCommand;
|
||||||
class cmCustomCommandGenerator;
|
class cmCustomCommandGenerator;
|
||||||
class cmCustomCommandLines;
|
class cmCustomCommandLines;
|
||||||
class cmGeneratorTarget;
|
class cmGeneratorTarget;
|
||||||
@@ -363,6 +364,9 @@ public:
|
|||||||
bool command_expand_lists = false, const std::string& job_pool = "",
|
bool command_expand_lists = false, const std::string& job_pool = "",
|
||||||
bool stdPipesUTF8 = false);
|
bool stdPipesUTF8 = false);
|
||||||
|
|
||||||
|
virtual std::vector<cmCustomCommandGenerator> MakeCustomCommandGenerators(
|
||||||
|
cmCustomCommand const& cc, std::string const& config);
|
||||||
|
|
||||||
std::vector<std::string> ExpandCustomCommandOutputPaths(
|
std::vector<std::string> ExpandCustomCommandOutputPaths(
|
||||||
cmCompiledGeneratorExpression const& cge, std::string const& config);
|
cmCompiledGeneratorExpression const& cge, std::string const& config);
|
||||||
std::vector<std::string> ExpandCustomCommandOutputGenex(
|
std::vector<std::string> ExpandCustomCommandOutputGenex(
|
||||||
|
@@ -575,20 +575,8 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool transformDepfile = false;
|
for (cmCustomCommandGenerator const& ccg :
|
||||||
auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116);
|
this->MakeCustomCommandGenerators(*cc, config)) {
|
||||||
switch (cmp0116) {
|
|
||||||
case cmPolicies::OLD:
|
|
||||||
case cmPolicies::WARN:
|
|
||||||
break;
|
|
||||||
case cmPolicies::REQUIRED_IF_USED:
|
|
||||||
case cmPolicies::REQUIRED_ALWAYS:
|
|
||||||
case cmPolicies::NEW:
|
|
||||||
transformDepfile = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmCustomCommandGenerator ccg(*cc, config, this, transformDepfile);
|
|
||||||
|
|
||||||
const std::vector<std::string>& outputs = ccg.GetOutputs();
|
const std::vector<std::string>& outputs = ccg.GetOutputs();
|
||||||
const std::vector<std::string>& byproducts = ccg.GetByproducts();
|
const std::vector<std::string>& byproducts = ccg.GetByproducts();
|
||||||
@@ -607,7 +595,8 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
|
|||||||
std::transform(outputs.begin(), outputs.end(), ninjaOutputs.begin(),
|
std::transform(outputs.begin(), outputs.end(), ninjaOutputs.begin(),
|
||||||
gg->MapToNinjaPath());
|
gg->MapToNinjaPath());
|
||||||
std::transform(byproducts.begin(), byproducts.end(),
|
std::transform(byproducts.begin(), byproducts.end(),
|
||||||
ninjaOutputs.begin() + outputs.size(), gg->MapToNinjaPath());
|
ninjaOutputs.begin() + outputs.size(),
|
||||||
|
gg->MapToNinjaPath());
|
||||||
|
|
||||||
for (std::string const& ninjaOutput : ninjaOutputs) {
|
for (std::string const& ninjaOutput : ninjaOutputs) {
|
||||||
gg->SeenCustomCommandOutput(ninjaOutput);
|
gg->SeenCustomCommandOutput(ninjaOutput);
|
||||||
@@ -635,7 +624,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
|
|||||||
|
|
||||||
std::string depfile = cc->GetDepfile();
|
std::string depfile = cc->GetDepfile();
|
||||||
if (!depfile.empty()) {
|
if (!depfile.empty()) {
|
||||||
switch (cmp0116) {
|
switch (this->GetPolicyStatus(cmPolicies::CMP0116)) {
|
||||||
case cmPolicies::WARN:
|
case cmPolicies::WARN:
|
||||||
if (this->GetCurrentBinaryDirectory() !=
|
if (this->GetCurrentBinaryDirectory() !=
|
||||||
this->GetBinaryDirectory() ||
|
this->GetBinaryDirectory() ||
|
||||||
@@ -667,6 +656,28 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
|
|||||||
ninjaDeps, orderOnlyDeps);
|
ninjaDeps, orderOnlyDeps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<cmCustomCommandGenerator>
|
||||||
|
cmLocalNinjaGenerator::MakeCustomCommandGenerators(cmCustomCommand const& cc,
|
||||||
|
std::string const& config)
|
||||||
|
{
|
||||||
|
bool transformDepfile = false;
|
||||||
|
switch (this->GetPolicyStatus(cmPolicies::CMP0116)) {
|
||||||
|
case cmPolicies::OLD:
|
||||||
|
case cmPolicies::WARN:
|
||||||
|
break;
|
||||||
|
case cmPolicies::REQUIRED_IF_USED:
|
||||||
|
case cmPolicies::REQUIRED_ALWAYS:
|
||||||
|
case cmPolicies::NEW:
|
||||||
|
transformDepfile = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<cmCustomCommandGenerator> ccgs;
|
||||||
|
ccgs.emplace_back(cc, config, this, transformDepfile);
|
||||||
|
return ccgs;
|
||||||
|
}
|
||||||
|
|
||||||
void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc,
|
void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc,
|
||||||
cmGeneratorTarget* target)
|
cmGeneratorTarget* target)
|
||||||
|
@@ -70,6 +70,9 @@ public:
|
|||||||
const std::string& fileConfig,
|
const std::string& fileConfig,
|
||||||
cmNinjaTargetDepends depends);
|
cmNinjaTargetDepends depends);
|
||||||
|
|
||||||
|
std::vector<cmCustomCommandGenerator> MakeCustomCommandGenerators(
|
||||||
|
cmCustomCommand const& cc, std::string const& config) override;
|
||||||
|
|
||||||
void AddCustomCommandTarget(cmCustomCommand const* cc,
|
void AddCustomCommandTarget(cmCustomCommand const* cc,
|
||||||
cmGeneratorTarget* target);
|
cmGeneratorTarget* target);
|
||||||
void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
|
void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
|
||||||
|
Reference in New Issue
Block a user