From d0158b765b0660bcfe304830e179fa9bbdffd5d9 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Wed, 3 Nov 2021 13:23:03 +0900 Subject: cmMakefile: Move CMP0116 lookup into Add{Custom,Utility}Command Avoid repeating it at every call site. --- Source/cmAddCustomCommandCommand.cxx | 14 +++++------- Source/cmAddCustomTargetCommand.cxx | 5 ++-- Source/cmCPluginAPI.cxx | 12 ++++------ Source/cmFLTKWrapUICommand.cxx | 7 ++---- Source/cmMakefile.cxx | 44 ++++++++++++++++++------------------ Source/cmMakefile.h | 34 +++++++++++++--------------- Source/cmQTWrapCPPCommand.cxx | 7 +++--- Source/cmQTWrapUICommand.cxx | 10 +++----- 8 files changed, 58 insertions(+), 75 deletions(-) diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index a7ce3a6..ff2cc3e 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -320,16 +320,15 @@ bool cmAddCustomCommandCommand(std::vector const& args, if (source.empty() && output.empty()) { // Source is empty, use the target. std::vector no_depends; - mf.AddCustomCommandToTarget( - target, byproducts, no_depends, commandLines, cctype, comment, - working.c_str(), mf.GetPolicyStatus(cmPolicies::CMP0116), escapeOldStyle, - uses_terminal, depfile, job_pool, command_expand_lists); + mf.AddCustomCommandToTarget(target, byproducts, no_depends, commandLines, + cctype, comment, working.c_str(), + escapeOldStyle, uses_terminal, depfile, + job_pool, command_expand_lists); } else if (target.empty()) { // Target is empty, use the output. mf.AddCustomCommandToOutput( output, byproducts, depends, main_dependency, implicit_depends, - commandLines, comment, working.c_str(), - mf.GetPolicyStatus(cmPolicies::CMP0116), nullptr, false, escapeOldStyle, + commandLines, comment, working.c_str(), nullptr, false, escapeOldStyle, uses_terminal, command_expand_lists, depfile, job_pool); } else if (!byproducts.empty()) { status.SetError("BYPRODUCTS may not be specified with SOURCE signatures"); @@ -366,8 +365,7 @@ bool cmAddCustomCommandCommand(std::vector const& args, // Use the old-style mode for backward compatibility. mf.AddCustomCommandOldStyle(target, outputs, depends, source, commandLines, - comment, - mf.GetPolicyStatus(cmPolicies::CMP0116)); + comment); } return true; diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index 2b19aad..104065f 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -10,7 +10,6 @@ #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" -#include "cmPolicies.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -214,8 +213,8 @@ bool cmAddCustomTargetCommand(std::vector const& args, bool escapeOldStyle = !verbatim; cmTarget* target = mf.AddUtilityCommand( targetName, excludeFromAll, working_directory.c_str(), byproducts, depends, - commandLines, mf.GetPolicyStatus(cmPolicies::CMP0116), escapeOldStyle, - comment, uses_terminal, command_expand_lists, job_pool); + commandLines, escapeOldStyle, comment, uses_terminal, command_expand_lists, + job_pool); // Add additional user-specified source files to the target. target->AddSources(sources); diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index c49347d..6f44739 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -225,8 +225,7 @@ static void CCONV cmAddUtilityCommand(void* arg, const char* utilityName, // Pass the call to the makefile instance. std::vector no_byproducts; mf->AddUtilityCommand(utilityName, !all, nullptr, no_byproducts, depends2, - commandLines, - mf->GetPolicyStatus(cmPolicies::CMP0116)); + commandLines); } static void CCONV cmAddCustomCommand(void* arg, const char* source, @@ -267,8 +266,7 @@ static void CCONV cmAddCustomCommand(void* arg, const char* source, // Pass the call to the makefile instance. const char* no_comment = nullptr; mf->AddCustomCommandOldStyle(target, outputs2, depends2, source, - commandLines, no_comment, - mf->GetPolicyStatus(cmPolicies::CMP0116)); + commandLines, no_comment); } static void CCONV cmAddCustomCommandToOutput(void* arg, const char* output, @@ -304,8 +302,7 @@ static void CCONV cmAddCustomCommandToOutput(void* arg, const char* output, const char* no_comment = nullptr; const char* no_working_dir = nullptr; mf->AddCustomCommandToOutput(output, depends2, main_dependency, commandLines, - no_comment, no_working_dir, - mf->GetPolicyStatus(cmPolicies::CMP0116)); + no_comment, no_working_dir); } static void CCONV cmAddCustomCommandToTarget(void* arg, const char* target, @@ -348,8 +345,7 @@ static void CCONV cmAddCustomCommandToTarget(void* arg, const char* target, 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, - mf->GetPolicyStatus(cmPolicies::CMP0116)); + cctype, no_comment, no_working_dir); } static void addLinkLibrary(cmMakefile* mf, std::string const& target, diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index 77d5795..d88617a 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -10,7 +10,6 @@ #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" -#include "cmPolicies.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" @@ -99,11 +98,9 @@ bool cmFLTKWrapUICommand(std::vector const& args, 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.GetPolicyStatus(cmPolicies::CMP0116)); + commandLines, no_comment, no_working_dir); mf.AddCustomCommandToOutput(hname, depends, no_main_dependency, - commandLines, no_comment, no_working_dir, - mf.GetPolicyStatus(cmPolicies::CMP0116)); + commandLines, no_comment, no_working_dir); cmSourceFile* sf = mf.GetSource(cxxres); sf->AddDepend(hname); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index bf3e217..e376323 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1059,9 +1059,8 @@ cmTarget* cmMakefile::AddCustomCommandToTarget( const std::string& target, const std::vector& byproducts, const std::vector& depends, const cmCustomCommandLines& commandLines, cmCustomCommandType type, - const char* comment, const char* workingDir, - cmPolicies::PolicyStatus cmp0116, bool escapeOldStyle, bool uses_terminal, - const std::string& depfile, const std::string& job_pool, + 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) { cmTarget* t = this->GetCustomCommandTarget( @@ -1075,6 +1074,8 @@ cmTarget* cmMakefile::AddCustomCommandToTarget( // Always create the byproduct sources and mark them generated. this->CreateGeneratedOutputs(byproducts); + auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116); + // Strings could be moved into the callback function with C++14. cm::optional commentStr = MakeOptionalString(comment); cm::optional workingStr = MakeOptionalString(workingDir); @@ -1097,18 +1098,16 @@ void cmMakefile::AddCustomCommandToOutput( const std::string& output, const std::vector& depends, const std::string& main_dependency, const cmCustomCommandLines& commandLines, const char* comment, const char* workingDir, - cmPolicies::PolicyStatus cmp0116, const CommandSourceCallback& callback, - bool replace, bool escapeOldStyle, bool uses_terminal, - bool command_expand_lists, const std::string& depfile, + 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) { std::vector no_byproducts; cmImplicitDependsList no_implicit_depends; this->AddCustomCommandToOutput( { output }, no_byproducts, depends, main_dependency, no_implicit_depends, - commandLines, comment, workingDir, cmp0116, callback, replace, - escapeOldStyle, uses_terminal, command_expand_lists, depfile, job_pool, - stdPipesUTF8); + commandLines, comment, workingDir, callback, replace, escapeOldStyle, + uses_terminal, command_expand_lists, depfile, job_pool, stdPipesUTF8); } void cmMakefile::AddCustomCommandToOutput( @@ -1117,10 +1116,9 @@ void cmMakefile::AddCustomCommandToOutput( const std::vector& depends, const std::string& main_dependency, const cmImplicitDependsList& implicit_depends, const cmCustomCommandLines& commandLines, const char* comment, - const char* workingDir, cmPolicies::PolicyStatus cmp0116, - 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 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()) { @@ -1137,6 +1135,8 @@ void cmMakefile::AddCustomCommandToOutput( this->CreateGeneratedOutputs(outputs); this->CreateGeneratedOutputs(byproducts); + auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116); + // Strings could be moved into the callback function with C++14. cm::optional commentStr = MakeOptionalString(comment); cm::optional workingStr = MakeOptionalString(workingDir); @@ -1160,8 +1160,7 @@ void cmMakefile::AddCustomCommandToOutput( void cmMakefile::AddCustomCommandOldStyle( const std::string& target, const std::vector& outputs, const std::vector& depends, const std::string& source, - const cmCustomCommandLines& commandLines, const char* comment, - cmPolicies::PolicyStatus cmp0116) + const cmCustomCommandLines& commandLines, const char* comment) { // Translate the old-style signature to one of the new-style // signatures. @@ -1172,7 +1171,7 @@ void cmMakefile::AddCustomCommandOldStyle( std::vector no_byproducts; this->AddCustomCommandToTarget( target, no_byproducts, depends, commandLines, - cmCustomCommandType::POST_BUILD, comment, nullptr, cmp0116); + cmCustomCommandType::POST_BUILD, comment, nullptr); return; } @@ -1205,8 +1204,7 @@ void cmMakefile::AddCustomCommandOldStyle( // 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, cmp0116, - addRuleFileToTarget); + comment, nullptr, addRuleFileToTarget); } } else { std::string no_main_dependency; @@ -1216,7 +1214,7 @@ void cmMakefile::AddCustomCommandOldStyle( // 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, cmp0116, + commandLines, comment, nullptr, addRuleFileToTarget); } } @@ -1243,9 +1241,9 @@ cmTarget* cmMakefile::AddUtilityCommand( const std::string& utilityName, bool excludeFromAll, const char* workingDir, const std::vector& byproducts, const std::vector& depends, - const cmCustomCommandLines& commandLines, cmPolicies::PolicyStatus cmp0116, - bool escapeOldStyle, const char* comment, bool uses_terminal, - bool command_expand_lists, const std::string& job_pool, bool stdPipesUTF8) + const cmCustomCommandLines& commandLines, bool escapeOldStyle, + const char* comment, bool uses_terminal, bool command_expand_lists, + const std::string& job_pool, bool stdPipesUTF8) { cmTarget* target = this->AddNewUtilityTarget(utilityName, excludeFromAll); @@ -1258,6 +1256,8 @@ cmTarget* cmMakefile::AddUtilityCommand( // Always create the byproduct sources and mark them generated. this->CreateGeneratedOutputs(byproducts); + auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116); + // Strings could be moved into the callback function with C++14. cm::optional commentStr = MakeOptionalString(comment); cm::optional workingStr = MakeOptionalString(workingDir); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 671cdab..c29fb00 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -169,8 +169,7 @@ public: const std::string& target, const std::vector& byproducts, const std::vector& depends, const cmCustomCommandLines& commandLines, cmCustomCommandType type, - const char* comment, const char* workingDir, - cmPolicies::PolicyStatus cmp0116, bool escapeOldStyle = true, + 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); @@ -187,11 +186,11 @@ public: const std::string& output, const std::vector& depends, const std::string& main_dependency, const cmCustomCommandLines& commandLines, const char* comment, - const char* workingDir, cmPolicies::PolicyStatus cmp0116, - 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 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& outputs, const std::vector& byproducts, @@ -199,18 +198,17 @@ public: const std::string& main_dependency, const cmImplicitDependsList& implicit_depends, const cmCustomCommandLines& commandLines, const char* comment, - const char* workingDir, cmPolicies::PolicyStatus cmp0116, - 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 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 AddCustomCommandOldStyle(const std::string& target, const std::vector& outputs, const std::vector& depends, const std::string& source, const cmCustomCommandLines& commandLines, - const char* comment, - cmPolicies::PolicyStatus cmp0116); + const char* comment); void AppendCustomCommandToOutput( const std::string& output, const std::vector& depends, const cmImplicitDependsList& implicit_depends, @@ -256,10 +254,10 @@ public: const std::string& utilityName, bool excludeFromAll, const char* workingDir, const std::vector& byproducts, const std::vector& depends, - const cmCustomCommandLines& commandLines, cmPolicies::PolicyStatus cmp0116, - bool escapeOldStyle = true, const char* comment = nullptr, - bool uses_terminal = false, bool command_expand_lists = false, - const std::string& job_pool = "", bool stdPipesUTF8 = false); + 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); /** * Add a subdirectory to the build. diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx index ca0b259..cc4df8f 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -5,7 +5,6 @@ #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" -#include "cmPolicies.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" @@ -73,9 +72,9 @@ bool cmQTWrapCPPCommand(std::vector const& args, 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, mf.GetPolicyStatus(cmPolicies::CMP0116)); + mf.AddCustomCommandToOutput(newName, depends, no_main_dependency, + commandLines, "Qt Wrapped File", + no_working_dir); } } diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx index f98f0b3..66c0228 100644 --- a/Source/cmQTWrapUICommand.cxx +++ b/Source/cmQTWrapUICommand.cxx @@ -5,7 +5,6 @@ #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" -#include "cmPolicies.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" @@ -88,19 +87,16 @@ bool cmQTWrapUICommand(std::vector const& args, const char* no_comment = nullptr; const char* no_working_dir = nullptr; mf.AddCustomCommandToOutput(hName, depends, no_main_dependency, - hCommandLines, no_comment, no_working_dir, - mf.GetPolicyStatus(cmPolicies::CMP0116)); + hCommandLines, no_comment, no_working_dir); depends.push_back(hName); mf.AddCustomCommandToOutput(cxxName, depends, no_main_dependency, - cxxCommandLines, no_comment, no_working_dir, - mf.GetPolicyStatus(cmPolicies::CMP0116)); + cxxCommandLines, no_comment, no_working_dir); depends.clear(); depends.push_back(hName); mf.AddCustomCommandToOutput(mocName, depends, no_main_dependency, - mocCommandLines, no_comment, no_working_dir, - mf.GetPolicyStatus(cmPolicies::CMP0116)); + mocCommandLines, no_comment, no_working_dir); } } -- cgit v0.12 From 9b31a977481ea07c979549246ee46946e9978e08 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Mon, 1 Nov 2021 23:19:05 +0900 Subject: cmCustomCommand: Move constructor arguments to individual setters Make `cmCustomCommand` have just only default constructor. Use each setter instead. This follows the builder pattern. Introduce `cc::SetOutputs(std::string output)`. This will be used later, as substitution for `cc::SetOutputs({output})`. --- Source/cmCustomCommand.cxx | 53 +++++++++++++++++++++----------- Source/cmCustomCommand.h | 24 ++++++++++----- Source/cmGlobalGenerator.cxx | 11 +++---- Source/cmGlobalVisualStudioGenerator.cxx | 10 ++++-- Source/cmGlobalXCodeGenerator.cxx | 11 ++++--- Source/cmLocalGenerator.cxx | 23 ++++++++++---- Source/cmLocalVisualStudioGenerator.cxx | 10 ++---- Source/cmQtAutoGenInitializer.cxx | 12 +++++--- 8 files changed, 95 insertions(+), 59 deletions(-) diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index ec60ff7..f009632 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -6,28 +6,19 @@ #include -cmCustomCommand::cmCustomCommand(std::vector outputs, - std::vector byproducts, - std::vector depends, - cmCustomCommandLines commandLines, - cmListFileBacktrace lfbt, const char* comment, - const char* workingDirectory, - bool stdPipesUTF8) - : Outputs(std::move(outputs)) - , Byproducts(std::move(byproducts)) - , Depends(std::move(depends)) - , CommandLines(std::move(commandLines)) - , Backtrace(std::move(lfbt)) - , Comment(comment ? comment : "") - , WorkingDirectory(workingDirectory ? workingDirectory : "") - , HaveComment(comment != nullptr) - , StdPipesUTF8(stdPipesUTF8) +const std::vector& cmCustomCommand::GetOutputs() const { + return this->Outputs; } -const std::vector& cmCustomCommand::GetOutputs() const +void cmCustomCommand::SetOutputs(std::vector outputs) { - return this->Outputs; + this->Outputs = std::move(outputs); +} + +void cmCustomCommand::SetOutputs(std::string output) +{ + this->Outputs = { std::move(output) }; } const std::vector& cmCustomCommand::GetByproducts() const @@ -35,22 +26,43 @@ const std::vector& cmCustomCommand::GetByproducts() const return this->Byproducts; } +void cmCustomCommand::SetByproducts(std::vector byproducts) +{ + this->Byproducts = std::move(byproducts); +} + const std::vector& cmCustomCommand::GetDepends() const { return this->Depends; } +void cmCustomCommand::SetDepends(std::vector depends) +{ + Depends = std::move(depends); +} + const cmCustomCommandLines& cmCustomCommand::GetCommandLines() const { return this->CommandLines; } +void cmCustomCommand::SetCommandLines(cmCustomCommandLines commandLines) +{ + this->CommandLines = std::move(commandLines); +} + const char* cmCustomCommand::GetComment() const { const char* no_comment = nullptr; return this->HaveComment ? this->Comment.c_str() : no_comment; } +void cmCustomCommand::SetComment(const char* comment) +{ + this->Comment = comment ? comment : ""; + this->HaveComment = (comment != nullptr); +} + void cmCustomCommand::AppendCommands(const cmCustomCommandLines& commandLines) { cm::append(this->CommandLines, commandLines); @@ -86,6 +98,11 @@ cmListFileBacktrace const& cmCustomCommand::GetBacktrace() const return this->Backtrace; } +void cmCustomCommand::SetBacktrace(cmListFileBacktrace lfbt) +{ + this->Backtrace = std::move(lfbt); +} + cmImplicitDependsList const& cmCustomCommand::GetImplicitDepends() const { return this->ImplicitDepends; diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index 5cbd3d1..5ae26dd 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -25,22 +25,18 @@ class cmImplicitDependsList class cmCustomCommand { public: - /** Main constructor specifies all information for the command. */ - cmCustomCommand(std::vector outputs, - std::vector byproducts, - std::vector depends, - cmCustomCommandLines commandLines, cmListFileBacktrace lfbt, - const char* comment, const char* workingDirectory, - bool stdPipesUTF8); - /** Get the output file produced by the command. */ const std::vector& GetOutputs() const; + void SetOutputs(std::vector outputs); + void SetOutputs(std::string output); /** Get the extra files produced by the command. */ const std::vector& GetByproducts() const; + void SetByproducts(std::vector byproducts); /** Get the vector that holds the list of dependencies. */ const std::vector& GetDepends() const; + void SetDepends(std::vector depends); /** Get the working directory. */ std::string const& GetWorkingDirectory() const @@ -48,14 +44,25 @@ public: return this->WorkingDirectory; } + void SetWorkingDirectory(const char* workingDirectory) + { + this->WorkingDirectory = (workingDirectory ? workingDirectory : ""); + } + /** Get the list of command lines. */ const cmCustomCommandLines& GetCommandLines() const; + void SetCommandLines(cmCustomCommandLines commandLines); /** Get the comment string for the command. */ const char* GetComment() const; + void SetComment(const char* comment); /** Get a value indicating if the command uses UTF-8 output pipes. */ bool GetStdPipesUTF8() const { return this->StdPipesUTF8; } + void SetStdPipesUTF8(bool stdPipesUTF8) + { + this->StdPipesUTF8 = stdPipesUTF8; + } /** Append to the list of command lines. */ void AppendCommands(const cmCustomCommandLines& commandLines); @@ -74,6 +81,7 @@ public: /** Backtrace of the command that created this custom command. */ cmListFileBacktrace const& GetBacktrace() const; + void SetBacktrace(cmListFileBacktrace lfbt); void SetImplicitDepends(cmImplicitDependsList const&); void AppendImplicitDepends(cmImplicitDependsList const&); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 94eec2e..b02dc29 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -38,7 +38,6 @@ #include "cmInstallGenerator.h" #include "cmInstallRuntimeDependencySet.h" #include "cmLinkLineComputer.h" -#include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMSVC60LinkLineComputer.h" #include "cmMakefile.h" @@ -2877,13 +2876,11 @@ void cmGlobalGenerator::CreateGlobalTarget(GlobalTargetInfo const& gti, cmTarget& target = tb.first; target.SetProperty("EXCLUDE_FROM_ALL", "TRUE"); - std::vector no_outputs; - std::vector no_byproducts; - std::vector no_depends; // Store the custom command in the target. - cmCustomCommand cc(no_outputs, no_byproducts, no_depends, gti.CommandLines, - cmListFileBacktrace(), nullptr, gti.WorkingDir.c_str(), - gti.StdPipesUTF8); + cmCustomCommand cc; + cc.SetCommandLines(gti.CommandLines); + cc.SetWorkingDirectory(gti.WorkingDir.c_str()); + cc.SetStdPipesUTF8(gti.StdPipesUTF8); cc.SetUsesTerminal(gti.UsesTerminal); target.AddPostBuildCommand(std::move(cc)); if (!gti.Message.empty()) { diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index f9bd67e..580c82b 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -942,9 +942,13 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand( cmCustomCommandLines commandLines = cmMakeSingleCommandLine( { cmakeCommand, "-E", "__create_def", mdi->DefFile, objs_file }); - cmCustomCommand command(outputs, empty, empty, commandLines, - gt->Target->GetMakefile()->GetBacktrace(), - "Auto build dll exports", ".", true); + cmCustomCommand command; + command.SetOutputs(outputs); + command.SetCommandLines(commandLines); + command.SetComment("Auto build dll exports"); + command.SetBacktrace(gt->Target->GetMakefile()->GetBacktrace()); + command.SetWorkingDirectory("."); + command.SetStdPipesUTF8(true); commands.push_back(std::move(command)); } diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 5b99945..a836f43 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1723,15 +1723,16 @@ void cmGlobalXCodeGenerator::CreateCustomCommands( cmStrCat("$GetName(), '>'); std::string str_link_file = cmStrCat("$GetName(), '>'); - bool stdPipesUTF8 = true; cmCustomCommandLines cmd = cmMakeSingleCommandLine( { cmSystemTools::GetCMakeCommand(), "-E", "cmake_symlink_library", str_file, str_so_file, str_link_file }); - cmCustomCommand command( - std::vector(), std::vector(), - std::vector(), cmd, this->CurrentMakefile->GetBacktrace(), - "Creating symlinks", "", stdPipesUTF8); + cmCustomCommand command; + command.SetCommandLines(cmd); + command.SetComment("Creating symlinks"); + command.SetWorkingDirectory(""); + command.SetBacktrace(this->CurrentMakefile->GetBacktrace()); + command.SetStdPipesUTF8(true); postbuild.push_back(std::move(command)); } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index c106137..d1f642f 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -4123,9 +4123,15 @@ cmSourceFile* AddCustomCommand( depends2.push_back(main_dependency); } - std::unique_ptr cc = cm::make_unique( - outputs, byproducts, depends2, commandLines, lfbt, comment, workingDir, - stdPipesUTF8); + std::unique_ptr cc = cm::make_unique(); + cc->SetByproducts(byproducts); + cc->SetDepends(std::move(depends2)); + cc->SetOutputs(outputs); + cc->SetCommandLines(commandLines); + cc->SetComment(comment); + cc->SetBacktrace(lfbt); + cc->SetWorkingDirectory(workingDir); + cc->SetStdPipesUTF8(stdPipesUTF8); cc->SetEscapeOldStyle(escapeOldStyle); cc->SetEscapeAllowMakeVars(true); cc->SetImplicitDepends(implicit_depends); @@ -4182,9 +4188,14 @@ void AddCustomCommandToTarget(cmLocalGenerator& lg, cmPolicies::PolicyStatus cmp0116) { // Add the command to the appropriate build step for the target. - std::vector no_output; - cmCustomCommand cc(no_output, byproducts, depends, commandLines, lfbt, - comment, workingDir, stdPipesUTF8); + cmCustomCommand cc; + cc.SetByproducts(byproducts); + cc.SetDepends(depends); + cc.SetCommandLines(commandLines); + cc.SetComment(comment); + cc.SetBacktrace(lfbt); + cc.SetWorkingDirectory(workingDir); + cc.SetStdPipesUTF8(stdPipesUTF8); cc.SetEscapeOldStyle(escapeOldStyle); cc.SetEscapeAllowMakeVars(true); cc.SetUsesTerminal(uses_terminal); diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index 4ed1dd9..3e23f35 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -99,15 +99,11 @@ cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmGeneratorTarget* target, } // Add a pre-build event to create the directory. - std::vector no_output; - std::vector no_byproducts; - std::vector no_depends; - bool stdPipesUTF8 = true; cmCustomCommandLines commands = cmMakeSingleCommandLine( { cmSystemTools::GetCMakeCommand(), "-E", "make_directory", impDir }); - pcc.reset(new cmCustomCommand(no_output, no_byproducts, no_depends, commands, - cmListFileBacktrace(), nullptr, nullptr, - stdPipesUTF8)); + pcc.reset(new cmCustomCommand()); + pcc->SetCommandLines(commands); + pcc->SetStdPipesUTF8(true); pcc->SetEscapeOldStyle(false); pcc->SetEscapeAllowMakeVars(true); return pcc; diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index c49cafe..e124758 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1246,11 +1246,13 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case. // // PRE_BUILD does not support file dependencies! - const std::vector no_output; - const std::vector no_deps; - cmCustomCommand cc(no_output, autogenByproducts, no_deps, commandLines, - this->Makefile->GetBacktrace(), autogenComment.c_str(), - this->Dir.Work.c_str(), stdPipesUTF8); + cmCustomCommand cc; + cc.SetByproducts(autogenByproducts); + cc.SetCommandLines(commandLines); + cc.SetComment(autogenComment.c_str()); + cc.SetBacktrace(this->Makefile->GetBacktrace()); + cc.SetWorkingDirectory(this->Dir.Work.c_str()); + cc.SetStdPipesUTF8(stdPipesUTF8); cc.SetEscapeOldStyle(false); cc.SetEscapeAllowMakeVars(true); this->GenTarget->Target->AddPreBuildCommand(std::move(cc)); -- cgit v0.12 From 90e1206f253c0acbef37668403133585a31b2a92 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 14 Nov 2021 10:19:28 +0900 Subject: cmMakefile: Introduce GeneratorAction as the class. --- Source/cmMakefile.cxx | 10 ++++++++-- Source/cmMakefile.h | 27 ++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index e376323..e84e474 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -891,12 +891,18 @@ struct file_not_persistent }; } -void cmMakefile::AddGeneratorAction(GeneratorAction action) +void cmMakefile::AddGeneratorAction(GeneratorAction&& action) { assert(!this->GeneratorActionsInvoked); this->GeneratorActions.emplace_back(std::move(action), this->Backtrace); } +void cmMakefile::GeneratorAction::operator()(cmLocalGenerator& lg, + const cmListFileBacktrace& lfbt) +{ + Action(lg, lfbt); +} + void cmMakefile::DoGenerate(cmLocalGenerator& lg) { // do all the variable expansions here @@ -904,7 +910,7 @@ void cmMakefile::DoGenerate(cmLocalGenerator& lg) // give all the commands a chance to do something // after the file has been parsed before generation - for (const BT& action : this->GeneratorActions) { + for (auto& action : this->GeneratorActions) { action.Value(lg, action.Backtrace); } this->GeneratorActionsInvoked = true; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index c29fb00..75412d7 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -140,13 +140,34 @@ public: bool EnforceUniqueName(std::string const& name, std::string& msg, bool isCustom = false) const; - using GeneratorAction = - std::function; + class GeneratorAction + { + using ActionT = + std::function; + + public: + GeneratorAction(ActionT&& action) + : Action(std::move(action)) + { + } + + void operator()(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt); + + private: + ActionT Action; + }; /** * Register an action that is executed during Generate */ - void AddGeneratorAction(GeneratorAction action); + void AddGeneratorAction(GeneratorAction&& action); + + /// Helper to insert the constructor GeneratorAction(args...) + template + void AddGeneratorAction(Args&&... args) + { + AddGeneratorAction(GeneratorAction(std::move(args)...)); + } /** * Perform generate actions, Library dependency analysis etc before output of -- cgit v0.12 From e37511ae7eb68a46fb9edb9f00d3fc179f713e45 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 14 Nov 2021 17:22:33 +0900 Subject: cmMakefile: Simplify detail:::Add{Custom,Utility}Command Note 1: `detail::AddCustomCommandToTarget()` resets cc, since cc is not moved away. Note 2: In `detail::AddUtilityCommand()`, a few vars are preserved before using. Their refs will be alive in most cases, but cc might be destroyed in the future. --- Source/cmLocalGenerator.cxx | 206 ++++++++++++++++++++------------------------ Source/cmLocalGenerator.h | 45 +++------- Source/cmMakefile.cxx | 105 +++++++++++++--------- Source/cmMakefile.h | 15 +++- 4 files changed, 183 insertions(+), 188 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index d1f642f..98f8fcc 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1072,11 +1072,22 @@ cmTarget* cmLocalGenerator::AddCustomCommandToTarget( return nullptr; } - detail::AddCustomCommandToTarget( - *this, this->DirectoryBacktrace, cmCommandOrigin::Generator, t, byproducts, - depends, commandLines, type, comment, workingDir, escapeOldStyle, - uses_terminal, depfile, job_pool, command_expand_lists, stdPipesUTF8, - cmp0116); + auto cc = cm::make_unique(); + cc->SetBacktrace(this->DirectoryBacktrace); + 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); + detail::AddCustomCommandToTarget(*this, cmCommandOrigin::Generator, t, type, + std::move(cc)); return t; } @@ -1113,11 +1124,25 @@ cmSourceFile* cmLocalGenerator::AddCustomCommandToOutput( return nullptr; } - return detail::AddCustomCommandToOutput( - *this, this->DirectoryBacktrace, cmCommandOrigin::Generator, outputs, - byproducts, depends, main_dependency, implicit_depends, commandLines, - comment, workingDir, replace, escapeOldStyle, uses_terminal, - command_expand_lists, depfile, job_pool, stdPipesUTF8, cmp0116); + auto cc = cm::make_unique(); + cc->SetBacktrace(this->DirectoryBacktrace); + 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); + return detail::AddCustomCommandToOutput(*this, cmCommandOrigin::Generator, + main_dependency, std::move(cc), + replace); } cmTarget* cmLocalGenerator::AddUtilityCommand( @@ -1136,10 +1161,21 @@ cmTarget* cmLocalGenerator::AddUtilityCommand( return target; } - detail::AddUtilityCommand( - *this, this->DirectoryBacktrace, cmCommandOrigin::Generator, target, - workingDir, byproducts, depends, commandLines, escapeOldStyle, comment, - uses_terminal, command_expand_lists, job_pool, stdPipesUTF8, cmp0116); + auto cc = cm::make_unique(); + cc->SetBacktrace(this->DirectoryBacktrace); + 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); + detail::AddUtilityCommand(*this, cmCommandOrigin::Generator, target, + std::move(cc)); return target; } @@ -4051,19 +4087,16 @@ std::string ComputeCustomCommandRuleFileName(cmLocalGenerator& lg, h.HashString(output).substr(0, 16)); } -cmSourceFile* AddCustomCommand( - cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, const std::vector& outputs, - const std::vector& byproducts, - const std::vector& 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, - const std::string& job_pool, bool stdPipesUTF8, - cmPolicies::PolicyStatus cmp0116) +cmSourceFile* AddCustomCommand(cmLocalGenerator& lg, cmCommandOrigin origin, + const std::string& main_dependency, + std::unique_ptr cc, + bool replace) { cmMakefile* mf = lg.GetMakefile(); + const auto& lfbt = cc->GetBacktrace(); + const auto& outputs = cc->GetOutputs(); + const auto& byproducts = cc->GetByproducts(); + const auto& commandLines = cc->GetCommandLines(); // Choose a source file on which to store the custom command. cmSourceFile* file = nullptr; @@ -4118,34 +4151,18 @@ cmSourceFile* AddCustomCommand( // Attach the custom command to the file. if (file) { // Construct a complete list of dependencies. - std::vector depends2(depends); if (!main_dependency.empty()) { - depends2.push_back(main_dependency); - } - - std::unique_ptr cc = cm::make_unique(); - cc->SetByproducts(byproducts); - cc->SetDepends(std::move(depends2)); - cc->SetOutputs(outputs); - cc->SetCommandLines(commandLines); - cc->SetComment(comment); - cc->SetBacktrace(lfbt); - cc->SetWorkingDirectory(workingDir); - cc->SetStdPipesUTF8(stdPipesUTF8); - cc->SetEscapeOldStyle(escapeOldStyle); + cc->AppendDepends({ main_dependency }); + } + cc->SetEscapeAllowMakeVars(true); - cc->SetImplicitDepends(implicit_depends); - cc->SetUsesTerminal(uses_terminal); - cc->SetCommandExpandLists(command_expand_lists); - cc->SetDepfile(depfile); - cc->SetJobPool(job_pool); - cc->SetCMP0116Status(cmp0116); - file->SetCustomCommand(std::move(cc)); lg.AddSourceOutputs(file, outputs, cmLocalGenerator::OutputRole::Primary, lfbt, origin); lg.AddSourceOutputs(file, byproducts, cmLocalGenerator::OutputRole::Byproduct, lfbt, origin); + + file->SetCustomCommand(std::move(cc)); } return file; } @@ -4174,68 +4191,39 @@ bool AnyTargetCommandOutputMatches( } namespace detail { -void AddCustomCommandToTarget(cmLocalGenerator& lg, - const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, cmTarget* target, - const std::vector& byproducts, - const std::vector& 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, - cmPolicies::PolicyStatus cmp0116) +void AddCustomCommandToTarget(cmLocalGenerator& lg, cmCommandOrigin origin, + cmTarget* target, cmCustomCommandType type, + std::unique_ptr cc) { // Add the command to the appropriate build step for the target. - cmCustomCommand cc; - cc.SetByproducts(byproducts); - cc.SetDepends(depends); - cc.SetCommandLines(commandLines); - cc.SetComment(comment); - cc.SetBacktrace(lfbt); - cc.SetWorkingDirectory(workingDir); - cc.SetStdPipesUTF8(stdPipesUTF8); - cc.SetEscapeOldStyle(escapeOldStyle); - cc.SetEscapeAllowMakeVars(true); - cc.SetUsesTerminal(uses_terminal); - cc.SetCommandExpandLists(command_expand_lists); - cc.SetDepfile(depfile); - cc.SetJobPool(job_pool); - cc.SetCMP0116Status(cmp0116); - cc.SetTarget(target->GetName()); + cc->SetEscapeAllowMakeVars(true); + cc->SetTarget(target->GetName()); + + lg.AddTargetByproducts(target, cc->GetByproducts(), cc->GetBacktrace(), + origin); + switch (type) { case cmCustomCommandType::PRE_BUILD: - target->AddPreBuildCommand(std::move(cc)); + target->AddPreBuildCommand(std::move(*cc)); break; case cmCustomCommandType::PRE_LINK: - target->AddPreLinkCommand(std::move(cc)); + target->AddPreLinkCommand(std::move(*cc)); break; case cmCustomCommandType::POST_BUILD: - target->AddPostBuildCommand(std::move(cc)); + target->AddPostBuildCommand(std::move(*cc)); break; } - lg.AddTargetByproducts(target, byproducts, lfbt, origin); + cc.reset(); } -cmSourceFile* AddCustomCommandToOutput( - cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, const std::vector& outputs, - const std::vector& byproducts, - const std::vector& 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, - const std::string& job_pool, bool stdPipesUTF8, - cmPolicies::PolicyStatus cmp0116) +cmSourceFile* AddCustomCommandToOutput(cmLocalGenerator& lg, + cmCommandOrigin origin, + const std::string& main_dependency, + std::unique_ptr cc, + bool replace) { - return AddCustomCommand(lg, lfbt, origin, outputs, byproducts, depends, - main_dependency, implicit_depends, commandLines, - comment, workingDir, replace, escapeOldStyle, - uses_terminal, command_expand_lists, depfile, - job_pool, stdPipesUTF8, cmp0116); + return AddCustomCommand(lg, origin, main_dependency, std::move(cc), replace); } void AppendCustomCommandToOutput(cmLocalGenerator& lg, @@ -4278,33 +4266,27 @@ void AppendCustomCommandToOutput(cmLocalGenerator& lg, lfbt); } -void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, cmTarget* target, - const char* workingDir, - const std::vector& byproducts, - const std::vector& depends, - const cmCustomCommandLines& commandLines, - bool escapeOldStyle, const char* comment, - bool uses_terminal, bool command_expand_lists, - const std::string& job_pool, bool stdPipesUTF8, - cmPolicies::PolicyStatus cmp0116) +void AddUtilityCommand(cmLocalGenerator& lg, cmCommandOrigin origin, + cmTarget* target, std::unique_ptr cc) { + // They might be moved away + auto byproducts = cc->GetByproducts(); + auto lfbt = cc->GetBacktrace(); + // Use an empty comment to avoid generation of default comment. - if (!comment) { - comment = ""; + if (!cc->GetComment()) { + cc->SetComment(""); } // Create the generated symbolic output name of the utility target. std::string output = lg.CreateUtilityOutput(target->GetName(), byproducts, lfbt); + cc->SetOutputs(output); std::string no_main_dependency; - cmImplicitDependsList no_implicit_depends; - cmSourceFile* rule = AddCustomCommand( - lg, lfbt, origin, { output }, byproducts, depends, no_main_dependency, - no_implicit_depends, commandLines, comment, workingDir, - /*replace=*/false, escapeOldStyle, uses_terminal, command_expand_lists, - /*depfile=*/"", job_pool, stdPipesUTF8, cmp0116); + cmSourceFile* rule = + AddCustomCommand(lg, origin, no_main_dependency, std::move(cc), + /*replace=*/false); if (rule) { lg.AddTargetByproducts(target, byproducts, lfbt, origin); } diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 726817a..1304d81 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -713,30 +713,15 @@ bool cmLocalGeneratorCheckObjectName(std::string& objName, #endif namespace detail { -void AddCustomCommandToTarget(cmLocalGenerator& lg, - const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, cmTarget* target, - const std::vector& byproducts, - const std::vector& 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, - cmPolicies::PolicyStatus cmp0116); - -cmSourceFile* AddCustomCommandToOutput( - cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, const std::vector& outputs, - const std::vector& byproducts, - const std::vector& 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, - const std::string& job_pool, bool stdPipesUTF8, - cmPolicies::PolicyStatus cmp0116); +void AddCustomCommandToTarget(cmLocalGenerator& lg, cmCommandOrigin origin, + cmTarget* target, cmCustomCommandType type, + std::unique_ptr cc); + +cmSourceFile* AddCustomCommandToOutput(cmLocalGenerator& lg, + cmCommandOrigin origin, + const std::string& main_dependency, + std::unique_ptr cc, + bool replace); void AppendCustomCommandToOutput(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, @@ -745,16 +730,8 @@ void AppendCustomCommandToOutput(cmLocalGenerator& lg, const cmImplicitDependsList& implicit_depends, const cmCustomCommandLines& commandLines); -void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, cmTarget* target, - const char* workingDir, - const std::vector& byproducts, - const std::vector& depends, - const cmCustomCommandLines& commandLines, - bool escapeOldStyle, const char* comment, - bool uses_terminal, bool command_expand_lists, - const std::string& job_pool, bool stdPipesUTF8, - cmPolicies::PolicyStatus cmp0116); +void AddUtilityCommand(cmLocalGenerator& lg, cmCommandOrigin origin, + cmTarget* target, std::unique_ptr cc); std::vector ComputeISPCObjectSuffixes(cmGeneratorTarget* target); std::vector ComputeISPCExtraObjects( diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index e84e474..5db57ef 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -900,7 +900,12 @@ void cmMakefile::AddGeneratorAction(GeneratorAction&& action) void cmMakefile::GeneratorAction::operator()(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt) { - Action(lg, lfbt); + if (cc) { + CCAction(lg, lfbt, std::move(cc)); + } else { + assert(Action); + Action(lg, lfbt); + } } void cmMakefile::DoGenerate(cmLocalGenerator& lg) @@ -962,19 +967,6 @@ private: cmListFileBacktrace& Backtrace; cmListFileBacktrace Previous; }; - -cm::optional MakeOptionalString(const char* str) -{ - if (str) { - return str; - } - return cm::nullopt; -} - -const char* GetCStrOrNull(const cm::optional& str) -{ - return str ? str->c_str() : nullptr; -} } bool cmMakefile::ValidateCustomCommand( @@ -1082,19 +1074,29 @@ cmTarget* cmMakefile::AddCustomCommandToTarget( auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116); - // Strings could be moved into the callback function with C++14. - cm::optional commentStr = MakeOptionalString(comment); - cm::optional workingStr = MakeOptionalString(workingDir); + auto cc = cm::make_unique(); + 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); // Dispatch command creation to allow generator expressions in outputs. this->AddGeneratorAction( - [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt) { + std::move(cc), + [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, + std::unique_ptr tcc) { BacktraceGuard guard(this->Backtrace, lfbt); - detail::AddCustomCommandToTarget( - lg, lfbt, cmCommandOrigin::Project, t, byproducts, depends, - commandLines, type, GetCStrOrNull(commentStr), - GetCStrOrNull(workingStr), escapeOldStyle, uses_terminal, depfile, - job_pool, command_expand_lists, stdPipesUTF8, cmp0116); + tcc->SetBacktrace(lfbt); + detail::AddCustomCommandToTarget(lg, cmCommandOrigin::Project, t, type, + std::move(tcc)); }); return t; @@ -1143,20 +1145,32 @@ void cmMakefile::AddCustomCommandToOutput( auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116); - // Strings could be moved into the callback function with C++14. - cm::optional commentStr = MakeOptionalString(comment); - cm::optional workingStr = MakeOptionalString(workingDir); + auto cc = cm::make_unique(); + 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); // Dispatch command creation to allow generator expressions in outputs. this->AddGeneratorAction( - [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt) { + std::move(cc), + [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, + std::unique_ptr tcc) { BacktraceGuard guard(this->Backtrace, lfbt); + tcc->SetBacktrace(lfbt); cmSourceFile* sf = detail::AddCustomCommandToOutput( - lg, lfbt, cmCommandOrigin::Project, outputs, byproducts, depends, - main_dependency, implicit_depends, commandLines, - GetCStrOrNull(commentStr), GetCStrOrNull(workingStr), replace, - escapeOldStyle, uses_terminal, command_expand_lists, depfile, job_pool, - stdPipesUTF8, cmp0116); + lg, cmCommandOrigin::Project, main_dependency, std::move(tcc), + replace); if (callback && sf) { callback(sf); } @@ -1264,19 +1278,28 @@ cmTarget* cmMakefile::AddUtilityCommand( auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116); - // Strings could be moved into the callback function with C++14. - cm::optional commentStr = MakeOptionalString(comment); - cm::optional workingStr = MakeOptionalString(workingDir); + auto cc = cm::make_unique(); + 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); // Dispatch command creation to allow generator expressions in outputs. this->AddGeneratorAction( - [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt) { + std::move(cc), + [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, + std::unique_ptr tcc) { BacktraceGuard guard(this->Backtrace, lfbt); - detail::AddUtilityCommand( - lg, lfbt, cmCommandOrigin::Project, target, GetCStrOrNull(workingStr), - byproducts, depends, commandLines, escapeOldStyle, - GetCStrOrNull(commentStr), uses_terminal, command_expand_lists, - job_pool, stdPipesUTF8, cmp0116); + tcc->SetBacktrace(lfbt); + detail::AddUtilityCommand(lg, cmCommandOrigin::Project, target, + std::move(tcc)); }); return target; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 75412d7..82c17a1 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -24,6 +24,7 @@ #include "cm_sys_stat.h" #include "cmAlgorithms.h" +#include "cmCustomCommand.h" #include "cmCustomCommandTypes.h" #include "cmListFileCache.h" #include "cmMessageType.h" @@ -50,7 +51,6 @@ class cmExportBuildFileGenerator; class cmFunctionBlocker; class cmGeneratorExpressionEvaluationFile; class cmGlobalGenerator; -class cmImplicitDependsList; class cmInstallGenerator; class cmLocalGenerator; class cmMessenger; @@ -144,6 +144,9 @@ public: { using ActionT = std::function; + using CCActionT = + std::function cc)>; public: GeneratorAction(ActionT&& action) @@ -151,10 +154,20 @@ public: { } + GeneratorAction(std::unique_ptr tcc, CCActionT&& action) + : CCAction(std::move(action)) + , cc(std::move(tcc)) + { + } + void operator()(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt); private: ActionT Action; + + // FIXME: Use std::variant + CCActionT CCAction; + std::unique_ptr cc; }; /** -- cgit v0.12 From 68b4e3b255be7a8d0831d19b206f701efdb001c8 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 14 Nov 2021 16:55:38 +0900 Subject: cmGlobalVisualStudio8Generator: Fix the misaligned argument, stdPipesUTF8 The call to AddCustomCommandToTarget for "Checking File Globs" had misaligned arguments and previously passed `stdPipesUTF8` as `escapeOldStyle`. For now, set `escapeOldStyle` as `true`. Also `stdPipesUTF8` is `true` here. --- Source/cmGlobalVisualStudio8Generator.cxx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 1e45813..c4da8c3 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -203,11 +203,17 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() std::vector byproducts; byproducts.push_back(cm->GetGlobVerifyStamp()); - lg.AddCustomCommandToTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET, byproducts, - no_depends, verifyCommandLines, - cmCustomCommandType::PRE_BUILD, - "Checking File Globs", no_working_directory, - cmPolicies::NEW, stdPipesUTF8); + lg.AddCustomCommandToTarget( + CMAKE_CHECK_BUILD_SYSTEM_TARGET, byproducts, no_depends, + verifyCommandLines, cmCustomCommandType::PRE_BUILD, + "Checking File Globs", no_working_directory, cmPolicies::NEW, + /*escapeOldStyle=*/true, + /*uses_terminal=*/false, + /*depfile=*/"", + /*job_pool=*/"", + /*command_expand_lists=*/false, + /*objLibCommands=*/cmObjectLibraryCommands::Reject, + /*stdPipesUTF8=*/stdPipesUTF8); // Ensure ZERO_CHECK always runs in Visual Studio using MSBuild, // otherwise the prebuild command will not be run. -- cgit v0.12 From c46b041a3bcede9447c36de2f3359eb4c17f3f50 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 7 Nov 2021 12:45:49 +0900 Subject: cmLocalGenerator: Simplify Add{Custom,Utility}Command --- Source/cmGlobalVisualStudio8Generator.cxx | 45 ++++++------ Source/cmGlobalVisualStudioGenerator.cxx | 13 ++-- Source/cmGlobalXCodeGenerator.cxx | 33 ++++----- Source/cmLocalGenerator.cxx | 116 ++++++------------------------ Source/cmLocalGenerator.h | 47 +++--------- Source/cmLocalVisualStudio7Generator.cxx | 24 ++++--- Source/cmQtAutoGenGlobalInitializer.cxx | 15 ++-- Source/cmQtAutoGenInitializer.cxx | 93 ++++++++++++++---------- 8 files changed, 154 insertions(+), 232 deletions(-) diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index c4da8c3..48c662c 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -147,13 +147,10 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() auto& lg = cm::static_reference_cast(generators[0]); - const char* no_working_directory = nullptr; - std::vector no_byproducts; - std::vector no_depends; - cmCustomCommandLines no_commands; - cmTarget* tgt = lg.AddUtilityCommand( - CMAKE_CHECK_BUILD_SYSTEM_TARGET, false, no_working_directory, - no_byproducts, no_depends, no_commands, cmPolicies::NEW); + auto cc = cm::make_unique(); + cc->SetCMP0116Status(cmPolicies::NEW); + cmTarget* tgt = lg.AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false, + std::move(cc)); auto ptr = cm::make_unique(tgt, &lg); auto gt = ptr.get(); @@ -203,17 +200,15 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() std::vector byproducts; byproducts.push_back(cm->GetGlobVerifyStamp()); - lg.AddCustomCommandToTarget( - CMAKE_CHECK_BUILD_SYSTEM_TARGET, byproducts, no_depends, - verifyCommandLines, cmCustomCommandType::PRE_BUILD, - "Checking File Globs", no_working_directory, cmPolicies::NEW, - /*escapeOldStyle=*/true, - /*uses_terminal=*/false, - /*depfile=*/"", - /*job_pool=*/"", - /*command_expand_lists=*/false, - /*objLibCommands=*/cmObjectLibraryCommands::Reject, - /*stdPipesUTF8=*/stdPipesUTF8); + cc = cm::make_unique(); + cc->SetByproducts(byproducts); + cc->SetCommandLines(verifyCommandLines); + cc->SetComment("Checking File Globs"); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetStdPipesUTF8(stdPipesUTF8); + lg.AddCustomCommandToTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET, + cmCustomCommandType::PRE_BUILD, + std::move(cc)); // Ensure ZERO_CHECK always runs in Visual Studio using MSBuild, // otherwise the prebuild command will not be run. @@ -241,12 +236,16 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() // overwritten by the CreateVCProjBuildRule. // (this could be avoided with per-target source files) std::string no_main_dependency; - cmImplicitDependsList no_implicit_depends; + cc = cm::make_unique(); + cc->SetOutputs(stamps); + cc->SetDepends(listFiles); + cc->SetCommandLines(commandLines); + cc->SetComment("Checking Build System"); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetStdPipesUTF8(stdPipesUTF8); if (cmSourceFile* file = lg.AddCustomCommandToOutput( - stamps, no_byproducts, listFiles, no_main_dependency, - no_implicit_depends, commandLines, "Checking Build System", - no_working_directory, cmPolicies::NEW, true, false, false, false, "", - "", stdPipesUTF8)) { + no_main_dependency, std::move(cc), true)) { gt->AddSource(file->ResolveFullPath()); } else { cmSystemTools::Error("Error adding rule for " + stamps[0]); diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 580c82b..f6011d1 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -199,19 +199,18 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets() { // Add a special target that depends on ALL projects for easy build // of one configuration only. - const char* no_working_dir = nullptr; - std::vector no_byproducts; - std::vector no_depends; - cmCustomCommandLines no_commands; for (auto const& it : this->ProjectMap) { std::vector const& gen = it.second; // add the ALL_BUILD to the first local generator of each project if (!gen.empty()) { // Use no actual command lines so that the target itself is not // considered always out of date. - cmTarget* allBuild = gen[0]->AddUtilityCommand( - "ALL_BUILD", true, no_working_dir, no_byproducts, no_depends, - no_commands, cmPolicies::NEW, false, "Build all projects"); + auto cc = cm::make_unique(); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetComment("Build all projects"); + cmTarget* allBuild = + gen[0]->AddUtilityCommand("ALL_BUILD", true, std::move(cc)); gen[0]->AddGeneratorTarget( cm::make_unique(allBuild, gen[0])); diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index a836f43..44a3eb7 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -608,15 +608,13 @@ std::string cmGlobalXCodeGenerator::PostBuildMakeTarget( void cmGlobalXCodeGenerator::AddExtraTargets( cmLocalGenerator* root, std::vector& gens) { - const char* no_working_directory = nullptr; - std::vector no_byproducts; - std::vector no_depends; - // Add ALL_BUILD - cmTarget* allbuild = root->AddUtilityCommand( - "ALL_BUILD", true, no_working_directory, no_byproducts, no_depends, - cmMakeSingleCommandLine({ "echo", "Build all projects" }), - cmPolicies::NEW); + auto cc = cm::make_unique(); + cc->SetCommandLines( + cmMakeSingleCommandLine({ "echo", "Build all projects" })); + cc->SetCMP0116Status(cmPolicies::NEW); + cmTarget* allbuild = + root->AddUtilityCommand("ALL_BUILD", true, std::move(cc)); root->AddGeneratorTarget(cm::make_unique(allbuild, root)); @@ -642,10 +640,11 @@ void cmGlobalXCodeGenerator::AddExtraTargets( std::string file = this->ConvertToRelativeForMake(this->CurrentReRunCMakeMakefile); cmSystemTools::ReplaceString(file, "\\ ", " "); - cmTarget* check = root->AddUtilityCommand( - CMAKE_CHECK_BUILD_SYSTEM_TARGET, true, no_working_directory, - no_byproducts, no_depends, - cmMakeSingleCommandLine({ "make", "-f", file }), cmPolicies::NEW); + cc = cm::make_unique(); + cc->SetCommandLines(cmMakeSingleCommandLine({ "make", "-f", file })); + cc->SetCMP0116Status(cmPolicies::NEW); + cmTarget* check = root->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, + true, std::move(cc)); root->AddGeneratorTarget(cm::make_unique(check, root)); } @@ -671,11 +670,13 @@ void cmGlobalXCodeGenerator::AddExtraTargets( target->GetType() == cmStateEnums::OBJECT_LIBRARY) { legacyDependHelperCommandLines.front().back() = // fill placeholder this->PostBuildMakeTarget(target->GetName(), "$(CONFIGURATION)"); + cc = cm::make_unique(); + cc->SetCommandLines(legacyDependHelperCommandLines); + cc->SetComment("Depend check for xcode"); + cc->SetWorkingDirectory(legacyDependHelperDir.c_str()); + cc->SetCMP0116Status(cmPolicies::NEW); gen->AddCustomCommandToTarget( - target->GetName(), no_byproducts, no_depends, - legacyDependHelperCommandLines, cmCustomCommandType::POST_BUILD, - "Depend check for xcode", legacyDependHelperDir.c_str(), - cmPolicies::NEW, true, false, "", "", false, + target->GetName(), cmCustomCommandType::POST_BUILD, std::move(cc), cmObjectLibraryCommands::Accept); } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 98f8fcc..5e37fe4 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1057,14 +1057,8 @@ void cmLocalGenerator::AddCompileOptions(std::vector>& flags, } cmTarget* cmLocalGenerator::AddCustomCommandToTarget( - const std::string& target, const std::vector& byproducts, - const std::vector& depends, - const cmCustomCommandLines& commandLines, cmCustomCommandType type, - const char* comment, const char* workingDir, - cmPolicies::PolicyStatus cmp0116, bool escapeOldStyle, bool uses_terminal, - const std::string& depfile, const std::string& job_pool, - bool command_expand_lists, cmObjectLibraryCommands objLibCommands, - bool stdPipesUTF8) + const std::string& target, cmCustomCommandType type, + std::unique_ptr cc, cmObjectLibraryCommands objLibCommands) { cmTarget* t = this->Makefile->GetCustomCommandTarget( target, objLibCommands, this->DirectoryBacktrace); @@ -1072,20 +1066,8 @@ cmTarget* cmLocalGenerator::AddCustomCommandToTarget( return nullptr; } - auto cc = cm::make_unique(); cc->SetBacktrace(this->DirectoryBacktrace); - 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); + detail::AddCustomCommandToTarget(*this, cmCommandOrigin::Generator, t, type, std::move(cc)); @@ -1093,87 +1075,34 @@ cmTarget* cmLocalGenerator::AddCustomCommandToTarget( } cmSourceFile* cmLocalGenerator::AddCustomCommandToOutput( - const std::string& output, const std::vector& depends, - const std::string& main_dependency, const cmCustomCommandLines& commandLines, - const char* comment, const char* workingDir, - cmPolicies::PolicyStatus cmp0116, bool replace, bool escapeOldStyle, - bool uses_terminal, bool command_expand_lists, const std::string& depfile, - const std::string& job_pool, bool stdPipesUTF8) -{ - std::vector no_byproducts; - cmImplicitDependsList no_implicit_depends; - return this->AddCustomCommandToOutput( - { output }, no_byproducts, depends, main_dependency, no_implicit_depends, - commandLines, comment, workingDir, cmp0116, replace, escapeOldStyle, - uses_terminal, command_expand_lists, depfile, job_pool, stdPipesUTF8); -} - -cmSourceFile* cmLocalGenerator::AddCustomCommandToOutput( - const std::vector& outputs, - const std::vector& byproducts, - const std::vector& depends, const std::string& main_dependency, - const cmImplicitDependsList& implicit_depends, - const cmCustomCommandLines& commandLines, const char* comment, - const char* workingDir, cmPolicies::PolicyStatus cmp0116, 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 cc, + bool replace) { // Make sure there is at least one output. - if (outputs.empty()) { + if (cc->GetOutputs().empty()) { cmSystemTools::Error("Attempt to add a custom rule with no output!"); return nullptr; } - auto cc = cm::make_unique(); cc->SetBacktrace(this->DirectoryBacktrace); - 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); return detail::AddCustomCommandToOutput(*this, cmCommandOrigin::Generator, main_dependency, std::move(cc), replace); } cmTarget* cmLocalGenerator::AddUtilityCommand( - const std::string& utilityName, bool excludeFromAll, const char* workingDir, - const std::vector& byproducts, - const std::vector& depends, - const cmCustomCommandLines& commandLines, cmPolicies::PolicyStatus cmp0116, - bool escapeOldStyle, const char* comment, bool uses_terminal, - bool command_expand_lists, const std::string& job_pool, bool stdPipesUTF8) + const std::string& utilityName, bool excludeFromAll, + std::unique_ptr cc) { cmTarget* target = this->Makefile->AddNewUtilityTarget(utilityName, excludeFromAll); target->SetIsGeneratorProvided(true); - if (commandLines.empty() && depends.empty()) { + if (cc->GetCommandLines().empty() && cc->GetDepends().empty()) { return target; } - auto cc = cm::make_unique(); cc->SetBacktrace(this->DirectoryBacktrace); - 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); detail::AddUtilityCommand(*this, cmCommandOrigin::Generator, target, std::move(cc)); @@ -2786,8 +2715,6 @@ void cmLocalGenerator::CopyPchCompilePdb( file << "endforeach()\n"; } - bool stdPipesUTF8 = true; - auto configGenex = [&](cm::string_view expr) -> std::string { if (this->GetGlobalGenerator()->IsMultiConfig()) { return cmStrCat("$<$:", expr, ">"); @@ -2801,28 +2728,27 @@ void cmLocalGenerator::CopyPchCompilePdb( configGenex(copy_script) }); const std::string no_main_dependency; - const std::vector no_deps; const char* no_message = ""; - const char* no_current_dir = nullptr; - const cmPolicies::PolicyStatus cmp0116_new = cmPolicies::NEW; - std::vector no_byproducts; std::vector outputs; outputs.push_back(configGenex( cmStrCat(target_compile_pdb_dir, pdb_prefix, ReuseFrom, ".pdb"))); + auto cc = cm::make_unique(); + cc->SetCommandLines(commandLines); + cc->SetComment(no_message); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetStdPipesUTF8(true); + if (this->GetGlobalGenerator()->IsVisualStudio()) { + cc->SetByproducts(outputs); this->AddCustomCommandToTarget( - target->GetName(), outputs, no_deps, commandLines, - cmCustomCommandType::PRE_BUILD, no_message, no_current_dir, cmp0116_new, - true, false, "", "", false, cmObjectLibraryCommands::Accept, - stdPipesUTF8); + target->GetName(), cmCustomCommandType::PRE_BUILD, std::move(cc), + cmObjectLibraryCommands::Accept); } else { - cmImplicitDependsList no_implicit_depends; - cmSourceFile* copy_rule = this->AddCustomCommandToOutput( - outputs, no_byproducts, no_deps, no_main_dependency, no_implicit_depends, - commandLines, no_message, no_current_dir, cmp0116_new, false, true, - false, false, "", "", stdPipesUTF8); + cc->SetOutputs(outputs); + cmSourceFile* copy_rule = + this->AddCustomCommandToOutput(no_main_dependency, std::move(cc)); if (copy_rule) { target->AddSource(copy_rule->ResolveFullPath()); diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 1304d81..3edf5dc 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -329,53 +329,24 @@ public: * Add a custom PRE_BUILD, PRE_LINK, or POST_BUILD command to a target. */ cmTarget* AddCustomCommandToTarget( - const std::string& target, const std::vector& byproducts, - const std::vector& depends, - const cmCustomCommandLines& commandLines, cmCustomCommandType type, - const char* comment, const char* workingDir, - cmPolicies::PolicyStatus cmp0116, bool escapeOldStyle = true, - bool uses_terminal = false, const std::string& depfile = "", - const std::string& job_pool = "", bool command_expand_lists = false, - cmObjectLibraryCommands objLibCommands = cmObjectLibraryCommands::Reject, - bool stdPipesUTF8 = false); + const std::string& target, cmCustomCommandType type, + std::unique_ptr cc, + cmObjectLibraryCommands objLibCommands = cmObjectLibraryCommands::Reject); /** * Add a custom command to a source file. */ - cmSourceFile* AddCustomCommandToOutput( - const std::string& output, const std::vector& depends, - const std::string& main_dependency, - const cmCustomCommandLines& commandLines, const char* comment, - const char* workingDir, cmPolicies::PolicyStatus cmp0116, - 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); - cmSourceFile* AddCustomCommandToOutput( - const std::vector& outputs, - const std::vector& byproducts, - const std::vector& depends, - const std::string& main_dependency, - const cmImplicitDependsList& implicit_depends, - const cmCustomCommandLines& commandLines, const char* comment, - const char* workingDir, cmPolicies::PolicyStatus cmp0116, - 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); + cmSourceFile* AddCustomCommandToOutput(const std::string& main_dependency, + std::unique_ptr cc, + bool replace = false); /** * Add 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& byproducts, - const std::vector& depends, - const cmCustomCommandLines& commandLines, cmPolicies::PolicyStatus cmp0116, - 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 cc); virtual std::string CreateUtilityOutput( std::string const& targetName, std::vector const& byproducts, diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 7223049..886a4e8 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -110,7 +110,6 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets() const auto& tgts = this->GetGeneratorTargets(); for (auto& l : tgts) { if (l->GetType() == cmStateEnums::GLOBAL_TARGET) { - std::vector no_depends; cmCustomCommandLines force_commands = cmMakeSingleCommandLine({ "cd", "." }); std::string no_main_dependency; @@ -120,9 +119,13 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets() this->Makefile->GetOrCreateGeneratedSource(force)) { sf->SetProperty("SYMBOLIC", "1"); } + auto cc = cm::make_unique(); + cc->SetOutputs(force); + cc->SetCommandLines(force_commands); + cc->SetComment(" "); + cc->SetCMP0116Status(cmPolicies::NEW); if (cmSourceFile* file = this->AddCustomCommandToOutput( - force, no_depends, no_main_dependency, force_commands, " ", - nullptr, cmPolicies::NEW, true)) { + no_main_dependency, std::move(cc), true)) { l->AddSource(file->ResolveFullPath()); } } @@ -240,16 +243,19 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule() std::string argB = cmStrCat("-B", this->GetBinaryDirectory()); std::string stampName = cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/generate.stamp"); - bool stdPipesUTF8 = true; cmCustomCommandLines commandLines = cmMakeSingleCommandLine({ cmSystemTools::GetCMakeCommand(), argS, argB, "--check-stamp-file", stampName }); std::string comment = cmStrCat("Building Custom Rule ", makefileIn); - const char* no_working_directory = nullptr; - this->AddCustomCommandToOutput(stampName, listFiles, makefileIn, - commandLines, comment.c_str(), - no_working_directory, cmPolicies::NEW, true, - false, false, false, "", "", stdPipesUTF8); + auto cc = cm::make_unique(); + cc->SetOutputs(stampName); + cc->SetDepends(listFiles); + cc->SetCommandLines(commandLines); + cc->SetComment(comment.c_str()); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetStdPipesUTF8(true); + this->AddCustomCommandToOutput(makefileIn, std::move(cc), true); if (cmSourceFile* file = this->Makefile->GetSource(makefileIn)) { // Finalize the source file path now since we're adding this after // the generator validated all project-named sources. diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index f9e889a..b7ea7d6 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -7,7 +7,7 @@ #include -#include "cmCustomCommandLines.h" +#include "cmCustomCommand.h" #include "cmDuration.h" #include "cmGeneratorTarget.h" #include "cmLocalGenerator.h" @@ -171,13 +171,12 @@ void cmQtAutoGenGlobalInitializer::GetOrCreateGlobalTarget( cmMakefile* makefile = localGen->GetMakefile(); // Create utility target - std::vector no_byproducts; - std::vector no_depends; - cmCustomCommandLines no_commands; - const cmPolicies::PolicyStatus cmp0116_new = cmPolicies::NEW; - cmTarget* target = localGen->AddUtilityCommand( - name, true, makefile->GetHomeOutputDirectory().c_str(), no_byproducts, - no_depends, no_commands, cmp0116_new, false, comment.c_str()); + auto cc = cm::make_unique(); + cc->SetWorkingDirectory(makefile->GetHomeOutputDirectory().c_str()); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetComment(comment.c_str()); + cmTarget* target = localGen->AddUtilityCommand(name, true, std::move(cc)); localGen->AddGeneratorTarget( cm::make_unique(target, localGen)); diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index e124758..64d8ea9 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1231,14 +1231,16 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() // Add a rule file to cause the target to build if a dependency has // changed, which will trigger the pre-build command to run autogen std::string no_main_dependency; - cmCustomCommandLines no_command_lines; - this->LocalGen->AddCustomCommandToOutput( - timestampFileGenex, uicDependencies, no_main_dependency, - no_command_lines, /*comment=*/"", this->Dir.Work.c_str(), - /*cmp0116=*/cmPolicies::NEW, /*replace=*/false, - /*escapeOldStyle=*/false, /*uses_terminal=*/false, - /*command_expand_lists=*/false, /*depfile=*/"", /*job_pool=*/"", - stdPipesUTF8); + auto cc = cm::make_unique(); + cc->SetOutputs(timestampFileGenex); + cc->SetDepends(uicDependencies); + cc->SetComment(""); + cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetStdPipesUTF8(stdPipesUTF8); + this->LocalGen->AddCustomCommandToOutput(no_main_dependency, + std::move(cc)); } // Add the pre-build command directly to bypass the OBJECT_LIBRARY @@ -1323,11 +1325,15 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() dependencies.push_back(depname); } + auto cc = cm::make_unique(); + cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetByproducts(timestampTargetProvides); + cc->SetDepends(dependencies); + cc->SetCommandLines(timestampTargetCommandLines); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); cmTarget* timestampTarget = this->LocalGen->AddUtilityCommand( - timestampTargetName, true, this->Dir.Work.c_str(), - /*byproducts=*/timestampTargetProvides, - /*depends=*/dependencies, timestampTargetCommandLines, cmPolicies::NEW, - false, nullptr); + timestampTargetName, true, std::move(cc)); this->LocalGen->AddGeneratorTarget( cm::make_unique(timestampTarget, this->LocalGen)); @@ -1357,15 +1363,19 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() this->AddGeneratedSource(outputFile, this->Moc); const std::string no_main_dependency; - this->LocalGen->AddCustomCommandToOutput( - { outputFile }, timestampByproducts, dependencies, no_main_dependency, - /*implicit_depends=*/{}, commandLines, autogenComment.c_str(), - this->Dir.Work.c_str(), - /*cmp0116=*/cmPolicies::NEW, /*replace=*/false, - /*escapeOldStyle=*/false, - /*uses_terminal=*/false, - /*command_expand_lists=*/false, this->AutogenTarget.DepFile, "", - stdPipesUTF8); + cc = cm::make_unique(); + cc->SetOutputs(outputFile); + cc->SetByproducts(timestampByproducts); + cc->SetDepends(dependencies); + cc->SetCommandLines(commandLines); + cc->SetComment(autogenComment.c_str()); + cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetDepfile(this->AutogenTarget.DepFile); + cc->SetStdPipesUTF8(stdPipesUTF8); + this->LocalGen->AddCustomCommandToOutput(no_main_dependency, + std::move(cc)); // Alter variables for the autogen target which now merely wraps the // custom command @@ -1376,11 +1386,16 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() } // Create autogen target + auto cc = cm::make_unique(); + cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetByproducts(autogenByproducts); + cc->SetDepends(dependencies); + cc->SetCommandLines(commandLines); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetComment(autogenComment.c_str()); cmTarget* autogenTarget = this->LocalGen->AddUtilityCommand( - this->AutogenTarget.Name, true, this->Dir.Work.c_str(), - /*byproducts=*/autogenByproducts, - /*depends=*/dependencies, commandLines, cmPolicies::NEW, false, - autogenComment.c_str()); + this->AutogenTarget.Name, true, std::move(cc)); // Create autogen generator target this->LocalGen->AddGeneratorTarget( cm::make_unique(autogenTarget, this->LocalGen)); @@ -1437,7 +1452,6 @@ bool cmQtAutoGenInitializer::InitRccTargets() ccDepends.push_back(qrc.QrcFile); ccDepends.push_back(qrc.InfoFile); - bool stdPipesUTF8 = true; cmCustomCommandLines commandLines; if (this->MultiConfig) { // Build for all configurations @@ -1455,6 +1469,13 @@ bool cmQtAutoGenInitializer::InitRccTargets() cmStrCat("Automatic RCC for ", FileProjectRelativePath(this->Makefile, qrc.QrcFile)); + auto cc = cm::make_unique(); + cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetCommandLines(commandLines); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetComment(ccComment.c_str()); + cc->SetStdPipesUTF8(true); + if (qrc.Generated || this->Rcc.GlobalTarget) { // Create custom rcc target std::string ccName; @@ -1464,10 +1485,11 @@ bool cmQtAutoGenInitializer::InitRccTargets() ccName += cmStrCat('_', qrc.QrcPathChecksum); } - cmTarget* autoRccTarget = this->LocalGen->AddUtilityCommand( - ccName, true, this->Dir.Work.c_str(), ccOutput, ccDepends, - commandLines, cmPolicies::NEW, false, ccComment.c_str(), false, - false, "", stdPipesUTF8); + cc->SetByproducts(ccOutput); + cc->SetDepends(ccDepends); + cc->SetEscapeOldStyle(false); + cmTarget* autoRccTarget = + this->LocalGen->AddUtilityCommand(ccName, true, std::move(cc)); // Create autogen generator target this->LocalGen->AddGeneratorTarget( @@ -1503,12 +1525,11 @@ bool cmQtAutoGenInitializer::InitRccTargets() ccDepends.push_back(this->Rcc.ExecutableTargetName); } std::string no_main_dependency; - cmImplicitDependsList no_implicit_depends; - this->LocalGen->AddCustomCommandToOutput( - ccOutput, ccByproducts, ccDepends, no_main_dependency, - no_implicit_depends, commandLines, ccComment.c_str(), - this->Dir.Work.c_str(), cmPolicies::NEW, false, true, false, false, - "", "", stdPipesUTF8); + cc->SetOutputs(ccOutput); + cc->SetByproducts(ccByproducts); + cc->SetDepends(ccDepends); + this->LocalGen->AddCustomCommandToOutput(no_main_dependency, + std::move(cc)); } // Reconfigure when .qrc file changes this->Makefile->AddCMakeDependFile(qrc.QrcFile); -- cgit v0.12 From 3bb2542535fa2ca1e78195b69c53916a55d322e1 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Mon, 8 Nov 2021 00:25:33 +0900 Subject: cmMakefile: Simplify Add*Command and adopt to cmAddCustom*Command --- Source/cmAddCustomCommandCommand.cxx | 28 +++++--- Source/cmAddCustomTargetCommand.cxx | 20 ++++-- Source/cmCPluginAPI.cxx | 25 ++++--- Source/cmFLTKWrapUICommand.cxx | 21 ++++-- Source/cmMakefile.cxx | 126 ++++++++++------------------------- Source/cmMakefile.h | 44 +++--------- Source/cmQTWrapCPPCommand.cxx | 15 +++-- 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 #include +#include + +#include #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" @@ -316,20 +319,25 @@ bool cmAddCustomCommandCommand(std::vector const& args, } // Choose which mode of the command to use. - bool escapeOldStyle = !verbatim; + auto cc = cm::make_unique(); + 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 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 +#include + +#include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" @@ -210,11 +213,18 @@ bool cmAddCustomTargetCommand(std::vector 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(); + 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 no_byproducts; - mf->AddUtilityCommand(utilityName, !all, nullptr, no_byproducts, depends2, - commandLines); + auto cc = cm::make_unique(); + 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(); + 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 no_byproducts; - std::vector 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(); + 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 +#include +#include + +#include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmListFileCache.h" @@ -95,12 +99,17 @@ bool cmFLTKWrapUICommand(std::vector 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(); + hcc->SetDepends(depends); + hcc->SetCommandLines(commandLines); + auto ccc = cm::make_unique(*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& byproducts, - const std::vector& 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 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(); - 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& 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 cc, + const CommandSourceCallback& callback, bool replace) { - std::vector 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& outputs, - const std::vector& byproducts, - const std::vector& 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(); - 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& depends, const std::string& source, const cmCustomCommandLines& commandLines, const char* comment) { + auto cc = cm::make_unique(); + 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 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(*cc); + cc1->SetOutputs(output); + this->AddCustomCommandToOutput(source, std::move(cc1), + addRuleFileToTarget); } } else { std::string no_main_dependency; - std::vector 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(*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& byproducts, - const std::vector& 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 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(); - 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& byproducts, - const std::vector& 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 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& 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& outputs, - const std::vector& byproducts, - const std::vector& 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 cc, + const CommandSourceCallback& callback = nullptr, bool replace = false); void AddCustomCommandOldStyle(const std::string& target, const std::vector& outputs, const std::vector& 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& byproducts, - const std::vector& 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 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 + +#include + +#include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" @@ -71,10 +76,12 @@ bool cmQTWrapCPPCommand(std::vector 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(); + 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 + +#include + +#include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmMakefile.h" @@ -84,19 +89,26 @@ bool cmQTWrapUICommand(std::vector const& args, std::vector 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(); + 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(); + 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(); + cc->SetOutputs(mocName); + cc->SetDepends(depends); + cc->SetCommandLines(mocCommandLines); + mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc)); } } -- cgit v0.12