diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2021-11-01 14:19:05 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-11-18 17:02:37 (GMT) |
commit | 9b31a977481ea07c979549246ee46946e9978e08 (patch) | |
tree | 07b8d6b8618140ed066c8b1d3efe37c0bd994233 /Source | |
parent | d0158b765b0660bcfe304830e179fa9bbdffd5d9 (diff) | |
download | CMake-9b31a977481ea07c979549246ee46946e9978e08.zip CMake-9b31a977481ea07c979549246ee46946e9978e08.tar.gz CMake-9b31a977481ea07c979549246ee46946e9978e08.tar.bz2 |
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})`.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCustomCommand.cxx | 53 | ||||
-rw-r--r-- | Source/cmCustomCommand.h | 24 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 11 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudioGenerator.cxx | 10 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 11 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 23 | ||||
-rw-r--r-- | Source/cmLocalVisualStudioGenerator.cxx | 10 | ||||
-rw-r--r-- | 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 <cmext/algorithm> -cmCustomCommand::cmCustomCommand(std::vector<std::string> outputs, - std::vector<std::string> byproducts, - std::vector<std::string> 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<std::string>& cmCustomCommand::GetOutputs() const { + return this->Outputs; } -const std::vector<std::string>& cmCustomCommand::GetOutputs() const +void cmCustomCommand::SetOutputs(std::vector<std::string> outputs) { - return this->Outputs; + this->Outputs = std::move(outputs); +} + +void cmCustomCommand::SetOutputs(std::string output) +{ + this->Outputs = { std::move(output) }; } const std::vector<std::string>& cmCustomCommand::GetByproducts() const @@ -35,22 +26,43 @@ const std::vector<std::string>& cmCustomCommand::GetByproducts() const return this->Byproducts; } +void cmCustomCommand::SetByproducts(std::vector<std::string> byproducts) +{ + this->Byproducts = std::move(byproducts); +} + const std::vector<std::string>& cmCustomCommand::GetDepends() const { return this->Depends; } +void cmCustomCommand::SetDepends(std::vector<std::string> 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<std::string> outputs, - std::vector<std::string> byproducts, - std::vector<std::string> depends, - cmCustomCommandLines commandLines, cmListFileBacktrace lfbt, - const char* comment, const char* workingDirectory, - bool stdPipesUTF8); - /** Get the output file produced by the command. */ const std::vector<std::string>& GetOutputs() const; + void SetOutputs(std::vector<std::string> outputs); + void SetOutputs(std::string output); /** Get the extra files produced by the command. */ const std::vector<std::string>& GetByproducts() const; + void SetByproducts(std::vector<std::string> byproducts); /** Get the vector that holds the list of dependencies. */ const std::vector<std::string>& GetDepends() const; + void SetDepends(std::vector<std::string> 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<std::string> no_outputs; - std::vector<std::string> no_byproducts; - std::vector<std::string> 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("$<TARGET_SONAME_FILE:", gtgt->GetName(), '>'); std::string str_link_file = cmStrCat("$<TARGET_LINKER_FILE:", gtgt->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::string>(), std::vector<std::string>(), - std::vector<std::string>(), 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<cmCustomCommand> cc = cm::make_unique<cmCustomCommand>( - outputs, byproducts, depends2, commandLines, lfbt, comment, workingDir, - stdPipesUTF8); + std::unique_ptr<cmCustomCommand> cc = cm::make_unique<cmCustomCommand>(); + 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<std::string> 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<std::string> no_output; - std::vector<std::string> no_byproducts; - std::vector<std::string> 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<std::string> no_output; - const std::vector<std::string> 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)); |