diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2021-11-07 15:25:33 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-11-18 17:02:38 (GMT) |
commit | 3bb2542535fa2ca1e78195b69c53916a55d322e1 (patch) | |
tree | 807f1bb4f08bdca8360c4f76b0150cefb0490177 /Source | |
parent | c46b041a3bcede9447c36de2f3359eb4c17f3f50 (diff) | |
download | CMake-3bb2542535fa2ca1e78195b69c53916a55d322e1.zip CMake-3bb2542535fa2ca1e78195b69c53916a55d322e1.tar.gz CMake-3bb2542535fa2ca1e78195b69c53916a55d322e1.tar.bz2 |
cmMakefile: Simplify Add*Command and adopt to cmAddCustom*Command
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmAddCustomCommandCommand.cxx | 28 | ||||
-rw-r--r-- | Source/cmAddCustomTargetCommand.cxx | 20 | ||||
-rw-r--r-- | Source/cmCPluginAPI.cxx | 25 | ||||
-rw-r--r-- | Source/cmFLTKWrapUICommand.cxx | 21 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 126 | ||||
-rw-r--r-- | Source/cmMakefile.h | 44 | ||||
-rw-r--r-- | Source/cmQTWrapCPPCommand.cxx | 15 | ||||
-rw-r--r-- | Source/cmQTWrapUICommand.cxx | 28 |
8 files changed, 133 insertions, 174 deletions
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index ff2cc3e..0798ed4 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -4,6 +4,9 @@ #include <sstream> #include <unordered_set> +#include <utility> + +#include <cm/memory> #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" @@ -316,20 +319,25 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, } // Choose which mode of the command to use. - bool escapeOldStyle = !verbatim; + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetByproducts(byproducts); + cc->SetCommandLines(commandLines); + cc->SetComment(comment); + cc->SetWorkingDirectory(working.c_str()); + cc->SetEscapeOldStyle(!verbatim); + cc->SetUsesTerminal(uses_terminal); + cc->SetDepfile(depfile); + cc->SetJobPool(job_pool); + cc->SetCommandExpandLists(command_expand_lists); if (source.empty() && output.empty()) { // Source is empty, use the target. - std::vector<std::string> no_depends; - mf.AddCustomCommandToTarget(target, byproducts, no_depends, commandLines, - cctype, comment, working.c_str(), - escapeOldStyle, uses_terminal, depfile, - job_pool, command_expand_lists); + mf.AddCustomCommandToTarget(target, cctype, std::move(cc)); } else if (target.empty()) { // Target is empty, use the output. - mf.AddCustomCommandToOutput( - output, byproducts, depends, main_dependency, implicit_depends, - commandLines, comment, working.c_str(), nullptr, false, escapeOldStyle, - uses_terminal, command_expand_lists, depfile, job_pool); + cc->SetOutputs(output); + cc->SetDepends(depends); + cc->SetImplicitDepends(implicit_depends); + mf.AddCustomCommandToOutput(main_dependency, std::move(cc)); } else if (!byproducts.empty()) { status.SetError("BYPRODUCTS may not be specified with SOURCE signatures"); return false; diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index 104065f..a246d06 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -4,6 +4,9 @@ #include <utility> +#include <cm/memory> + +#include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" @@ -210,11 +213,18 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args, } // Add the utility target to the makefile. - bool escapeOldStyle = !verbatim; - cmTarget* target = mf.AddUtilityCommand( - targetName, excludeFromAll, working_directory.c_str(), byproducts, depends, - commandLines, escapeOldStyle, comment, uses_terminal, command_expand_lists, - job_pool); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetWorkingDirectory(working_directory.c_str()); + cc->SetByproducts(byproducts); + cc->SetDepends(depends); + cc->SetCommandLines(commandLines); + cc->SetEscapeOldStyle(!verbatim); + cc->SetComment(comment); + cc->SetUsesTerminal(uses_terminal); + cc->SetCommandExpandLists(command_expand_lists); + cc->SetJobPool(job_pool); + cmTarget* target = + mf.AddUtilityCommand(targetName, excludeFromAll, std::move(cc)); // Add additional user-specified source files to the target. target->AddSources(sources); diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 6f44739..9714e16 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -223,9 +223,10 @@ static void CCONV cmAddUtilityCommand(void* arg, const char* utilityName, } // Pass the call to the makefile instance. - std::vector<std::string> no_byproducts; - mf->AddUtilityCommand(utilityName, !all, nullptr, no_byproducts, depends2, - commandLines); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetDepends(depends2); + cc->SetCommandLines(commandLines); + mf->AddUtilityCommand(utilityName, !all, std::move(cc)); } static void CCONV cmAddCustomCommand(void* arg, const char* source, @@ -299,10 +300,11 @@ static void CCONV cmAddCustomCommandToOutput(void* arg, const char* output, } // Pass the call to the makefile instance. - const char* no_comment = nullptr; - const char* no_working_dir = nullptr; - mf->AddCustomCommandToOutput(output, depends2, main_dependency, commandLines, - no_comment, no_working_dir); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetOutputs(output); + cc->SetDepends(depends2); + cc->SetCommandLines(commandLines); + mf->AddCustomCommandToOutput(main_dependency, std::move(cc)); } static void CCONV cmAddCustomCommandToTarget(void* arg, const char* target, @@ -340,12 +342,9 @@ static void CCONV cmAddCustomCommandToTarget(void* arg, const char* target, } // Pass the call to the makefile instance. - std::vector<std::string> no_byproducts; - std::vector<std::string> no_depends; - const char* no_comment = nullptr; - const char* no_working_dir = nullptr; - mf->AddCustomCommandToTarget(target, no_byproducts, no_depends, commandLines, - cctype, no_comment, no_working_dir); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetCommandLines(commandLines); + mf->AddCustomCommandToTarget(target, cctype, std::move(cc)); } static void addLinkLibrary(cmMakefile* mf, std::string const& target, diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index d88617a..47dd709 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -3,7 +3,11 @@ #include "cmFLTKWrapUICommand.h" #include <cstddef> +#include <utility> +#include <cm/memory> + +#include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmListFileCache.h" @@ -95,12 +99,17 @@ bool cmFLTKWrapUICommand(std::vector<std::string> const& args, // Add command for generating the .h and .cxx files std::string no_main_dependency; - const char* no_comment = nullptr; - const char* no_working_dir = nullptr; - mf.AddCustomCommandToOutput(cxxres, depends, no_main_dependency, - commandLines, no_comment, no_working_dir); - mf.AddCustomCommandToOutput(hname, depends, no_main_dependency, - commandLines, no_comment, no_working_dir); + + auto hcc = cm::make_unique<cmCustomCommand>(); + hcc->SetDepends(depends); + hcc->SetCommandLines(commandLines); + auto ccc = cm::make_unique<cmCustomCommand>(*hcc); + + hcc->SetOutputs(cxxres); + mf.AddCustomCommandToOutput(no_main_dependency, std::move(hcc)); + + ccc->SetOutputs(hname); + mf.AddCustomCommandToOutput(no_main_dependency, std::move(ccc)); cmSourceFile* sf = mf.GetSource(cxxres); sf->AddDepend(hname); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5db57ef..fe56dec 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1054,13 +1054,12 @@ cmTarget* cmMakefile::GetCustomCommandTarget( } cmTarget* cmMakefile::AddCustomCommandToTarget( - const std::string& target, const std::vector<std::string>& byproducts, - const std::vector<std::string>& depends, - const cmCustomCommandLines& commandLines, cmCustomCommandType type, - const char* comment, const char* workingDir, bool escapeOldStyle, - bool uses_terminal, const std::string& depfile, const std::string& job_pool, - bool command_expand_lists, bool stdPipesUTF8) + const std::string& target, cmCustomCommandType type, + std::unique_ptr<cmCustomCommand> cc) { + const auto& byproducts = cc->GetByproducts(); + const auto& commandLines = cc->GetCommandLines(); + cmTarget* t = this->GetCustomCommandTarget( target, cmObjectLibraryCommands::Reject, this->Backtrace); @@ -1072,21 +1071,7 @@ cmTarget* cmMakefile::AddCustomCommandToTarget( // Always create the byproduct sources and mark them generated. this->CreateGeneratedOutputs(byproducts); - auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116); - - auto cc = cm::make_unique<cmCustomCommand>(); - cc->SetByproducts(byproducts); - cc->SetDepends(depends); - cc->SetCommandLines(commandLines); - cc->SetComment(comment); - cc->SetWorkingDirectory(workingDir); - cc->SetEscapeOldStyle(escapeOldStyle); - cc->SetUsesTerminal(uses_terminal); - cc->SetDepfile(depfile); - cc->SetJobPool(job_pool); - cc->SetCommandExpandLists(command_expand_lists); - cc->SetStdPipesUTF8(stdPipesUTF8); - cc->SetCMP0116Status(cmp0116); + cc->SetCMP0116Status(this->GetPolicyStatus(cmPolicies::CMP0116)); // Dispatch command creation to allow generator expressions in outputs. this->AddGeneratorAction( @@ -1103,31 +1088,13 @@ cmTarget* cmMakefile::AddCustomCommandToTarget( } void 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, - const CommandSourceCallback& callback, bool replace, bool escapeOldStyle, - bool uses_terminal, bool command_expand_lists, const std::string& depfile, - const std::string& job_pool, bool stdPipesUTF8) + const std::string& main_dependency, std::unique_ptr<cmCustomCommand> cc, + const CommandSourceCallback& callback, bool replace) { - std::vector<std::string> no_byproducts; - cmImplicitDependsList no_implicit_depends; - this->AddCustomCommandToOutput( - { output }, no_byproducts, depends, main_dependency, no_implicit_depends, - commandLines, comment, workingDir, callback, replace, escapeOldStyle, - uses_terminal, command_expand_lists, depfile, job_pool, stdPipesUTF8); -} + const auto& outputs = cc->GetOutputs(); + const auto& byproducts = cc->GetByproducts(); + const auto& commandLines = cc->GetCommandLines(); -void 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, const CommandSourceCallback& callback, bool replace, - bool escapeOldStyle, bool uses_terminal, bool command_expand_lists, - const std::string& depfile, const std::string& job_pool, bool stdPipesUTF8) -{ // Make sure there is at least one output. if (outputs.empty()) { cmSystemTools::Error("Attempt to add a custom rule with no output!"); @@ -1143,23 +1110,7 @@ void cmMakefile::AddCustomCommandToOutput( this->CreateGeneratedOutputs(outputs); this->CreateGeneratedOutputs(byproducts); - auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116); - - auto cc = cm::make_unique<cmCustomCommand>(); - cc->SetOutputs(outputs); - cc->SetByproducts(byproducts); - cc->SetDepends(depends); - cc->SetImplicitDepends(implicit_depends); - cc->SetCommandLines(commandLines); - cc->SetComment(comment); - cc->SetWorkingDirectory(workingDir); - cc->SetEscapeOldStyle(escapeOldStyle); - cc->SetUsesTerminal(uses_terminal); - cc->SetCommandExpandLists(command_expand_lists); - cc->SetDepfile(depfile); - cc->SetJobPool(job_pool); - cc->SetStdPipesUTF8(stdPipesUTF8); - cc->SetCMP0116Status(cmp0116); + cc->SetCMP0116Status(this->GetPolicyStatus(cmPolicies::CMP0116)); // Dispatch command creation to allow generator expressions in outputs. this->AddGeneratorAction( @@ -1182,16 +1133,19 @@ void cmMakefile::AddCustomCommandOldStyle( const std::vector<std::string>& depends, const std::string& source, const cmCustomCommandLines& commandLines, const char* comment) { + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetDepends(depends); + cc->SetCommandLines(commandLines); + cc->SetComment(comment); + // Translate the old-style signature to one of the new-style // signatures. if (source == target) { // In the old-style signature if the source and target were the // same then it added a post-build rule to the target. Preserve // this behavior. - std::vector<std::string> no_byproducts; - this->AddCustomCommandToTarget( - target, no_byproducts, depends, commandLines, - cmCustomCommandType::POST_BUILD, comment, nullptr); + this->AddCustomCommandToTarget(target, cmCustomCommandType::POST_BUILD, + std::move(cc)); return; } @@ -1223,18 +1177,20 @@ void cmMakefile::AddCustomCommandOldStyle( if (sourceFiles.find(source)) { // The source looks like a real file. Use it as the main dependency. for (std::string const& output : outputs) { - this->AddCustomCommandToOutput(output, depends, source, commandLines, - comment, nullptr, addRuleFileToTarget); + auto cc1 = cm::make_unique<cmCustomCommand>(*cc); + cc1->SetOutputs(output); + this->AddCustomCommandToOutput(source, std::move(cc1), + addRuleFileToTarget); } } else { std::string no_main_dependency; - std::vector<std::string> depends2 = depends; - depends2.push_back(source); + cc->AppendDepends({ source }); // The source may not be a real file. Do not use a main dependency. for (std::string const& output : outputs) { - this->AddCustomCommandToOutput(output, depends2, no_main_dependency, - commandLines, comment, nullptr, + auto cc1 = cm::make_unique<cmCustomCommand>(*cc); + cc1->SetOutputs(output); + this->AddCustomCommandToOutput(no_main_dependency, std::move(cc1), addRuleFileToTarget); } } @@ -1257,14 +1213,13 @@ void cmMakefile::AppendCustomCommandToOutput( } } -cmTarget* cmMakefile::AddUtilityCommand( - const std::string& utilityName, bool excludeFromAll, const char* workingDir, - const std::vector<std::string>& byproducts, - const std::vector<std::string>& depends, - const cmCustomCommandLines& commandLines, bool escapeOldStyle, - const char* comment, bool uses_terminal, bool command_expand_lists, - const std::string& job_pool, bool stdPipesUTF8) +cmTarget* cmMakefile::AddUtilityCommand(const std::string& utilityName, + bool excludeFromAll, + std::unique_ptr<cmCustomCommand> cc) { + const auto& depends = cc->GetDepends(); + const auto& byproducts = cc->GetByproducts(); + const auto& commandLines = cc->GetCommandLines(); cmTarget* target = this->AddNewUtilityTarget(utilityName, excludeFromAll); // Validate custom commands. @@ -1276,20 +1231,7 @@ cmTarget* cmMakefile::AddUtilityCommand( // Always create the byproduct sources and mark them generated. this->CreateGeneratedOutputs(byproducts); - auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116); - - auto cc = cm::make_unique<cmCustomCommand>(); - cc->SetWorkingDirectory(workingDir); - cc->SetByproducts(byproducts); - cc->SetDepends(depends); - cc->SetCommandLines(commandLines); - cc->SetEscapeOldStyle(escapeOldStyle); - cc->SetComment(comment); - cc->SetUsesTerminal(uses_terminal); - cc->SetCommandExpandLists(command_expand_lists); - cc->SetJobPool(job_pool); - cc->SetStdPipesUTF8(stdPipesUTF8); - cc->SetCMP0116Status(cmp0116); + cc->SetCMP0116Status(this->GetPolicyStatus(cmPolicies::CMP0116)); // Dispatch command creation to allow generator expressions in outputs. this->AddGeneratorAction( diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 82c17a1..af18230 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -199,14 +199,9 @@ public: * Dispatch adding a custom PRE_BUILD, PRE_LINK, or POST_BUILD command to a * target. */ - cmTarget* AddCustomCommandToTarget( - const std::string& target, const std::vector<std::string>& byproducts, - const std::vector<std::string>& depends, - const cmCustomCommandLines& commandLines, cmCustomCommandType type, - const char* comment, const char* workingDir, bool escapeOldStyle = true, - bool uses_terminal = false, const std::string& depfile = "", - const std::string& job_pool = "", bool command_expand_lists = false, - bool stdPipesUTF8 = false); + cmTarget* AddCustomCommandToTarget(const std::string& target, + cmCustomCommandType type, + std::unique_ptr<cmCustomCommand> cc); /** * Called for each file with custom command. @@ -217,26 +212,8 @@ public: * Dispatch adding a custom command to a source file. */ void 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, const CommandSourceCallback& callback = nullptr, - bool replace = false, bool escapeOldStyle = true, - bool uses_terminal = false, bool command_expand_lists = false, - const std::string& depfile = "", const std::string& job_pool = "", - bool stdPipesUTF8 = false); - void 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, const CommandSourceCallback& callback = nullptr, - bool replace = false, bool escapeOldStyle = true, - bool uses_terminal = false, bool command_expand_lists = false, - const std::string& depfile = "", const std::string& job_pool = "", - bool stdPipesUTF8 = false); + const std::string& main_dependency, std::unique_ptr<cmCustomCommand> cc, + const CommandSourceCallback& callback = nullptr, bool replace = false); void AddCustomCommandOldStyle(const std::string& target, const std::vector<std::string>& outputs, const std::vector<std::string>& depends, @@ -284,14 +261,9 @@ public: * Dispatch adding a utility to the build. A utility target is a command * that is run every time the target is built. */ - cmTarget* AddUtilityCommand( - const std::string& utilityName, bool excludeFromAll, - const char* workingDir, const std::vector<std::string>& byproducts, - const std::vector<std::string>& depends, - const cmCustomCommandLines& commandLines, bool escapeOldStyle = true, - const char* comment = nullptr, bool uses_terminal = false, - bool command_expand_lists = false, const std::string& job_pool = "", - bool stdPipesUTF8 = false); + cmTarget* AddUtilityCommand(const std::string& utilityName, + bool excludeFromAll, + std::unique_ptr<cmCustomCommand> cc); /** * Add a subdirectory to the build. diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx index cc4df8f..b489944 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -2,6 +2,11 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmQTWrapCPPCommand.h" +#include <utility> + +#include <cm/memory> + +#include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" @@ -71,10 +76,12 @@ bool cmQTWrapCPPCommand(std::vector<std::string> const& args, depends.push_back(hname); std::string no_main_dependency; - const char* no_working_dir = nullptr; - mf.AddCustomCommandToOutput(newName, depends, no_main_dependency, - commandLines, "Qt Wrapped File", - no_working_dir); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetOutputs(newName); + cc->SetDepends(depends); + cc->SetCommandLines(commandLines); + cc->SetComment("Qt Wrapped File"); + mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc)); } } diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx index 66c0228..4d65f33 100644 --- a/Source/cmQTWrapUICommand.cxx +++ b/Source/cmQTWrapUICommand.cxx @@ -2,6 +2,11 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmQTWrapUICommand.h" +#include <utility> + +#include <cm/memory> + +#include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" @@ -84,19 +89,26 @@ bool cmQTWrapUICommand(std::vector<std::string> const& args, std::vector<std::string> depends; depends.push_back(uiName); std::string no_main_dependency; - const char* no_comment = nullptr; - const char* no_working_dir = nullptr; - mf.AddCustomCommandToOutput(hName, depends, no_main_dependency, - hCommandLines, no_comment, no_working_dir); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetOutputs(hName); + cc->SetDepends(depends); + cc->SetCommandLines(hCommandLines); + mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc)); depends.push_back(hName); - mf.AddCustomCommandToOutput(cxxName, depends, no_main_dependency, - cxxCommandLines, no_comment, no_working_dir); + cc = cm::make_unique<cmCustomCommand>(); + cc->SetOutputs(cxxName); + cc->SetDepends(depends); + cc->SetCommandLines(cxxCommandLines); + mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc)); depends.clear(); depends.push_back(hName); - mf.AddCustomCommandToOutput(mocName, depends, no_main_dependency, - mocCommandLines, no_comment, no_working_dir); + cc = cm::make_unique<cmCustomCommand>(); + cc->SetOutputs(mocName); + cc->SetDepends(depends); + cc->SetCommandLines(mocCommandLines); + mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc)); } } |