summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2021-11-14 08:22:33 (GMT)
committerBrad King <brad.king@kitware.com>2021-11-18 17:02:37 (GMT)
commite37511ae7eb68a46fb9edb9f00d3fc179f713e45 (patch)
tree98bde246d5424c4552bb1b0149f96449d948bd86 /Source/cmMakefile.cxx
parent90e1206f253c0acbef37668403133585a31b2a92 (diff)
downloadCMake-e37511ae7eb68a46fb9edb9f00d3fc179f713e45.zip
CMake-e37511ae7eb68a46fb9edb9f00d3fc179f713e45.tar.gz
CMake-e37511ae7eb68a46fb9edb9f00d3fc179f713e45.tar.bz2
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.
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx105
1 files changed, 64 insertions, 41 deletions
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<std::string> MakeOptionalString(const char* str)
-{
- if (str) {
- return str;
- }
- return cm::nullopt;
-}
-
-const char* GetCStrOrNull(const cm::optional<std::string>& 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<std::string> commentStr = MakeOptionalString(comment);
- cm::optional<std::string> workingStr = MakeOptionalString(workingDir);
+ auto cc = cm::make_unique<cmCustomCommand>();
+ cc->SetByproducts(byproducts);
+ cc->SetDepends(depends);
+ cc->SetCommandLines(commandLines);
+ cc->SetComment(comment);
+ cc->SetWorkingDirectory(workingDir);
+ cc->SetEscapeOldStyle(escapeOldStyle);
+ cc->SetUsesTerminal(uses_terminal);
+ cc->SetDepfile(depfile);
+ cc->SetJobPool(job_pool);
+ cc->SetCommandExpandLists(command_expand_lists);
+ cc->SetStdPipesUTF8(stdPipesUTF8);
+ cc->SetCMP0116Status(cmp0116);
// 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<cmCustomCommand> 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<std::string> commentStr = MakeOptionalString(comment);
- cm::optional<std::string> workingStr = MakeOptionalString(workingDir);
+ auto cc = cm::make_unique<cmCustomCommand>();
+ cc->SetOutputs(outputs);
+ cc->SetByproducts(byproducts);
+ cc->SetDepends(depends);
+ cc->SetImplicitDepends(implicit_depends);
+ cc->SetCommandLines(commandLines);
+ cc->SetComment(comment);
+ cc->SetWorkingDirectory(workingDir);
+ cc->SetEscapeOldStyle(escapeOldStyle);
+ cc->SetUsesTerminal(uses_terminal);
+ cc->SetCommandExpandLists(command_expand_lists);
+ cc->SetDepfile(depfile);
+ cc->SetJobPool(job_pool);
+ cc->SetStdPipesUTF8(stdPipesUTF8);
+ cc->SetCMP0116Status(cmp0116);
// 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<cmCustomCommand> 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<std::string> commentStr = MakeOptionalString(comment);
- cm::optional<std::string> workingStr = MakeOptionalString(workingDir);
+ auto cc = cm::make_unique<cmCustomCommand>();
+ cc->SetWorkingDirectory(workingDir);
+ cc->SetByproducts(byproducts);
+ cc->SetDepends(depends);
+ cc->SetCommandLines(commandLines);
+ cc->SetEscapeOldStyle(escapeOldStyle);
+ cc->SetComment(comment);
+ cc->SetUsesTerminal(uses_terminal);
+ cc->SetCommandExpandLists(command_expand_lists);
+ cc->SetJobPool(job_pool);
+ cc->SetStdPipesUTF8(stdPipesUTF8);
+ cc->SetCMP0116Status(cmp0116);
// 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<cmCustomCommand> 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;