summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2021-12-12 06:01:20 (GMT)
committerBrad King <brad.king@kitware.com>2021-12-14 15:48:43 (GMT)
commit780341f360773d7b3b766b835bd539f46397e0a6 (patch)
tree767cdbaa73a9b9c7c38a31ab962034f1386d918f
parenta6fa3fa136c291c36aefbc79b62995a63bf9107b (diff)
downloadCMake-780341f360773d7b3b766b835bd539f46397e0a6.zip
CMake-780341f360773d7b3b766b835bd539f46397e0a6.tar.gz
CMake-780341f360773d7b3b766b835bd539f46397e0a6.tar.bz2
cmCustomCommand: Track main dependency explicitly
Store the main dependency as the first entry in the dependency list plus a boolean member indicating its existence. Note that this slightly changes existing behavior: the main dependency was previously the last entry of the dependency list.
-rw-r--r--Source/cmAddCustomCommandCommand.cxx3
-rw-r--r--Source/cmCPluginAPI.cxx3
-rw-r--r--Source/cmCustomCommand.cxx24
-rw-r--r--Source/cmCustomCommand.h5
-rw-r--r--Source/cmFLTKWrapUICommand.cxx5
-rw-r--r--Source/cmGlobalVisualStudio8Generator.cxx5
-rw-r--r--Source/cmLocalGenerator.cxx28
-rw-r--r--Source/cmLocalGenerator.h4
-rw-r--r--Source/cmLocalVisualStudio7Generator.cxx8
-rw-r--r--Source/cmMakefile.cxx15
-rw-r--r--Source/cmMakefile.h2
-rw-r--r--Source/cmQTWrapCPPCommand.cxx3
-rw-r--r--Source/cmQTWrapUICommand.cxx7
-rw-r--r--Source/cmQtAutoGenInitializer.cxx12
14 files changed, 64 insertions, 60 deletions
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx
index 0798ed4..831e9c7 100644
--- a/Source/cmAddCustomCommandCommand.cxx
+++ b/Source/cmAddCustomCommandCommand.cxx
@@ -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;
diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx
index 9714e16..1b11f20 100644
--- a/Source/cmCPluginAPI.cxx
+++ b/Source/cmCPluginAPI.cxx
@@ -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,
diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx
index f009632..68c65bb 100644
--- a/Source/cmCustomCommand.cxx
+++ b/Source/cmCustomCommand.cxx
@@ -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;
diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h
index 5ae26dd..5533847 100644
--- a/Source/cmCustomCommand.h
+++ b/Source/cmCustomCommand.h
@@ -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;
};
diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx
index 47dd709..80c069f 100644
--- a/Source/cmFLTKWrapUICommand.cxx
+++ b/Source/cmFLTKWrapUICommand.cxx
@@ -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);
diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx
index 4e53dff..dbd2de9 100644
--- a/Source/cmGlobalVisualStudio8Generator.cxx
+++ b/Source/cmGlobalVisualStudio8Generator.cxx
@@ -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]);
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index a07e298..5b3aad3 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -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);
}
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 5793f29..c73cd62 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -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);
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx
index c40e33e..dc9dcc7 100644
--- a/Source/cmLocalVisualStudio7Generator.cxx
+++ b/Source/cmLocalVisualStudio7Generator.cxx
@@ -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.
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 950fa7b..cc687b1 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -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);
}
}
}
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index af18230..85988b8 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -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,
diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx
index b489944..58cf514 100644
--- a/Source/cmQTWrapCPPCommand.cxx
+++ b/Source/cmQTWrapCPPCommand.cxx
@@ -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));
}
}
diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx
index 4d65f33..8b2a42c 100644
--- a/Source/cmQTWrapUICommand.cxx
+++ b/Source/cmQTWrapUICommand.cxx
@@ -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));
}
}
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index c2a37fe..a01e6ae 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -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);