summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-09-16 14:16:57 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-09-16 14:18:51 (GMT)
commit7c47894b459c0f71ebe32b64a619f290df6bcf44 (patch)
tree968b49e366e60ab1c0afe0849abd8dac6edeb1f4
parent1df2f8803b79c2e27d123de4f3f351bae824feef (diff)
parent5d28e361b709a781a131cb9d9da73f04484eff54 (diff)
downloadCMake-7c47894b459c0f71ebe32b64a619f290df6bcf44.zip
CMake-7c47894b459c0f71ebe32b64a619f290df6bcf44.tar.gz
CMake-7c47894b459c0f71ebe32b64a619f290df6bcf44.tar.bz2
Merge topic 'prepare-deferred-custom-command-creation'
5d28e361b7 add_custom_command: Move append functionality into class cmMakefile 4fb29850ad add_custom_command: Refactor setting implicit depends Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3810
-rw-r--r--Source/cmAddCustomCommandCommand.cxx40
-rw-r--r--Source/cmCustomCommand.cxx7
-rw-r--r--Source/cmCustomCommand.h17
-rw-r--r--Source/cmGlobalVisualStudio8Generator.cxx9
-rw-r--r--Source/cmMakefile.cxx33
-rw-r--r--Source/cmMakefile.h6
-rw-r--r--Source/cmQtAutoGenInitializer.cxx10
7 files changed, 65 insertions, 57 deletions
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx
index d7afb57..c91198c 100644
--- a/Source/cmAddCustomCommandCommand.cxx
+++ b/Source/cmAddCustomCommandCommand.cxx
@@ -12,7 +12,6 @@
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmPolicies.h"
-#include "cmSourceFile.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
@@ -50,7 +49,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;
@@ -316,14 +315,9 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
// Check for an append request.
if (append) {
- // Lookup an existing command.
- if (cmSourceFile* sf = mf.GetSourceFileWithOutput(output[0])) {
- if (cmCustomCommand* cc = sf->GetCustomCommand()) {
- cc->AppendCommands(commandLines);
- cc->AppendDepends(depends);
- cc->AppendImplicitDepends(implicit_depends);
- return true;
- }
+ if (mf.AppendCustomCommandToOutput(output[0], depends, implicit_depends,
+ commandLines)) {
+ return true;
}
// No command for this output exists.
@@ -350,28 +344,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;
diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx
index 7402eeb..fc6718d 100644
--- a/Source/cmCustomCommand.cxx
+++ b/Source/cmCustomCommand.cxx
@@ -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);
}
diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h
index 102b178..bb5a0ed 100644
--- a/Source/cmCustomCommand.h
+++ b/Source/cmCustomCommand.h
@@ -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;
diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx
index 5e60108..18ff9ac 100644
--- a/Source/cmGlobalVisualStudio8Generator.cxx
+++ b/Source/cmGlobalVisualStudio8Generator.cxx
@@ -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]);
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 9e64f97..caf4168 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -945,6 +945,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,
@@ -1029,6 +1030,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);
@@ -1087,10 +1089,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(
@@ -1151,6 +1154,23 @@ void cmMakefile::AddCustomCommandOldStyle(
}
}
+bool cmMakefile::AppendCustomCommandToOutput(
+ const std::string& output, const std::vector<std::string>& depends,
+ const cmImplicitDependsList& implicit_depends,
+ const cmCustomCommandLines& commandLines)
+{
+ // Lookup an existing command.
+ if (cmSourceFile* sf = this->GetSourceFileWithOutput(output)) {
+ if (cmCustomCommand* cc = sf->GetCustomCommand()) {
+ cc->AppendCommands(commandLines);
+ cc->AppendDepends(depends);
+ cc->AppendImplicitDepends(implicit_depends);
+ return true;
+ }
+ }
+ return false;
+}
+
cmTarget* cmMakefile::AddUtilityCommand(
const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
const std::vector<std::string>& depends, const char* workingDirectory,
@@ -1224,11 +1244,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.
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index dc9318b..e32e4b3 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -42,6 +42,7 @@ class cmExportBuildFileGenerator;
class cmFunctionBlocker;
class cmGeneratorExpressionEvaluationFile;
class cmGlobalGenerator;
+class cmImplicitDependsList;
class cmInstallGenerator;
class cmMessenger;
class cmSourceFile;
@@ -184,6 +185,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,
@@ -201,6 +203,10 @@ public:
const std::string& source,
const cmCustomCommandLines& commandLines,
const char* comment);
+ bool AppendCustomCommandToOutput(
+ const std::string& output, const std::vector<std::string>& depends,
+ const cmImplicitDependsList& implicit_depends,
+ const cmCustomCommandLines& commandLines);
/**
* Add a define flag to the build.
diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx
index d6916b0..54304c3 100644
--- a/Source/cmQtAutoGenInitializer.cxx
+++ b/Source/cmQtAutoGenInitializer.cxx
@@ -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);