mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-31 19:00:54 -06:00
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})`.
This commit is contained in:
committed by
Brad King
parent
d0158b765b
commit
9b31a97748
@@ -6,51 +6,63 @@
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
void cmCustomCommand::SetOutputs(std::vector<std::string> 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
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -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&);
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user