summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2023-05-01 19:12:46 +0200
committerMarc Chevrier <marc.chevrier@gmail.com>2023-05-04 19:34:36 +0200
commit72faa9a0175f7651c2707fead6a41450d2aaec88 (patch)
treee62fa3432742f1c62d1d911544e4cf42ca4028bd /Source
parent0d2d5a229c1cda842f0e67134637f19fc69de6c6 (diff)
downloadcmake-72faa9a0175f7651c2707fead6a41450d2aaec88.tar.gz
CreateRulePlaceholderExpander(): enhance memory management
This method returns now a std::unique_ptr instance rather than a raw pointer.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmLocalGenerator.cxx13
-rw-r--r--Source/cmLocalGenerator.h3
-rw-r--r--Source/cmLocalNinjaGenerator.cxx10
-rw-r--r--Source/cmLocalNinjaGenerator.h4
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx3
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.cxx8
-rw-r--r--Source/cmMakefileLibraryTargetGenerator.cxx8
-rw-r--r--Source/cmMakefileTargetGenerator.cxx7
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx16
-rw-r--r--Source/cmNinjaTargetGenerator.cxx8
10 files changed, 39 insertions, 41 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index b02fa62487..4089fd440b 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -207,12 +207,12 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
}
}
-cmRulePlaceholderExpander* cmLocalGenerator::CreateRulePlaceholderExpander()
- const
+std::unique_ptr<cmRulePlaceholderExpander>
+cmLocalGenerator::CreateRulePlaceholderExpander() const
{
- return new cmRulePlaceholderExpander(this->Compilers, this->VariableMappings,
- this->CompilerSysroot,
- this->LinkerSysroot);
+ return cm::make_unique<cmRulePlaceholderExpander>(
+ this->Compilers, this->VariableMappings, this->CompilerSysroot,
+ this->LinkerSysroot);
}
cmLocalGenerator::~cmLocalGenerator() = default;
@@ -3222,8 +3222,7 @@ void cmLocalGenerator::AppendDependencyInfoLinkerFlags(
auto depFile = this->ConvertToOutputFormat(
this->MaybeRelativeToWorkDir(this->GetLinkDependencyFile(target, config)),
cmOutputConverter::SHELL);
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander = this->CreateRulePlaceholderExpander();
cmRulePlaceholderExpander::RuleVariables linkDepsVariables;
linkDepsVariables.DependencyFile = depFile.c_str();
rulePlaceholderExpander->ExpandRuleVariables(this, depFlag,
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 3ad52c4256..c811408138 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -137,7 +137,8 @@ public:
return this->GlobalGenerator;
}
- virtual cmRulePlaceholderExpander* CreateRulePlaceholderExpander() const;
+ virtual std::unique_ptr<cmRulePlaceholderExpander>
+ CreateRulePlaceholderExpander() const;
std::string GetLinkLibsCMP0065(std::string const& linkLanguage,
cmGeneratorTarget& tgt) const;
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index 82d5a607b9..4b0604c55e 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -47,13 +47,12 @@ cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg,
// Virtual public methods.
-cmRulePlaceholderExpander*
+std::unique_ptr<cmRulePlaceholderExpander>
cmLocalNinjaGenerator::CreateRulePlaceholderExpander() const
{
- cmRulePlaceholderExpander* ret =
- this->cmLocalGenerator::CreateRulePlaceholderExpander();
+ auto ret = this->cmLocalGenerator::CreateRulePlaceholderExpander();
ret->SetTargetImpLib("$TARGET_IMPLIB");
- return ret;
+ return std::unique_ptr<cmRulePlaceholderExpander>(std::move(ret));
}
cmLocalNinjaGenerator::~cmLocalNinjaGenerator() = default;
@@ -913,8 +912,7 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
}
vars.Output = output.c_str();
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander = this->CreateRulePlaceholderExpander();
std::string launcher = *property_value;
rulePlaceholderExpander->ExpandRuleVariables(this, launcher, vars);
diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h
index 0bc462b038..74b8b3b3f8 100644
--- a/Source/cmLocalNinjaGenerator.h
+++ b/Source/cmLocalNinjaGenerator.h
@@ -6,6 +6,7 @@
#include <iosfwd>
#include <map>
+#include <memory>
#include <set>
#include <string>
#include <vector>
@@ -41,7 +42,8 @@ public:
void Generate() override;
- cmRulePlaceholderExpander* CreateRulePlaceholderExpander() const override;
+ std::unique_ptr<cmRulePlaceholderExpander> CreateRulePlaceholderExpander()
+ const override;
std::string GetTargetDirectory(
cmGeneratorTarget const* target) const override;
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index 9f3894adbd..cfe4eb629d 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -969,8 +969,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
*content << dir;
}
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander = this->CreateRulePlaceholderExpander();
// Add each command line to the set of commands.
std::vector<std::string> commands1;
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx
index be8318cd12..4a2b9e8996 100644
--- a/Source/cmMakefileExecutableTargetGenerator.cxx
+++ b/Source/cmMakefileExecutableTargetGenerator.cxx
@@ -232,8 +232,8 @@ void cmMakefileExecutableTargetGenerator::WriteNvidiaDeviceExecutableRule(
launcher = cmStrCat(val, ' ');
}
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->LocalGenerator->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander =
+ this->LocalGenerator->CreateRulePlaceholderExpander();
// Expand placeholders in the commands.
rulePlaceholderExpander->SetTargetImpLib(targetOutput);
@@ -598,8 +598,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
launcher = cmStrCat(val, ' ');
}
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->LocalGenerator->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander =
+ this->LocalGenerator->CreateRulePlaceholderExpander();
// Expand placeholders in the commands.
rulePlaceholderExpander->SetTargetImpLib(targetOutPathImport);
diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx
index 0ebbe4d190..b07a74b568 100644
--- a/Source/cmMakefileLibraryTargetGenerator.cxx
+++ b/Source/cmMakefileLibraryTargetGenerator.cxx
@@ -373,8 +373,8 @@ void cmMakefileLibraryTargetGenerator::WriteNvidiaDeviceLibraryRules(
launcher = cmStrCat(val, ' ');
}
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->LocalGenerator->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander =
+ this->LocalGenerator->CreateRulePlaceholderExpander();
// Construct the main link rule and expand placeholders.
rulePlaceholderExpander->SetTargetImpLib(targetOutput);
@@ -696,8 +696,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
}
// Expand the rule variables.
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->LocalGenerator->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander =
+ this->LocalGenerator->CreateRulePlaceholderExpander();
bool useWatcomQuote =
this->Makefile->IsOn(linkRuleVar + "_USE_WATCOM_QUOTE");
cmList real_link_commands;
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index 97e3fad85f..02cdf57275 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -967,8 +967,8 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
bool const lang_has_assembly = lang_has_preprocessor;
bool const lang_can_export_cmds = lang_has_preprocessor;
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->LocalGenerator->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander =
+ this->LocalGenerator->CreateRulePlaceholderExpander();
// Construct the compile rules.
{
@@ -1789,8 +1789,7 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule(
vars.Flags = flags.c_str();
std::string compileCmd = this->GetLinkRule("CMAKE_CUDA_DEVICE_LINK_COMPILE");
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- localGen->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander = localGen->CreateRulePlaceholderExpander();
rulePlaceholderExpander->ExpandRuleVariables(localGen, compileCmd, vars);
commands.emplace_back(compileCmd);
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 9903d63614..063ca6ba6a 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -302,8 +302,8 @@ void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkRule(
launcher = cmStrCat(val, ' ');
}
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->GetLocalGenerator()->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander =
+ this->GetLocalGenerator()->CreateRulePlaceholderExpander();
// Rule for linking library/executable.
std::vector<std::string> linkCmds = this->ComputeDeviceLinkCmd();
@@ -362,8 +362,8 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRules(
std::string compileCmd = this->GetMakefile()->GetRequiredDefinition(
"CMAKE_CUDA_DEVICE_LINK_COMPILE");
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->GetLocalGenerator()->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander =
+ this->GetLocalGenerator()->CreateRulePlaceholderExpander();
rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
compileCmd, vars);
@@ -511,8 +511,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile,
launcher = cmStrCat(val, ' ');
}
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->GetLocalGenerator()->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander =
+ this->GetLocalGenerator()->CreateRulePlaceholderExpander();
// Rule for linking library/executable.
std::vector<std::string> linkCmds = this->ComputeLinkCmd(config);
@@ -584,8 +584,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile,
std::string cmd =
this->GetMakefile()->GetDefinition("CMAKE_CREATE_TEXT_STUBS");
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->GetLocalGenerator()->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander =
+ this->GetLocalGenerator()->CreateRulePlaceholderExpander();
cmRulePlaceholderExpander::RuleVariables vars;
vars.Target = "$in";
rulePlaceholderExpander->SetTargetImpLib("$out");
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 7ce6c96d2d..4ed491d33c 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -665,8 +665,8 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
std::string const modmapFormat =
this->Makefile->GetSafeDefinition(modmapFormatVar);
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->GetLocalGenerator()->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander =
+ this->GetLocalGenerator()->CreateRulePlaceholderExpander();
std::string const tdi = this->GetLocalGenerator()->ConvertToOutputFormat(
this->ConvertToNinjaPath(this->GetTargetDependInfoPath(lang, config)),
@@ -1865,8 +1865,8 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
this->Makefile->GetRequiredDefinition(cmdVar);
cmList compileCmds(compileCmd);
- std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
- this->GetLocalGenerator()->CreateRulePlaceholderExpander());
+ auto rulePlaceholderExpander =
+ this->GetLocalGenerator()->CreateRulePlaceholderExpander();
for (auto& i : compileCmds) {
// no launcher for CMAKE_EXPORT_COMPILE_COMMANDS