summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx91
1 files changed, 52 insertions, 39 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 13a6ed7..dc741d3 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -15,7 +15,9 @@
#include <utility>
#include <cm/iterator>
+#include <cm/memory>
#include <cm/optional>
+#include <cm/vector>
#include <cmext/algorithm>
#include "cmsys/FStream.hxx"
@@ -122,15 +124,7 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
#endif
}
-cmMakefile::~cmMakefile()
-{
- cmDeleteAll(this->InstallGenerators);
- cmDeleteAll(this->TestGenerators);
- cmDeleteAll(this->SourceFiles);
- cmDeleteAll(this->Tests);
- cmDeleteAll(this->ImportedTargetsOwned);
- cmDeleteAll(this->EvaluationFiles);
-}
+cmMakefile::~cmMakefile() = default;
cmDirectoryId cmMakefile::GetDirectoryId() const
{
@@ -138,7 +132,7 @@ cmDirectoryId cmMakefile::GetDirectoryId() const
// If we ever need to expose this to CMake language code we should
// add a read-only property in cmMakefile::GetProperty.
char buf[32];
- sprintf(buf, "<%p>",
+ sprintf(buf, "(%p)",
static_cast<void const*>(this)); // cast avoids format warning
return std::string(buf);
}
@@ -772,12 +766,13 @@ void cmMakefile::AddEvaluationFile(
std::unique_ptr<cmCompiledGeneratorExpression> condition,
bool inputIsContent)
{
- this->EvaluationFiles.push_back(new cmGeneratorExpressionEvaluationFile(
- inputFile, std::move(outputName), std::move(condition), inputIsContent,
- this->GetPolicyStatus(cmPolicies::CMP0070)));
+ this->EvaluationFiles.push_back(
+ cm::make_unique<cmGeneratorExpressionEvaluationFile>(
+ inputFile, std::move(outputName), std::move(condition), inputIsContent,
+ this->GetPolicyStatus(cmPolicies::CMP0070)));
}
-std::vector<cmGeneratorExpressionEvaluationFile*>
+const std::vector<std::unique_ptr<cmGeneratorExpressionEvaluationFile>>&
cmMakefile::GetEvaluationFiles() const
{
return this->EvaluationFiles;
@@ -839,12 +834,12 @@ void cmMakefile::DoGenerate(cmLocalGenerator& lg)
// we don't want cmake to re-run if a configured file is created and deleted
// during processing as that would make it a transient file that can't
// influence the build process
- cmEraseIf(this->OutputFiles, file_not_persistent());
+ cm::erase_if(this->OutputFiles, file_not_persistent());
// if a configured file is used as input for another configured file,
// and then deleted it will show up in the input list files so we
// need to scan those too
- cmEraseIf(this->ListFiles, file_not_persistent());
+ cm::erase_if(this->ListFiles, file_not_persistent());
}
// Generate the output file
@@ -1423,6 +1418,20 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent)
this->RecursionDepth = parent->RecursionDepth;
}
+void cmMakefile::AddInstallGenerator(std::unique_ptr<cmInstallGenerator> g)
+{
+ if (g) {
+ this->InstallGenerators.push_back(std::move(g));
+ }
+}
+
+void cmMakefile::AddTestGenerator(std::unique_ptr<cmTestGenerator> g)
+{
+ if (g) {
+ this->TestGenerators.push_back(std::move(g));
+ }
+}
+
void cmMakefile::PushFunctionScope(std::string const& fileName,
const cmPolicies::PolicyMap& pm)
{
@@ -1723,8 +1732,10 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
cmSystemTools::MakeDirectory(binPath);
- cmMakefile* subMf = new cmMakefile(this->GlobalGenerator, newSnapshot);
- this->GetGlobalGenerator()->AddMakefile(subMf);
+ auto subMfu =
+ cm::make_unique<cmMakefile>(this->GlobalGenerator, newSnapshot);
+ auto subMf = subMfu.get();
+ this->GetGlobalGenerator()->AddMakefile(std::move(subMfu));
if (excludeFromAll) {
subMf->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
@@ -1736,7 +1747,7 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
this->UnConfiguredDirectories.push_back(subMf);
}
- this->AddInstallGenerator(new cmInstallSubdirectoryGenerator(
+ this->AddInstallGenerator(cm::make_unique<cmInstallSubdirectoryGenerator>(
subMf, binPath.c_str(), excludeFromAll));
}
@@ -2100,18 +2111,18 @@ cmSourceFile* cmMakefile::LinearGetSourceFileWithOutput(
// Look through all the source files that have custom commands and see if the
// custom command has the passed source file as an output.
- for (cmSourceFile* src : this->SourceFiles) {
+ for (const auto& src : this->SourceFiles) {
// Does this source file have a custom command?
if (src->GetCustomCommand()) {
// Does the output of the custom command match the source file name?
if (AnyOutputMatches(name, src->GetCustomCommand()->GetOutputs())) {
// Return the first matching output.
- return src;
+ return src.get();
}
if (kind == cmSourceOutputKind::OutputOrByproduct) {
if (AnyOutputMatches(name, src->GetCustomCommand()->GetByproducts())) {
// Do not return the source yet as there might be a matching output.
- fallback = src;
+ fallback = src.get();
}
}
}
@@ -3469,24 +3480,25 @@ cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName,
bool generated,
cmSourceFileLocationKind kind)
{
- cmSourceFile* sf = new cmSourceFile(this, sourceName, kind);
+ auto sf = cm::make_unique<cmSourceFile>(this, sourceName, kind);
if (generated) {
sf->SetProperty("GENERATED", "1");
}
- this->SourceFiles.push_back(sf);
auto name =
this->GetCMakeInstance()->StripExtension(sf->GetLocation().GetName());
#if defined(_WIN32) || defined(__APPLE__)
name = cmSystemTools::LowerCase(name);
#endif
- this->SourceFileSearchIndex[name].push_back(sf);
+ this->SourceFileSearchIndex[name].push_back(sf.get());
// for "Known" paths add direct lookup (used for faster lookup in GetSource)
if (kind == cmSourceFileLocationKind::Known) {
- this->KnownFileSearchIndex[sourceName] = sf;
+ this->KnownFileSearchIndex[sourceName] = sf.get();
}
- return sf;
+ this->SourceFiles.push_back(std::move(sf));
+
+ return this->SourceFiles.back().get();
}
cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName,
@@ -3615,8 +3627,7 @@ int cmMakefile::TryCompile(const std::string& srcdir,
// be run that way but the cmake object requires a vailid path
cmake cm(cmake::RoleProject, cmState::Project);
cm.SetIsInTryCompile(true);
- cmGlobalGenerator* gg =
- cm.CreateGlobalGenerator(this->GetGlobalGenerator()->GetName());
+ auto gg = cm.CreateGlobalGenerator(this->GetGlobalGenerator()->GetName());
if (!gg) {
this->IssueMessage(MessageType::INTERNAL_ERROR,
"Global generator '" +
@@ -3627,7 +3638,7 @@ int cmMakefile::TryCompile(const std::string& srcdir,
return 1;
}
gg->RecursionDepth = this->RecursionDepth;
- cm.SetGlobalGenerator(gg);
+ cm.SetGlobalGenerator(std::move(gg));
// do a configure
cm.SetHomeDirectory(srcdir);
@@ -3636,7 +3647,7 @@ int cmMakefile::TryCompile(const std::string& srcdir,
cm.SetGeneratorPlatform(this->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM"));
cm.SetGeneratorToolset(this->GetSafeDefinition("CMAKE_GENERATOR_TOOLSET"));
cm.LoadCache();
- if (!gg->IsMultiConfig()) {
+ if (!cm.GetGlobalGenerator()->IsMultiConfig()) {
if (const char* config =
this->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION")) {
// Tell the single-configuration generator which one to use.
@@ -3682,7 +3693,8 @@ int cmMakefile::TryCompile(const std::string& srcdir,
cm.SetCacheArgs(*cmakeArgs);
}
// to save time we pass the EnableLanguage info directly
- gg->EnableLanguagesFromGenerator(this->GetGlobalGenerator(), this);
+ cm.GetGlobalGenerator()->EnableLanguagesFromGenerator(
+ this->GetGlobalGenerator(), this);
if (this->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS")) {
cm.AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE", "",
cmStateEnums::INTERNAL);
@@ -4080,9 +4092,10 @@ cmTest* cmMakefile::CreateTest(const std::string& testName)
if (test) {
return test;
}
- test = new cmTest(this);
- test->SetName(testName);
- this->Tests[testName] = test;
+ auto newTest = cm::make_unique<cmTest>(this);
+ test = newTest.get();
+ newTest->SetName(testName);
+ this->Tests[testName] = std::move(newTest);
return test;
}
@@ -4090,7 +4103,7 @@ cmTest* cmMakefile::GetTest(const std::string& testName) const
{
auto mi = this->Tests.find(testName);
if (mi != this->Tests.end()) {
- return mi->second;
+ return mi->second.get();
}
return nullptr;
}
@@ -4098,7 +4111,7 @@ cmTest* cmMakefile::GetTest(const std::string& testName) const
void cmMakefile::GetTests(const std::string& config,
std::vector<cmTest*>& tests)
{
- for (auto generator : this->GetTestGenerators()) {
+ for (const auto& generator : this->GetTestGenerators()) {
if (generator->TestsForConfig(config)) {
tests.push_back(generator->GetTest());
}
@@ -4211,8 +4224,8 @@ cmTarget* cmMakefile::AddImportedTarget(const std::string& name,
this->GetGlobalGenerator()->IndexTarget(target.get());
// Transfer ownership to this cmMakefile object.
- this->ImportedTargetsOwned.push_back(target.get());
- return target.release();
+ this->ImportedTargetsOwned.push_back(std::move(target));
+ return this->ImportedTargetsOwned.back().get();
}
cmTarget* cmMakefile::FindTargetToUse(const std::string& name,