mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
add_custom_command: Refactor setting implicit depends
Implicit dependencies are now passed as argument to AddCustomCommandToOutput. This is necessary to be able to delay custom command creation.
This commit is contained in:
@@ -51,7 +51,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
|
|||||||
bool uses_terminal = false;
|
bool uses_terminal = false;
|
||||||
bool command_expand_lists = false;
|
bool command_expand_lists = false;
|
||||||
std::string implicit_depends_lang;
|
std::string implicit_depends_lang;
|
||||||
cmCustomCommand::ImplicitDependsList implicit_depends;
|
cmImplicitDependsList implicit_depends;
|
||||||
|
|
||||||
// Accumulate one command line at a time.
|
// Accumulate one command line at a time.
|
||||||
cmCustomCommandLine currentLine;
|
cmCustomCommandLine currentLine;
|
||||||
@@ -351,28 +351,10 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
|
|||||||
job_pool, command_expand_lists);
|
job_pool, command_expand_lists);
|
||||||
} else if (target.empty()) {
|
} else if (target.empty()) {
|
||||||
// Target is empty, use the output.
|
// Target is empty, use the output.
|
||||||
mf.AddCustomCommandToOutput(output, byproducts, depends, main_dependency,
|
mf.AddCustomCommandToOutput(
|
||||||
commandLines, comment, working.c_str(), false,
|
output, byproducts, depends, main_dependency, implicit_depends,
|
||||||
escapeOldStyle, uses_terminal,
|
commandLines, comment, working.c_str(), false, escapeOldStyle,
|
||||||
command_expand_lists, depfile, job_pool);
|
uses_terminal, command_expand_lists, depfile, job_pool);
|
||||||
|
|
||||||
// Add implicit dependency scanning requests if any were given.
|
|
||||||
if (!implicit_depends.empty()) {
|
|
||||||
bool okay = false;
|
|
||||||
if (cmSourceFile* sf = mf.GetSourceFileWithOutput(output[0])) {
|
|
||||||
if (cmCustomCommand* cc = sf->GetCustomCommand()) {
|
|
||||||
okay = true;
|
|
||||||
cc->SetImplicitDepends(implicit_depends);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!okay) {
|
|
||||||
std::ostringstream e;
|
|
||||||
e << "could not locate source file with a custom command producing \""
|
|
||||||
<< output[0] << "\" even though this command tried to create it!";
|
|
||||||
status.SetError(e.str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (!byproducts.empty()) {
|
} else if (!byproducts.empty()) {
|
||||||
status.SetError("BYPRODUCTS may not be specified with SOURCE signatures");
|
status.SetError("BYPRODUCTS may not be specified with SOURCE signatures");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -88,18 +88,17 @@ cmListFileBacktrace const& cmCustomCommand::GetBacktrace() const
|
|||||||
return this->Backtrace;
|
return this->Backtrace;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmCustomCommand::ImplicitDependsList const&
|
cmImplicitDependsList const& cmCustomCommand::GetImplicitDepends() const
|
||||||
cmCustomCommand::GetImplicitDepends() const
|
|
||||||
{
|
{
|
||||||
return this->ImplicitDepends;
|
return this->ImplicitDepends;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmCustomCommand::SetImplicitDepends(ImplicitDependsList const& l)
|
void cmCustomCommand::SetImplicitDepends(cmImplicitDependsList const& l)
|
||||||
{
|
{
|
||||||
this->ImplicitDepends = l;
|
this->ImplicitDepends = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmCustomCommand::AppendImplicitDepends(ImplicitDependsList const& l)
|
void cmCustomCommand::AppendImplicitDepends(cmImplicitDependsList const& l)
|
||||||
{
|
{
|
||||||
cmAppend(this->ImplicitDepends, l);
|
cmAppend(this->ImplicitDepends, l);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,11 @@
|
|||||||
|
|
||||||
class cmMakefile;
|
class cmMakefile;
|
||||||
|
|
||||||
|
class cmImplicitDependsList
|
||||||
|
: public std::vector<std::pair<std::string, std::string>>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
/** \class cmCustomCommand
|
/** \class cmCustomCommand
|
||||||
* \brief A class to encapsulate a custom command
|
* \brief A class to encapsulate a custom command
|
||||||
*
|
*
|
||||||
@@ -68,13 +73,9 @@ public:
|
|||||||
/** Backtrace of the command that created this custom command. */
|
/** Backtrace of the command that created this custom command. */
|
||||||
cmListFileBacktrace const& GetBacktrace() const;
|
cmListFileBacktrace const& GetBacktrace() const;
|
||||||
|
|
||||||
using ImplicitDependsPair = std::pair<std::string, std::string>;
|
void SetImplicitDepends(cmImplicitDependsList const&);
|
||||||
class ImplicitDependsList : public std::vector<ImplicitDependsPair>
|
void AppendImplicitDepends(cmImplicitDependsList const&);
|
||||||
{
|
cmImplicitDependsList const& GetImplicitDepends() const;
|
||||||
};
|
|
||||||
void SetImplicitDepends(ImplicitDependsList const&);
|
|
||||||
void AppendImplicitDepends(ImplicitDependsList const&);
|
|
||||||
ImplicitDependsList const& GetImplicitDepends() const;
|
|
||||||
|
|
||||||
/** Set/Get whether this custom command should be given access to the
|
/** Set/Get whether this custom command should be given access to the
|
||||||
real console (if possible). */
|
real console (if possible). */
|
||||||
@@ -99,7 +100,7 @@ private:
|
|||||||
std::vector<std::string> Depends;
|
std::vector<std::string> Depends;
|
||||||
cmCustomCommandLines CommandLines;
|
cmCustomCommandLines CommandLines;
|
||||||
cmListFileBacktrace Backtrace;
|
cmListFileBacktrace Backtrace;
|
||||||
ImplicitDependsList ImplicitDepends;
|
cmImplicitDependsList ImplicitDepends;
|
||||||
std::string Comment;
|
std::string Comment;
|
||||||
std::string WorkingDirectory;
|
std::string WorkingDirectory;
|
||||||
std::string Depfile;
|
std::string Depfile;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
#include "cmGlobalVisualStudio8Generator.h"
|
#include "cmGlobalVisualStudio8Generator.h"
|
||||||
|
|
||||||
|
#include "cmCustomCommand.h"
|
||||||
#include "cmDocumentationEntry.h"
|
#include "cmDocumentationEntry.h"
|
||||||
#include "cmGeneratedFileStream.h"
|
#include "cmGeneratedFileStream.h"
|
||||||
#include "cmGeneratorExpression.h"
|
#include "cmGeneratorExpression.h"
|
||||||
@@ -191,11 +192,13 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
|
|||||||
// file as the main dependency because it would get
|
// file as the main dependency because it would get
|
||||||
// overwritten by the CreateVCProjBuildRule.
|
// overwritten by the CreateVCProjBuildRule.
|
||||||
// (this could be avoided with per-target source files)
|
// (this could be avoided with per-target source files)
|
||||||
std::string no_main_dependency;
|
|
||||||
std::vector<std::string> no_byproducts;
|
std::vector<std::string> no_byproducts;
|
||||||
|
std::string no_main_dependency;
|
||||||
|
cmImplicitDependsList no_implicit_depends;
|
||||||
if (cmSourceFile* file = mf->AddCustomCommandToOutput(
|
if (cmSourceFile* file = mf->AddCustomCommandToOutput(
|
||||||
stamps, no_byproducts, listFiles, no_main_dependency, commandLines,
|
stamps, no_byproducts, listFiles, no_main_dependency,
|
||||||
"Checking Build System", no_working_directory, true, false)) {
|
no_implicit_depends, commandLines, "Checking Build System",
|
||||||
|
no_working_directory, true, false)) {
|
||||||
gt->AddSource(file->ResolveFullPath());
|
gt->AddSource(file->ResolveFullPath());
|
||||||
} else {
|
} else {
|
||||||
cmSystemTools::Error("Error adding rule for " + stamps[0]);
|
cmSystemTools::Error("Error adding rule for " + stamps[0]);
|
||||||
|
|||||||
@@ -914,6 +914,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
|
|||||||
const std::vector<std::string>& outputs,
|
const std::vector<std::string>& outputs,
|
||||||
const std::vector<std::string>& byproducts,
|
const std::vector<std::string>& byproducts,
|
||||||
const std::vector<std::string>& depends, const std::string& main_dependency,
|
const std::vector<std::string>& depends, const std::string& main_dependency,
|
||||||
|
const cmImplicitDependsList& implicit_depends,
|
||||||
const cmCustomCommandLines& commandLines, const char* comment,
|
const cmCustomCommandLines& commandLines, const char* comment,
|
||||||
const char* workingDir, bool replace, bool escapeOldStyle,
|
const char* workingDir, bool replace, bool escapeOldStyle,
|
||||||
bool uses_terminal, bool command_expand_lists, const std::string& depfile,
|
bool uses_terminal, bool command_expand_lists, const std::string& depfile,
|
||||||
@@ -998,6 +999,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
|
|||||||
this, outputs, byproducts, depends2, commandLines, comment, workingDir);
|
this, outputs, byproducts, depends2, commandLines, comment, workingDir);
|
||||||
cc->SetEscapeOldStyle(escapeOldStyle);
|
cc->SetEscapeOldStyle(escapeOldStyle);
|
||||||
cc->SetEscapeAllowMakeVars(true);
|
cc->SetEscapeAllowMakeVars(true);
|
||||||
|
cc->SetImplicitDepends(implicit_depends);
|
||||||
cc->SetUsesTerminal(uses_terminal);
|
cc->SetUsesTerminal(uses_terminal);
|
||||||
cc->SetCommandExpandLists(command_expand_lists);
|
cc->SetCommandExpandLists(command_expand_lists);
|
||||||
cc->SetDepfile(depfile);
|
cc->SetDepfile(depfile);
|
||||||
@@ -1044,10 +1046,11 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
|
|||||||
std::vector<std::string> outputs;
|
std::vector<std::string> outputs;
|
||||||
outputs.push_back(output);
|
outputs.push_back(output);
|
||||||
std::vector<std::string> no_byproducts;
|
std::vector<std::string> no_byproducts;
|
||||||
|
cmImplicitDependsList no_implicit_depends;
|
||||||
return this->AddCustomCommandToOutput(
|
return this->AddCustomCommandToOutput(
|
||||||
outputs, no_byproducts, depends, main_dependency, commandLines, comment,
|
outputs, no_byproducts, depends, main_dependency, no_implicit_depends,
|
||||||
workingDir, replace, escapeOldStyle, uses_terminal, command_expand_lists,
|
commandLines, comment, workingDir, replace, escapeOldStyle, uses_terminal,
|
||||||
depfile, job_pool);
|
command_expand_lists, depfile, job_pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmMakefile::AddCustomCommandOldStyle(
|
void cmMakefile::AddCustomCommandOldStyle(
|
||||||
@@ -1181,11 +1184,12 @@ cmTarget* cmMakefile::AddUtilityCommand(
|
|||||||
std::vector<std::string> forced;
|
std::vector<std::string> forced;
|
||||||
forced.push_back(force);
|
forced.push_back(force);
|
||||||
std::string no_main_dependency;
|
std::string no_main_dependency;
|
||||||
|
cmImplicitDependsList no_implicit_depends;
|
||||||
bool no_replace = false;
|
bool no_replace = false;
|
||||||
this->AddCustomCommandToOutput(
|
this->AddCustomCommandToOutput(
|
||||||
forced, byproducts, depends, no_main_dependency, commandLines, comment,
|
forced, byproducts, depends, no_main_dependency, no_implicit_depends,
|
||||||
workingDirectory, no_replace, escapeOldStyle, uses_terminal,
|
commandLines, comment, workingDirectory, no_replace, escapeOldStyle,
|
||||||
command_expand_lists, /*depfile=*/"", job_pool);
|
uses_terminal, command_expand_lists, /*depfile=*/"", job_pool);
|
||||||
cmSourceFile* sf = target->AddSourceCMP0049(force);
|
cmSourceFile* sf = target->AddSourceCMP0049(force);
|
||||||
|
|
||||||
// The output is not actually created so mark it symbolic.
|
// The output is not actually created so mark it symbolic.
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class cmExportBuildFileGenerator;
|
|||||||
class cmFunctionBlocker;
|
class cmFunctionBlocker;
|
||||||
class cmGeneratorExpressionEvaluationFile;
|
class cmGeneratorExpressionEvaluationFile;
|
||||||
class cmGlobalGenerator;
|
class cmGlobalGenerator;
|
||||||
|
class cmImplicitDependsList;
|
||||||
class cmInstallGenerator;
|
class cmInstallGenerator;
|
||||||
class cmMessenger;
|
class cmMessenger;
|
||||||
class cmSourceFile;
|
class cmSourceFile;
|
||||||
@@ -166,6 +167,7 @@ public:
|
|||||||
const std::vector<std::string>& byproducts,
|
const std::vector<std::string>& byproducts,
|
||||||
const std::vector<std::string>& depends,
|
const std::vector<std::string>& depends,
|
||||||
const std::string& main_dependency,
|
const std::string& main_dependency,
|
||||||
|
const cmImplicitDependsList& implicit_depends,
|
||||||
const cmCustomCommandLines& commandLines, const char* comment,
|
const cmCustomCommandLines& commandLines, const char* comment,
|
||||||
const char* workingDir, bool replace = false, bool escapeOldStyle = true,
|
const char* workingDir, bool replace = false, bool escapeOldStyle = true,
|
||||||
bool uses_terminal = false, bool command_expand_lists = false,
|
bool uses_terminal = false, bool command_expand_lists = false,
|
||||||
|
|||||||
@@ -1166,10 +1166,12 @@ bool cmQtAutoGenInitializer::InitRccTargets()
|
|||||||
if (!this->Rcc.ExecutableTargetName.empty()) {
|
if (!this->Rcc.ExecutableTargetName.empty()) {
|
||||||
ccDepends.push_back(this->Rcc.ExecutableTargetName);
|
ccDepends.push_back(this->Rcc.ExecutableTargetName);
|
||||||
}
|
}
|
||||||
makefile->AddCustomCommandToOutput(ccOutput, ccByproducts, ccDepends,
|
std::string no_main_dependency;
|
||||||
/*main_dependency*/ std::string(),
|
cmImplicitDependsList no_implicit_depends;
|
||||||
commandLines, ccComment.c_str(),
|
makefile->AddCustomCommandToOutput(
|
||||||
this->Dir.Work.c_str());
|
ccOutput, ccByproducts, ccDepends, no_main_dependency,
|
||||||
|
no_implicit_depends, commandLines, ccComment.c_str(),
|
||||||
|
this->Dir.Work.c_str());
|
||||||
}
|
}
|
||||||
// Reconfigure when .qrc file changes
|
// Reconfigure when .qrc file changes
|
||||||
makefile->AddCMakeDependFile(qrc.QrcFile);
|
makefile->AddCMakeDependFile(qrc.QrcFile);
|
||||||
|
|||||||
Reference in New Issue
Block a user