diff options
author | Daniel Eiband <daniel.eiband@brainlab.com> | 2019-09-12 23:00:36 +0200 |
---|---|---|
committer | Daniel Eiband <daniel.eiband@brainlab.com> | 2019-09-12 23:00:36 +0200 |
commit | 4fb29850ad325b70fb412d4fd596c0a0d627ae8b (patch) | |
tree | f9d79e5674c10160badf4cebc7e4b5d679d623d7 /Source | |
parent | 9602bcfc62d50d7bb302b02ae3b1f9afe941bae7 (diff) | |
download | cmake-4fb29850ad325b70fb412d4fd596c0a0d627ae8b.tar.gz |
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.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmAddCustomCommandCommand.cxx | 28 | ||||
-rw-r--r-- | Source/cmCustomCommand.cxx | 7 | ||||
-rw-r--r-- | Source/cmCustomCommand.h | 17 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudio8Generator.cxx | 9 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 16 | ||||
-rw-r--r-- | Source/cmMakefile.h | 2 | ||||
-rw-r--r-- | Source/cmQtAutoGenInitializer.cxx | 10 |
7 files changed, 41 insertions, 48 deletions
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index d2330e1675..2a0db45f86 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -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; diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index 7402eeb377..fc6718dcb2 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 102b1788e2..bb5a0edbd9 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 5e6010896a..18ff9ac50d 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 16cc453fdd..ec2e6460e7 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -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. diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 52464d641e..f9031c1f41 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; @@ -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, diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index d6916b06b4..54304c322c 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); |