mirror of
https://github.com/Kitware/CMake.git
synced 2026-03-09 01:09:30 -05:00
Merge topic 'custom-command-main-dependency'
780341f360 cmCustomCommand: Track main dependency explicitly
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6800
This commit is contained in:
@@ -335,9 +335,10 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
|
||||
} else if (target.empty()) {
|
||||
// Target is empty, use the output.
|
||||
cc->SetOutputs(output);
|
||||
cc->SetMainDependency(main_dependency);
|
||||
cc->SetDepends(depends);
|
||||
cc->SetImplicitDepends(implicit_depends);
|
||||
mf.AddCustomCommandToOutput(main_dependency, std::move(cc));
|
||||
mf.AddCustomCommandToOutput(std::move(cc));
|
||||
} else if (!byproducts.empty()) {
|
||||
status.SetError("BYPRODUCTS may not be specified with SOURCE signatures");
|
||||
return false;
|
||||
|
||||
@@ -302,9 +302,10 @@ static void CCONV cmAddCustomCommandToOutput(void* arg, const char* output,
|
||||
// Pass the call to the makefile instance.
|
||||
auto cc = cm::make_unique<cmCustomCommand>();
|
||||
cc->SetOutputs(output);
|
||||
cc->SetMainDependency(main_dependency);
|
||||
cc->SetDepends(depends2);
|
||||
cc->SetCommandLines(commandLines);
|
||||
mf->AddCustomCommandToOutput(main_dependency, std::move(cc));
|
||||
mf->AddCustomCommandToOutput(std::move(cc));
|
||||
}
|
||||
|
||||
static void CCONV cmAddCustomCommandToTarget(void* arg, const char* target,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#include "cmCustomCommand.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <utility>
|
||||
|
||||
#include <cmext/algorithm>
|
||||
@@ -38,9 +39,32 @@ const std::vector<std::string>& cmCustomCommand::GetDepends() const
|
||||
|
||||
void cmCustomCommand::SetDepends(std::vector<std::string> depends)
|
||||
{
|
||||
if (this->HasMainDependency_) {
|
||||
depends.insert(depends.begin(), std::move(this->Depends[0]));
|
||||
}
|
||||
|
||||
Depends = std::move(depends);
|
||||
}
|
||||
|
||||
const std::string& cmCustomCommand::GetMainDependency() const
|
||||
{
|
||||
assert(this->HasMainDependency_);
|
||||
return this->Depends[0];
|
||||
}
|
||||
|
||||
void cmCustomCommand::SetMainDependency(std::string main_dependency)
|
||||
{
|
||||
if (this->HasMainDependency_) {
|
||||
assert(!main_dependency.empty());
|
||||
this->Depends[0] = std::move(main_dependency);
|
||||
} else if (main_dependency.empty()) {
|
||||
// Do nothing.
|
||||
} else {
|
||||
this->Depends.insert(this->Depends.begin(), std::move(main_dependency));
|
||||
this->HasMainDependency_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
const cmCustomCommandLines& cmCustomCommand::GetCommandLines() const
|
||||
{
|
||||
return this->CommandLines;
|
||||
|
||||
@@ -38,6 +38,10 @@ public:
|
||||
const std::vector<std::string>& GetDepends() const;
|
||||
void SetDepends(std::vector<std::string> depends);
|
||||
|
||||
bool HasMainDependency() const { return this->HasMainDependency_; }
|
||||
const std::string& GetMainDependency() const;
|
||||
void SetMainDependency(std::string main_dependency);
|
||||
|
||||
/** Get the working directory. */
|
||||
std::string const& GetWorkingDirectory() const
|
||||
{
|
||||
@@ -130,5 +134,6 @@ private:
|
||||
bool UsesTerminal = false;
|
||||
bool CommandExpandLists = false;
|
||||
bool StdPipesUTF8 = false;
|
||||
bool HasMainDependency_ = false;
|
||||
cmPolicies::PolicyStatus CMP0116Status = cmPolicies::WARN;
|
||||
};
|
||||
|
||||
@@ -98,7 +98,6 @@ bool cmFLTKWrapUICommand(std::vector<std::string> const& args,
|
||||
});
|
||||
|
||||
// Add command for generating the .h and .cxx files
|
||||
std::string no_main_dependency;
|
||||
|
||||
auto hcc = cm::make_unique<cmCustomCommand>();
|
||||
hcc->SetDepends(depends);
|
||||
@@ -106,10 +105,10 @@ bool cmFLTKWrapUICommand(std::vector<std::string> const& args,
|
||||
auto ccc = cm::make_unique<cmCustomCommand>(*hcc);
|
||||
|
||||
hcc->SetOutputs(cxxres);
|
||||
mf.AddCustomCommandToOutput(no_main_dependency, std::move(hcc));
|
||||
mf.AddCustomCommandToOutput(std::move(hcc));
|
||||
|
||||
ccc->SetOutputs(hname);
|
||||
mf.AddCustomCommandToOutput(no_main_dependency, std::move(ccc));
|
||||
mf.AddCustomCommandToOutput(std::move(ccc));
|
||||
|
||||
cmSourceFile* sf = mf.GetSource(cxxres);
|
||||
sf->AddDepend(hname);
|
||||
|
||||
@@ -254,7 +254,6 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
|
||||
// file as the main dependency because it would get
|
||||
// overwritten by the CreateVCProjBuildRule.
|
||||
// (this could be avoided with per-target source files)
|
||||
std::string no_main_dependency;
|
||||
cc = cm::make_unique<cmCustomCommand>();
|
||||
cc->SetOutputs(stamps);
|
||||
cc->SetDepends(listFiles);
|
||||
@@ -263,8 +262,8 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
|
||||
cc->SetCMP0116Status(cmPolicies::NEW);
|
||||
cc->SetEscapeOldStyle(false);
|
||||
cc->SetStdPipesUTF8(stdPipesUTF8);
|
||||
if (cmSourceFile* file = lg.AddCustomCommandToOutput(
|
||||
no_main_dependency, std::move(cc), true)) {
|
||||
if (cmSourceFile* file =
|
||||
lg.AddCustomCommandToOutput(std::move(cc), true)) {
|
||||
gt->AddSource(file->ResolveFullPath());
|
||||
} else {
|
||||
cmSystemTools::Error("Error adding rule for " + stamps[0]);
|
||||
|
||||
@@ -1072,8 +1072,7 @@ cmTarget* cmLocalGenerator::AddCustomCommandToTarget(
|
||||
}
|
||||
|
||||
cmSourceFile* cmLocalGenerator::AddCustomCommandToOutput(
|
||||
const std::string& main_dependency, std::unique_ptr<cmCustomCommand> cc,
|
||||
bool replace)
|
||||
std::unique_ptr<cmCustomCommand> cc, bool replace)
|
||||
{
|
||||
// Make sure there is at least one output.
|
||||
if (cc->GetOutputs().empty()) {
|
||||
@@ -1083,8 +1082,7 @@ cmSourceFile* cmLocalGenerator::AddCustomCommandToOutput(
|
||||
|
||||
cc->SetBacktrace(this->DirectoryBacktrace);
|
||||
return detail::AddCustomCommandToOutput(*this, cmCommandOrigin::Generator,
|
||||
main_dependency, std::move(cc),
|
||||
replace);
|
||||
std::move(cc), replace);
|
||||
}
|
||||
|
||||
cmTarget* cmLocalGenerator::AddUtilityCommand(
|
||||
@@ -2724,7 +2722,6 @@ void cmLocalGenerator::CopyPchCompilePdb(
|
||||
configGenex(cmStrCat("-DPDB_PREFIX=", pdb_prefix)), configGenex("-P"),
|
||||
configGenex(copy_script) });
|
||||
|
||||
const std::string no_main_dependency;
|
||||
const char* no_message = "";
|
||||
|
||||
std::vector<std::string> outputs;
|
||||
@@ -2744,8 +2741,7 @@ void cmLocalGenerator::CopyPchCompilePdb(
|
||||
cmObjectLibraryCommands::Accept);
|
||||
} else {
|
||||
cc->SetOutputs(outputs);
|
||||
cmSourceFile* copy_rule =
|
||||
this->AddCustomCommandToOutput(no_main_dependency, std::move(cc));
|
||||
cmSourceFile* copy_rule = this->AddCustomCommandToOutput(std::move(cc));
|
||||
|
||||
if (copy_rule) {
|
||||
target->AddSource(copy_rule->ResolveFullPath());
|
||||
@@ -4011,7 +4007,6 @@ std::string ComputeCustomCommandRuleFileName(cmLocalGenerator& lg,
|
||||
}
|
||||
|
||||
cmSourceFile* AddCustomCommand(cmLocalGenerator& lg, cmCommandOrigin origin,
|
||||
const std::string& main_dependency,
|
||||
std::unique_ptr<cmCustomCommand> cc,
|
||||
bool replace)
|
||||
{
|
||||
@@ -4023,7 +4018,8 @@ cmSourceFile* AddCustomCommand(cmLocalGenerator& lg, cmCommandOrigin origin,
|
||||
|
||||
// Choose a source file on which to store the custom command.
|
||||
cmSourceFile* file = nullptr;
|
||||
if (!commandLines.empty() && !main_dependency.empty()) {
|
||||
if (!commandLines.empty() && cc->HasMainDependency()) {
|
||||
const auto& main_dependency = cc->GetMainDependency();
|
||||
// The main dependency was specified. Use it unless a different
|
||||
// custom command already used it.
|
||||
file = mf->GetSource(main_dependency);
|
||||
@@ -4073,11 +4069,6 @@ cmSourceFile* AddCustomCommand(cmLocalGenerator& lg, cmCommandOrigin origin,
|
||||
|
||||
// Attach the custom command to the file.
|
||||
if (file) {
|
||||
// Construct a complete list of dependencies.
|
||||
if (!main_dependency.empty()) {
|
||||
cc->AppendDepends({ main_dependency });
|
||||
}
|
||||
|
||||
cc->SetEscapeAllowMakeVars(true);
|
||||
|
||||
lg.AddSourceOutputs(file, outputs, cmLocalGenerator::OutputRole::Primary,
|
||||
@@ -4142,11 +4133,10 @@ void AddCustomCommandToTarget(cmLocalGenerator& lg, cmCommandOrigin origin,
|
||||
|
||||
cmSourceFile* AddCustomCommandToOutput(cmLocalGenerator& lg,
|
||||
cmCommandOrigin origin,
|
||||
const std::string& main_dependency,
|
||||
std::unique_ptr<cmCustomCommand> cc,
|
||||
bool replace)
|
||||
{
|
||||
return AddCustomCommand(lg, origin, main_dependency, std::move(cc), replace);
|
||||
return AddCustomCommand(lg, origin, std::move(cc), replace);
|
||||
}
|
||||
|
||||
void AppendCustomCommandToOutput(cmLocalGenerator& lg,
|
||||
@@ -4206,10 +4196,8 @@ void AddUtilityCommand(cmLocalGenerator& lg, cmCommandOrigin origin,
|
||||
lg.CreateUtilityOutput(target->GetName(), byproducts, lfbt);
|
||||
cc->SetOutputs(output);
|
||||
|
||||
std::string no_main_dependency;
|
||||
cmSourceFile* rule =
|
||||
AddCustomCommand(lg, origin, no_main_dependency, std::move(cc),
|
||||
/*replace=*/false);
|
||||
cmSourceFile* rule = AddCustomCommand(lg, origin, std::move(cc),
|
||||
/*replace=*/false);
|
||||
if (rule) {
|
||||
lg.AddTargetByproducts(target, byproducts, lfbt, origin);
|
||||
}
|
||||
|
||||
@@ -330,8 +330,7 @@ public:
|
||||
/**
|
||||
* Add a custom command to a source file.
|
||||
*/
|
||||
cmSourceFile* AddCustomCommandToOutput(const std::string& main_dependency,
|
||||
std::unique_ptr<cmCustomCommand> cc,
|
||||
cmSourceFile* AddCustomCommandToOutput(std::unique_ptr<cmCustomCommand> cc,
|
||||
bool replace = false);
|
||||
|
||||
/**
|
||||
@@ -683,7 +682,6 @@ void AddCustomCommandToTarget(cmLocalGenerator& lg, cmCommandOrigin origin,
|
||||
|
||||
cmSourceFile* AddCustomCommandToOutput(cmLocalGenerator& lg,
|
||||
cmCommandOrigin origin,
|
||||
const std::string& main_dependency,
|
||||
std::unique_ptr<cmCustomCommand> cc,
|
||||
bool replace);
|
||||
|
||||
|
||||
@@ -129,7 +129,6 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets()
|
||||
if (l->GetType() == cmStateEnums::GLOBAL_TARGET) {
|
||||
cmCustomCommandLines force_commands =
|
||||
cmMakeSingleCommandLine({ "cd", "." });
|
||||
std::string no_main_dependency;
|
||||
std::string force = cmStrCat(this->GetCurrentBinaryDirectory(),
|
||||
"/CMakeFiles/", l->GetName(), "_force");
|
||||
if (cmSourceFile* sf =
|
||||
@@ -141,8 +140,8 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets()
|
||||
cc->SetCommandLines(force_commands);
|
||||
cc->SetComment(" ");
|
||||
cc->SetCMP0116Status(cmPolicies::NEW);
|
||||
if (cmSourceFile* file = this->AddCustomCommandToOutput(
|
||||
no_main_dependency, std::move(cc), true)) {
|
||||
if (cmSourceFile* file =
|
||||
this->AddCustomCommandToOutput(std::move(cc), true)) {
|
||||
l->AddSource(file->ResolveFullPath());
|
||||
}
|
||||
}
|
||||
@@ -266,13 +265,14 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
|
||||
std::string comment = cmStrCat("Building Custom Rule ", makefileIn);
|
||||
auto cc = cm::make_unique<cmCustomCommand>();
|
||||
cc->SetOutputs(stampName);
|
||||
cc->SetMainDependency(makefileIn);
|
||||
cc->SetDepends(listFiles);
|
||||
cc->SetCommandLines(commandLines);
|
||||
cc->SetComment(comment.c_str());
|
||||
cc->SetCMP0116Status(cmPolicies::NEW);
|
||||
cc->SetEscapeOldStyle(false);
|
||||
cc->SetStdPipesUTF8(true);
|
||||
this->AddCustomCommandToOutput(makefileIn, std::move(cc), true);
|
||||
this->AddCustomCommandToOutput(std::move(cc), true);
|
||||
if (cmSourceFile* file = this->Makefile->GetSource(makefileIn)) {
|
||||
// Finalize the source file path now since we're adding this after
|
||||
// the generator validated all project-named sources.
|
||||
|
||||
@@ -1087,8 +1087,8 @@ cmTarget* cmMakefile::AddCustomCommandToTarget(
|
||||
}
|
||||
|
||||
void cmMakefile::AddCustomCommandToOutput(
|
||||
const std::string& main_dependency, std::unique_ptr<cmCustomCommand> cc,
|
||||
const CommandSourceCallback& callback, bool replace)
|
||||
std::unique_ptr<cmCustomCommand> cc, const CommandSourceCallback& callback,
|
||||
bool replace)
|
||||
{
|
||||
const auto& outputs = cc->GetOutputs();
|
||||
const auto& byproducts = cc->GetByproducts();
|
||||
@@ -1119,8 +1119,7 @@ void cmMakefile::AddCustomCommandToOutput(
|
||||
BacktraceGuard guard(this->Backtrace, lfbt);
|
||||
tcc->SetBacktrace(lfbt);
|
||||
cmSourceFile* sf = detail::AddCustomCommandToOutput(
|
||||
lg, cmCommandOrigin::Project, main_dependency, std::move(tcc),
|
||||
replace);
|
||||
lg, cmCommandOrigin::Project, std::move(tcc), replace);
|
||||
if (callback && sf) {
|
||||
callback(sf);
|
||||
}
|
||||
@@ -1178,19 +1177,17 @@ void cmMakefile::AddCustomCommandOldStyle(
|
||||
for (std::string const& output : outputs) {
|
||||
auto cc1 = cm::make_unique<cmCustomCommand>(*cc);
|
||||
cc1->SetOutputs(output);
|
||||
this->AddCustomCommandToOutput(source, std::move(cc1),
|
||||
addRuleFileToTarget);
|
||||
cc1->SetMainDependency(source);
|
||||
this->AddCustomCommandToOutput(std::move(cc1), addRuleFileToTarget);
|
||||
}
|
||||
} else {
|
||||
std::string no_main_dependency;
|
||||
cc->AppendDepends({ source });
|
||||
|
||||
// The source may not be a real file. Do not use a main dependency.
|
||||
for (std::string const& output : outputs) {
|
||||
auto cc1 = cm::make_unique<cmCustomCommand>(*cc);
|
||||
cc1->SetOutputs(output);
|
||||
this->AddCustomCommandToOutput(no_main_dependency, std::move(cc1),
|
||||
addRuleFileToTarget);
|
||||
this->AddCustomCommandToOutput(std::move(cc1), addRuleFileToTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ public:
|
||||
* Dispatch adding a custom command to a source file.
|
||||
*/
|
||||
void AddCustomCommandToOutput(
|
||||
const std::string& main_dependency, std::unique_ptr<cmCustomCommand> cc,
|
||||
std::unique_ptr<cmCustomCommand> cc,
|
||||
const CommandSourceCallback& callback = nullptr, bool replace = false);
|
||||
void AddCustomCommandOldStyle(const std::string& target,
|
||||
const std::vector<std::string>& outputs,
|
||||
|
||||
@@ -75,13 +75,12 @@ bool cmQTWrapCPPCommand(std::vector<std::string> const& args,
|
||||
depends.push_back(moc_exe);
|
||||
depends.push_back(hname);
|
||||
|
||||
std::string no_main_dependency;
|
||||
auto cc = cm::make_unique<cmCustomCommand>();
|
||||
cc->SetOutputs(newName);
|
||||
cc->SetDepends(depends);
|
||||
cc->SetCommandLines(commandLines);
|
||||
cc->SetComment("Qt Wrapped File");
|
||||
mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc));
|
||||
mf.AddCustomCommandToOutput(std::move(cc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,19 +88,18 @@ bool cmQTWrapUICommand(std::vector<std::string> const& args,
|
||||
|
||||
std::vector<std::string> depends;
|
||||
depends.push_back(uiName);
|
||||
std::string no_main_dependency;
|
||||
auto cc = cm::make_unique<cmCustomCommand>();
|
||||
cc->SetOutputs(hName);
|
||||
cc->SetDepends(depends);
|
||||
cc->SetCommandLines(hCommandLines);
|
||||
mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc));
|
||||
mf.AddCustomCommandToOutput(std::move(cc));
|
||||
|
||||
depends.push_back(hName);
|
||||
cc = cm::make_unique<cmCustomCommand>();
|
||||
cc->SetOutputs(cxxName);
|
||||
cc->SetDepends(depends);
|
||||
cc->SetCommandLines(cxxCommandLines);
|
||||
mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc));
|
||||
mf.AddCustomCommandToOutput(std::move(cc));
|
||||
|
||||
depends.clear();
|
||||
depends.push_back(hName);
|
||||
@@ -108,7 +107,7 @@ bool cmQTWrapUICommand(std::vector<std::string> const& args,
|
||||
cc->SetOutputs(mocName);
|
||||
cc->SetDepends(depends);
|
||||
cc->SetCommandLines(mocCommandLines);
|
||||
mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc));
|
||||
mf.AddCustomCommandToOutput(std::move(cc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1230,7 +1230,6 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
|
||||
|
||||
// Add a rule file to cause the target to build if a dependency has
|
||||
// changed, which will trigger the pre-build command to run autogen
|
||||
std::string no_main_dependency;
|
||||
auto cc = cm::make_unique<cmCustomCommand>();
|
||||
cc->SetOutputs(timestampFileGenex);
|
||||
cc->SetDepends(uicDependencies);
|
||||
@@ -1239,8 +1238,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
|
||||
cc->SetCMP0116Status(cmPolicies::NEW);
|
||||
cc->SetEscapeOldStyle(false);
|
||||
cc->SetStdPipesUTF8(stdPipesUTF8);
|
||||
this->LocalGen->AddCustomCommandToOutput(no_main_dependency,
|
||||
std::move(cc));
|
||||
this->LocalGen->AddCustomCommandToOutput(std::move(cc));
|
||||
}
|
||||
|
||||
// Add the pre-build command directly to bypass the OBJECT_LIBRARY
|
||||
@@ -1362,7 +1360,6 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
|
||||
{ cmSystemTools::GetCMakeCommand(), "-E", "touch", outputFile }));
|
||||
|
||||
this->AddGeneratedSource(outputFile, this->Moc);
|
||||
const std::string no_main_dependency;
|
||||
cc = cm::make_unique<cmCustomCommand>();
|
||||
cc->SetOutputs(outputFile);
|
||||
cc->SetByproducts(timestampByproducts);
|
||||
@@ -1374,8 +1371,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
|
||||
cc->SetEscapeOldStyle(false);
|
||||
cc->SetDepfile(this->AutogenTarget.DepFile);
|
||||
cc->SetStdPipesUTF8(stdPipesUTF8);
|
||||
this->LocalGen->AddCustomCommandToOutput(no_main_dependency,
|
||||
std::move(cc));
|
||||
this->LocalGen->AddCustomCommandToOutput(std::move(cc));
|
||||
|
||||
// Alter variables for the autogen target which now merely wraps the
|
||||
// custom command
|
||||
@@ -1524,12 +1520,10 @@ bool cmQtAutoGenInitializer::InitRccTargets()
|
||||
if (!this->Rcc.ExecutableTargetName.empty()) {
|
||||
ccDepends.push_back(this->Rcc.ExecutableTargetName);
|
||||
}
|
||||
std::string no_main_dependency;
|
||||
cc->SetOutputs(ccOutput);
|
||||
cc->SetByproducts(ccByproducts);
|
||||
cc->SetDepends(ccDepends);
|
||||
this->LocalGen->AddCustomCommandToOutput(no_main_dependency,
|
||||
std::move(cc));
|
||||
this->LocalGen->AddCustomCommandToOutput(std::move(cc));
|
||||
}
|
||||
// Reconfigure when .qrc file changes
|
||||
this->Makefile->AddCMakeDependFile(qrc.QrcFile);
|
||||
|
||||
Reference in New Issue
Block a user