mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-31 10:50:16 -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 command_expand_lists = false;
|
||||
std::string implicit_depends_lang;
|
||||
cmCustomCommand::ImplicitDependsList implicit_depends;
|
||||
cmImplicitDependsList implicit_depends;
|
||||
|
||||
// Accumulate one command line at a time.
|
||||
cmCustomCommandLine currentLine;
|
||||
@@ -351,28 +351,10 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
|
||||
job_pool, command_expand_lists);
|
||||
} else if (target.empty()) {
|
||||
// Target is empty, use the output.
|
||||
mf.AddCustomCommandToOutput(output, byproducts, depends, main_dependency,
|
||||
commandLines, comment, working.c_str(), false,
|
||||
escapeOldStyle, 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;
|
||||
}
|
||||
}
|
||||
mf.AddCustomCommandToOutput(
|
||||
output, byproducts, depends, main_dependency, implicit_depends,
|
||||
commandLines, comment, working.c_str(), false, escapeOldStyle,
|
||||
uses_terminal, command_expand_lists, depfile, job_pool);
|
||||
} else if (!byproducts.empty()) {
|
||||
status.SetError("BYPRODUCTS may not be specified with SOURCE signatures");
|
||||
return false;
|
||||
|
||||
@@ -88,18 +88,17 @@ cmListFileBacktrace const& cmCustomCommand::GetBacktrace() const
|
||||
return this->Backtrace;
|
||||
}
|
||||
|
||||
cmCustomCommand::ImplicitDependsList const&
|
||||
cmCustomCommand::GetImplicitDepends() const
|
||||
cmImplicitDependsList const& cmCustomCommand::GetImplicitDepends() const
|
||||
{
|
||||
return this->ImplicitDepends;
|
||||
}
|
||||
|
||||
void cmCustomCommand::SetImplicitDepends(ImplicitDependsList const& l)
|
||||
void cmCustomCommand::SetImplicitDepends(cmImplicitDependsList const& l)
|
||||
{
|
||||
this->ImplicitDepends = l;
|
||||
}
|
||||
|
||||
void cmCustomCommand::AppendImplicitDepends(ImplicitDependsList const& l)
|
||||
void cmCustomCommand::AppendImplicitDepends(cmImplicitDependsList const& l)
|
||||
{
|
||||
cmAppend(this->ImplicitDepends, l);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,11 @@
|
||||
|
||||
class cmMakefile;
|
||||
|
||||
class cmImplicitDependsList
|
||||
: public std::vector<std::pair<std::string, std::string>>
|
||||
{
|
||||
};
|
||||
|
||||
/** \class cmCustomCommand
|
||||
* \brief A class to encapsulate a custom command
|
||||
*
|
||||
@@ -68,13 +73,9 @@ public:
|
||||
/** Backtrace of the command that created this custom command. */
|
||||
cmListFileBacktrace const& GetBacktrace() const;
|
||||
|
||||
using ImplicitDependsPair = std::pair<std::string, std::string>;
|
||||
class ImplicitDependsList : public std::vector<ImplicitDependsPair>
|
||||
{
|
||||
};
|
||||
void SetImplicitDepends(ImplicitDependsList const&);
|
||||
void AppendImplicitDepends(ImplicitDependsList const&);
|
||||
ImplicitDependsList const& GetImplicitDepends() const;
|
||||
void SetImplicitDepends(cmImplicitDependsList const&);
|
||||
void AppendImplicitDepends(cmImplicitDependsList const&);
|
||||
cmImplicitDependsList const& GetImplicitDepends() const;
|
||||
|
||||
/** Set/Get whether this custom command should be given access to the
|
||||
real console (if possible). */
|
||||
@@ -99,7 +100,7 @@ private:
|
||||
std::vector<std::string> Depends;
|
||||
cmCustomCommandLines CommandLines;
|
||||
cmListFileBacktrace Backtrace;
|
||||
ImplicitDependsList ImplicitDepends;
|
||||
cmImplicitDependsList ImplicitDepends;
|
||||
std::string Comment;
|
||||
std::string WorkingDirectory;
|
||||
std::string Depfile;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
#include "cmGlobalVisualStudio8Generator.h"
|
||||
|
||||
#include "cmCustomCommand.h"
|
||||
#include "cmDocumentationEntry.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGeneratorExpression.h"
|
||||
@@ -191,11 +192,13 @@ 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;
|
||||
std::vector<std::string> no_byproducts;
|
||||
std::string no_main_dependency;
|
||||
cmImplicitDependsList no_implicit_depends;
|
||||
if (cmSourceFile* file = mf->AddCustomCommandToOutput(
|
||||
stamps, no_byproducts, listFiles, no_main_dependency, commandLines,
|
||||
"Checking Build System", no_working_directory, true, false)) {
|
||||
stamps, no_byproducts, listFiles, no_main_dependency,
|
||||
no_implicit_depends, commandLines, "Checking Build System",
|
||||
no_working_directory, true, false)) {
|
||||
gt->AddSource(file->ResolveFullPath());
|
||||
} else {
|
||||
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>& byproducts,
|
||||
const std::vector<std::string>& depends, const std::string& main_dependency,
|
||||
const cmImplicitDependsList& implicit_depends,
|
||||
const cmCustomCommandLines& commandLines, const char* comment,
|
||||
const char* workingDir, bool replace, bool escapeOldStyle,
|
||||
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);
|
||||
cc->SetEscapeOldStyle(escapeOldStyle);
|
||||
cc->SetEscapeAllowMakeVars(true);
|
||||
cc->SetImplicitDepends(implicit_depends);
|
||||
cc->SetUsesTerminal(uses_terminal);
|
||||
cc->SetCommandExpandLists(command_expand_lists);
|
||||
cc->SetDepfile(depfile);
|
||||
@@ -1044,10 +1046,11 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
|
||||
std::vector<std::string> outputs;
|
||||
outputs.push_back(output);
|
||||
std::vector<std::string> no_byproducts;
|
||||
cmImplicitDependsList no_implicit_depends;
|
||||
return this->AddCustomCommandToOutput(
|
||||
outputs, no_byproducts, depends, main_dependency, commandLines, comment,
|
||||
workingDir, replace, escapeOldStyle, uses_terminal, command_expand_lists,
|
||||
depfile, job_pool);
|
||||
outputs, no_byproducts, depends, main_dependency, no_implicit_depends,
|
||||
commandLines, comment, workingDir, replace, escapeOldStyle, uses_terminal,
|
||||
command_expand_lists, depfile, job_pool);
|
||||
}
|
||||
|
||||
void cmMakefile::AddCustomCommandOldStyle(
|
||||
@@ -1181,11 +1184,12 @@ cmTarget* cmMakefile::AddUtilityCommand(
|
||||
std::vector<std::string> forced;
|
||||
forced.push_back(force);
|
||||
std::string no_main_dependency;
|
||||
cmImplicitDependsList no_implicit_depends;
|
||||
bool no_replace = false;
|
||||
this->AddCustomCommandToOutput(
|
||||
forced, byproducts, depends, no_main_dependency, commandLines, comment,
|
||||
workingDirectory, no_replace, escapeOldStyle, uses_terminal,
|
||||
command_expand_lists, /*depfile=*/"", job_pool);
|
||||
forced, byproducts, depends, no_main_dependency, no_implicit_depends,
|
||||
commandLines, comment, workingDirectory, no_replace, escapeOldStyle,
|
||||
uses_terminal, command_expand_lists, /*depfile=*/"", job_pool);
|
||||
cmSourceFile* sf = target->AddSourceCMP0049(force);
|
||||
|
||||
// The output is not actually created so mark it symbolic.
|
||||
|
||||
@@ -42,6 +42,7 @@ class cmExportBuildFileGenerator;
|
||||
class cmFunctionBlocker;
|
||||
class cmGeneratorExpressionEvaluationFile;
|
||||
class cmGlobalGenerator;
|
||||
class cmImplicitDependsList;
|
||||
class cmInstallGenerator;
|
||||
class cmMessenger;
|
||||
class cmSourceFile;
|
||||
@@ -166,6 +167,7 @@ public:
|
||||
const std::vector<std::string>& byproducts,
|
||||
const std::vector<std::string>& depends,
|
||||
const std::string& main_dependency,
|
||||
const cmImplicitDependsList& implicit_depends,
|
||||
const cmCustomCommandLines& commandLines, const char* comment,
|
||||
const char* workingDir, bool replace = false, bool escapeOldStyle = true,
|
||||
bool uses_terminal = false, bool command_expand_lists = false,
|
||||
|
||||
@@ -1166,10 +1166,12 @@ bool cmQtAutoGenInitializer::InitRccTargets()
|
||||
if (!this->Rcc.ExecutableTargetName.empty()) {
|
||||
ccDepends.push_back(this->Rcc.ExecutableTargetName);
|
||||
}
|
||||
makefile->AddCustomCommandToOutput(ccOutput, ccByproducts, ccDepends,
|
||||
/*main_dependency*/ std::string(),
|
||||
commandLines, ccComment.c_str(),
|
||||
this->Dir.Work.c_str());
|
||||
std::string no_main_dependency;
|
||||
cmImplicitDependsList no_implicit_depends;
|
||||
makefile->AddCustomCommandToOutput(
|
||||
ccOutput, ccByproducts, ccDepends, no_main_dependency,
|
||||
no_implicit_depends, commandLines, ccComment.c_str(),
|
||||
this->Dir.Work.c_str());
|
||||
}
|
||||
// Reconfigure when .qrc file changes
|
||||
makefile->AddCMakeDependFile(qrc.QrcFile);
|
||||
|
||||
Reference in New Issue
Block a user