diff options
author | Kulla Christoph <christoph.kulla@de.bosch.com> | 2016-08-05 12:39:31 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-08-30 13:05:18 (GMT) |
commit | 048d1adb4ede50e49dce00873a5961e424e149f9 (patch) | |
tree | 2f7ec3c0e5a773820c8cd74efa90c12124bbcce3 /Source | |
parent | 98caa14cc84cc659c2c5b51f84c6547b57c89c30 (diff) | |
download | CMake-048d1adb4ede50e49dce00873a5961e424e149f9.zip CMake-048d1adb4ede50e49dce00873a5961e424e149f9.tar.gz CMake-048d1adb4ede50e49dce00873a5961e424e149f9.tar.bz2 |
add_custom_command: Add DEPFILE option for Ninja
Provide a way for custom commands to inform the ninja build tool about
their implicit dependencies. For now simply make use of the option an
error on other generators.
Closes: #15479
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmAddCustomCommandCommand.cxx | 19 | ||||
-rw-r--r-- | Source/cmCustomCommand.cxx | 10 | ||||
-rw-r--r-- | Source/cmCustomCommand.h | 5 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 10 | ||||
-rw-r--r-- | Source/cmGlobalNinjaGenerator.h | 3 | ||||
-rw-r--r-- | Source/cmLocalNinjaGenerator.cxx | 3 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 10 | ||||
-rw-r--r-- | Source/cmMakefile.h | 18 | ||||
-rw-r--r-- | Source/cmNinjaUtilityTargetGenerator.cxx | 2 |
9 files changed, 56 insertions, 24 deletions
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index 400be77..2c4a4ca 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -15,6 +15,8 @@ #include "cmSourceFile.h" +#include "cmGlobalGenerator.h" + // cmAddCustomCommandCommand bool cmAddCustomCommandCommand::InitialPass( std::vector<std::string> const& args, cmExecutionStatus&) @@ -28,7 +30,7 @@ bool cmAddCustomCommandCommand::InitialPass( return false; } - std::string source, target, main_dependency, working; + std::string source, target, main_dependency, working, depfile; std::string comment_buffer; const char* comment = CM_NULLPTR; std::vector<std::string> depends, outputs, output, byproducts; @@ -60,6 +62,7 @@ bool cmAddCustomCommandCommand::InitialPass( doing_byproducts, doing_comment, doing_working_directory, + doing_depfile, doing_nothing }; @@ -110,6 +113,13 @@ bool cmAddCustomCommandCommand::InitialPass( doing = doing_implicit_depends_lang; } else if (copy == "COMMENT") { doing = doing_comment; + } else if (copy == "DEPFILE") { + doing = doing_depfile; + if (this->Makefile->GetGlobalGenerator()->GetName() != "Ninja") { + this->SetError("Option DEPFILE not supported by " + + this->Makefile->GetGlobalGenerator()->GetName()); + return false; + } } else { std::string filename; switch (doing) { @@ -147,6 +157,9 @@ bool cmAddCustomCommandCommand::InitialPass( filename = cmSystemTools::CollapseFullPath(filename); } switch (doing) { + case doing_depfile: + depfile = copy; + break; case doing_working_directory: working = copy; break; @@ -269,12 +282,12 @@ bool cmAddCustomCommandCommand::InitialPass( std::vector<std::string> no_depends; this->Makefile->AddCustomCommandToTarget( target, byproducts, no_depends, commandLines, cctype, comment, - working.c_str(), escapeOldStyle, uses_terminal); + working.c_str(), escapeOldStyle, uses_terminal, depfile); } else if (target.empty()) { // Target is empty, use the output. this->Makefile->AddCustomCommandToOutput( output, byproducts, depends, main_dependency, commandLines, comment, - working.c_str(), false, escapeOldStyle, uses_terminal); + working.c_str(), false, escapeOldStyle, uses_terminal, depfile); // Add implicit dependency scanning requests if any were given. if (!implicit_depends.empty()) { diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index 7533369..eaa49b0 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -135,3 +135,13 @@ void cmCustomCommand::SetUsesTerminal(bool b) { this->UsesTerminal = b; } + +const std::string& cmCustomCommand::GetDepfile() const +{ + return this->Depfile; +} + +void cmCustomCommand::SetDepfile(const std::string& depfile) +{ + this->Depfile = depfile; +} diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index c2b9738..34753f4 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -88,6 +88,10 @@ public: bool GetUsesTerminal() const; void SetUsesTerminal(bool b); + /** Set/Get the depfile (used by the Ninja generator) */ + const std::string& GetDepfile() const; + void SetDepfile(const std::string& depfile); + private: std::vector<std::string> Outputs; std::vector<std::string> Byproducts; @@ -97,6 +101,7 @@ private: ImplicitDependsList ImplicitDepends; std::string Comment; std::string WorkingDirectory; + std::string Depfile; bool HaveComment; bool EscapeAllowMakeVars; bool EscapeOldStyle; diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 2b83479..9bc8246 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -251,8 +251,8 @@ void cmGlobalNinjaGenerator::AddCustomCommandRule() void cmGlobalNinjaGenerator::WriteCustomCommandBuild( const std::string& command, const std::string& description, - const std::string& comment, bool uses_terminal, bool restat, - const cmNinjaDeps& outputs, const cmNinjaDeps& deps, + const std::string& comment, const std::string& depfile, bool uses_terminal, + bool restat, const cmNinjaDeps& outputs, const cmNinjaDeps& deps, const cmNinjaDeps& orderOnly) { std::string cmd = command; @@ -273,7 +273,9 @@ void cmGlobalNinjaGenerator::WriteCustomCommandBuild( if (uses_terminal && SupportsConsolePool()) { vars["pool"] = "console"; } - + if (!depfile.empty()) { + vars["depfile"] = depfile; + } this->WriteBuild(*this->BuildFileStream, comment, "CUSTOM_COMMAND", outputs, deps, cmNinjaDeps(), orderOnly, vars); @@ -839,7 +841,7 @@ void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies() std::copy(i->second.begin(), i->second.end(), std::back_inserter(deps)); WriteCustomCommandBuild(/*command=*/"", /*description=*/"", "Assume dependencies for generated source file.", - /*uses_terminal*/ false, + /*depfile*/ "", /*uses_terminal*/ false, /*restat*/ true, cmNinjaDeps(1, i->first), deps); } } diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h index 52fa5c9..082ee3a 100644 --- a/Source/cmGlobalNinjaGenerator.h +++ b/Source/cmGlobalNinjaGenerator.h @@ -113,7 +113,8 @@ public: void WriteCustomCommandBuild(const std::string& command, const std::string& description, - const std::string& comment, bool uses_terminal, + const std::string& comment, + const std::string& depfile, bool uses_terminal, bool restat, const cmNinjaDeps& outputs, const cmNinjaDeps& deps = cmNinjaDeps(), const cmNinjaDeps& orderOnly = cmNinjaDeps()); diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 46d7e18..4200e5d 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -412,7 +412,8 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( } else { this->GetGlobalNinjaGenerator()->WriteCustomCommandBuild( this->BuildCommandLine(cmdLines), this->ConstructComment(ccg), - "Custom command for " + ninjaOutputs[0], cc->GetUsesTerminal(), + "Custom command for " + ninjaOutputs[0], cc->GetDepfile(), + cc->GetUsesTerminal(), /*restat*/ !symbolic || !byproducts.empty(), ninjaOutputs, ninjaDeps, orderOnlyDeps); } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 6e47797..d1fddca 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -701,7 +701,7 @@ void cmMakefile::AddCustomCommandToTarget( const std::vector<std::string>& depends, const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type, const char* comment, const char* workingDir, bool escapeOldStyle, - bool uses_terminal) + bool uses_terminal, const std::string& depfile) { // Find the target to which to add the custom command. cmTargets::iterator ti = this->Targets.find(target); @@ -773,6 +773,7 @@ void cmMakefile::AddCustomCommandToTarget( cc.SetEscapeOldStyle(escapeOldStyle); cc.SetEscapeAllowMakeVars(true); cc.SetUsesTerminal(uses_terminal); + cc.SetDepfile(depfile); switch (type) { case cmTarget::PRE_BUILD: ti->second.AddPreBuildCommand(cc); @@ -792,7 +793,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( const std::vector<std::string>& depends, const std::string& main_dependency, const cmCustomCommandLines& commandLines, const char* comment, const char* workingDir, bool replace, bool escapeOldStyle, - bool uses_terminal) + bool uses_terminal, const std::string& depfile) { // Make sure there is at least one output. if (outputs.empty()) { @@ -886,6 +887,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( cc->SetEscapeOldStyle(escapeOldStyle); cc->SetEscapeAllowMakeVars(true); cc->SetUsesTerminal(uses_terminal); + cc->SetDepfile(depfile); file->SetCustomCommand(cc); this->UpdateOutputToSourceMap(outputs, file); } @@ -923,14 +925,14 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput( const std::string& output, const std::vector<std::string>& depends, const std::string& main_dependency, const cmCustomCommandLines& commandLines, const char* comment, const char* workingDir, bool replace, - bool escapeOldStyle, bool uses_terminal) + bool escapeOldStyle, bool uses_terminal, const std::string& depfile) { std::vector<std::string> outputs; outputs.push_back(output); std::vector<std::string> no_byproducts; return this->AddCustomCommandToOutput( outputs, no_byproducts, depends, main_dependency, commandLines, comment, - workingDir, replace, escapeOldStyle, uses_terminal); + workingDir, replace, escapeOldStyle, uses_terminal, depfile); } void cmMakefile::AddCustomCommandOldStyle( diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index b3587c5..4d137db 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -135,14 +135,12 @@ public: void FinalPass(); /** Add a custom command to the build. */ - void AddCustomCommandToTarget(const std::string& target, - const std::vector<std::string>& byproducts, - const std::vector<std::string>& depends, - const cmCustomCommandLines& commandLines, - cmTarget::CustomCommandType type, - const char* comment, const char* workingDir, - bool escapeOldStyle = true, - bool uses_terminal = false); + void AddCustomCommandToTarget( + const std::string& target, const std::vector<std::string>& byproducts, + const std::vector<std::string>& depends, + const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type, + const char* comment, const char* workingDir, bool escapeOldStyle = true, + bool uses_terminal = false, const std::string& depfile = ""); cmSourceFile* AddCustomCommandToOutput( const std::vector<std::string>& outputs, const std::vector<std::string>& byproducts, @@ -150,13 +148,13 @@ public: const std::string& main_dependency, const cmCustomCommandLines& commandLines, const char* comment, const char* workingDir, bool replace = false, bool escapeOldStyle = true, - bool uses_terminal = false); + bool uses_terminal = false, const std::string& depfile = ""); cmSourceFile* AddCustomCommandToOutput( const std::string& output, const std::vector<std::string>& depends, const std::string& main_dependency, const cmCustomCommandLines& commandLines, const char* comment, const char* workingDir, bool replace = false, bool escapeOldStyle = true, - bool uses_terminal = false); + bool uses_terminal = false, const std::string& depfile = ""); void AddCustomCommandOldStyle(const std::string& target, const std::vector<std::string>& outputs, const std::vector<std::string>& depends, diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx index 49836f2..0664104 100644 --- a/Source/cmNinjaUtilityTargetGenerator.cxx +++ b/Source/cmNinjaUtilityTargetGenerator.cxx @@ -150,7 +150,7 @@ void cmNinjaUtilityTargetGenerator::Generate() this->GetGlobalGenerator()->WriteCustomCommandBuild( command, desc, "Utility command for " + this->GetTargetName(), - uses_terminal, + /*depfile*/ "", uses_terminal, /*restat*/ true, util_outputs, deps); this->GetGlobalGenerator()->WritePhonyBuild( |