summaryrefslogtreecommitdiffstats
path: root/Source/cmake.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r--Source/cmake.cxx145
1 files changed, 67 insertions, 78 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 5341971..ab76df9 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -71,6 +71,8 @@
// include the generator
#if defined(_WIN32) && !defined(__CYGWIN__)
# if !defined(CMAKE_BOOT_MINGW)
+# include <cmext/memory>
+
# include "cmGlobalBorlandMakefileGenerator.h"
# include "cmGlobalJOMMakefileGenerator.h"
# include "cmGlobalNMakeMakefileGenerator.h"
@@ -203,14 +205,7 @@ cmake::cmake(Role role, cmState::Mode mode)
}
}
-cmake::~cmake()
-{
- if (this->GlobalGenerator) {
- delete this->GlobalGenerator;
- this->GlobalGenerator = nullptr;
- }
- cmDeleteAll(this->Generators);
-}
+cmake::~cmake() = default;
#if !defined(CMAKE_BOOTSTRAP)
Json::Value cmake::ReportVersionJson() const
@@ -463,12 +458,12 @@ void cmake::ReadListFile(const std::vector<std::string>& args,
{
// if a generator was not yet created, temporarily create one
cmGlobalGenerator* gg = this->GetGlobalGenerator();
- bool created = false;
// if a generator was not specified use a generic one
+ std::unique_ptr<cmGlobalGenerator> gen;
if (!gg) {
- gg = new cmGlobalGenerator(this);
- created = true;
+ gen = cm::make_unique<cmGlobalGenerator>(this);
+ gg = gen.get();
}
// read in the list file to fill the cache
@@ -490,11 +485,6 @@ void cmake::ReadListFile(const std::vector<std::string>& args,
cmSystemTools::Error("Error processing file: " + path);
}
}
-
- // free generic one if generated
- if (created) {
- delete gg;
- }
}
bool cmake::FindPackage(const std::vector<std::string>& args)
@@ -502,9 +492,7 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
this->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory());
this->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory());
- // if a generator was not yet created, temporarily create one
- cmGlobalGenerator* gg = new cmGlobalGenerator(this);
- this->SetGlobalGenerator(gg);
+ this->SetGlobalGenerator(cm::make_unique<cmGlobalGenerator>(this));
cmStateSnapshot snapshot = this->GetCurrentSnapshot();
snapshot.GetDirectory().SetCurrentBinary(
@@ -513,9 +501,9 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
cmSystemTools::GetCurrentWorkingDirectory());
// read in the list file to fill the cache
snapshot.SetDefaultDefinitions();
- auto mfu = cm::make_unique<cmMakefile>(gg, snapshot);
+ auto mfu = cm::make_unique<cmMakefile>(this->GetGlobalGenerator(), snapshot);
cmMakefile* mf = mfu.get();
- gg->AddMakefile(std::move(mfu));
+ this->GlobalGenerator->AddMakefile(std::move(mfu));
mf->SetArgcArgv(args);
@@ -540,8 +528,8 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS");
std::vector<std::string> includeDirs = cmExpandedList(includes);
- gg->CreateGenerationObjects();
- const auto& lg = gg->LocalGenerators[0];
+ this->GlobalGenerator->CreateGenerationObjects();
+ const auto& lg = this->GlobalGenerator->LocalGenerators[0];
std::string includeFlags =
lg->GetIncludeFlags(includeDirs, nullptr, language);
@@ -567,8 +555,9 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
std::string linkPath;
std::string flags;
std::string linkFlags;
- gg->CreateGenerationObjects();
- cmGeneratorTarget* gtgt = gg->FindGeneratorTarget(tgt->GetName());
+ this->GlobalGenerator->CreateGenerationObjects();
+ cmGeneratorTarget* gtgt =
+ this->GlobalGenerator->FindGeneratorTarget(tgt->GetName());
cmLocalGenerator* lg = gtgt->GetLocalGenerator();
cmLinkLineComputer linkLineComputer(lg,
lg->GetStateSnapshot().GetDirectory());
@@ -588,10 +577,6 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
}*/
}
- // free generic one if generated
- // this->SetGlobalGenerator(0); // setting 0-pointer is not possible
- // delete gg; // this crashes inside the cmake instance
-
return packageFound;
}
@@ -839,7 +824,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
}
value = args[i];
}
- cmGlobalGenerator* gen = this->CreateGlobalGenerator(value);
+ auto gen = this->CreateGlobalGenerator(value);
if (!gen) {
std::string kdevError;
if (value.find("KDevelop3", 0) != std::string::npos) {
@@ -851,7 +836,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
this->PrintGeneratorList();
return;
}
- this->SetGlobalGenerator(gen);
+ this->SetGlobalGenerator(std::move(gen));
}
// no option assume it is the path to the source or an existing build
else {
@@ -1119,7 +1104,7 @@ void cmake::AddDefaultExtraGenerators()
void cmake::GetRegisteredGenerators(std::vector<GeneratorInfo>& generators,
bool includeNamesWithPlatform) const
{
- for (cmGlobalGeneratorFactory* gen : this->Generators) {
+ for (const auto& gen : this->Generators) {
std::vector<std::string> names = gen->GetGeneratorNames();
if (includeNamesWithPlatform) {
@@ -1168,7 +1153,8 @@ void cmake::GetRegisteredGenerators(std::vector<GeneratorInfo>& generators,
}
}
-static std::pair<cmExternalMakefileProjectGenerator*, std::string>
+static std::pair<std::unique_ptr<cmExternalMakefileProjectGenerator>,
+ std::string>
createExtraGenerator(
const std::vector<cmExternalMakefileProjectGeneratorFactory*>& in,
const std::string& name)
@@ -1191,15 +1177,17 @@ createExtraGenerator(
return { nullptr, name };
}
-cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname)
+std::unique_ptr<cmGlobalGenerator> cmake::CreateGlobalGenerator(
+ const std::string& gname)
{
- std::pair<cmExternalMakefileProjectGenerator*, std::string> extra =
- createExtraGenerator(this->ExtraGenerators, gname);
- cmExternalMakefileProjectGenerator* extraGenerator = extra.first;
- const std::string name = extra.second;
+ std::pair<std::unique_ptr<cmExternalMakefileProjectGenerator>, std::string>
+ extra = createExtraGenerator(this->ExtraGenerators, gname);
+ std::unique_ptr<cmExternalMakefileProjectGenerator>& extraGenerator =
+ extra.first;
+ const std::string& name = extra.second;
- cmGlobalGenerator* generator = nullptr;
- for (cmGlobalGeneratorFactory* g : this->Generators) {
+ std::unique_ptr<cmGlobalGenerator> generator;
+ for (const auto& g : this->Generators) {
generator = g->CreateGlobalGenerator(name, this);
if (generator) {
break;
@@ -1207,9 +1195,7 @@ cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname)
}
if (generator) {
- generator->SetExternalMakefileProjectGenerator(extraGenerator);
- } else {
- delete extraGenerator;
+ generator->SetExternalMakefileProjectGenerator(std::move(extraGenerator));
}
return generator;
@@ -1261,15 +1247,13 @@ std::string cmake::FindCacheFile(const std::string& binaryDir)
return cachePath;
}
-void cmake::SetGlobalGenerator(cmGlobalGenerator* gg)
+void cmake::SetGlobalGenerator(std::unique_ptr<cmGlobalGenerator> gg)
{
if (!gg) {
cmSystemTools::Error("Error SetGlobalGenerator called with null");
return;
}
- // delete the old generator
if (this->GlobalGenerator) {
- delete this->GlobalGenerator;
// restore the original environment variables CXX and CC
// Restore CC
std::string env = "CC=";
@@ -1285,7 +1269,7 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator* gg)
}
// set the new
- this->GlobalGenerator = gg;
+ this->GlobalGenerator = std::move(gg);
// set the global flag for unix style paths on cmSystemTools as soon as
// the generator is set. This allows gmake to be used on windows.
@@ -1669,13 +1653,12 @@ int cmake::ActualConfigure()
std::unique_ptr<cmGlobalGenerator> cmake::EvaluateDefaultGlobalGenerator()
{
if (!this->EnvironmentGenerator.empty()) {
- cmGlobalGenerator* gen =
- this->CreateGlobalGenerator(this->EnvironmentGenerator);
+ auto gen = this->CreateGlobalGenerator(this->EnvironmentGenerator);
if (!gen) {
cmSystemTools::Error("CMAKE_GENERATOR was set but the specified "
"generator doesn't exist. Using CMake default.");
} else {
- return std::unique_ptr<cmGlobalGenerator>(gen);
+ return gen;
}
}
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
@@ -1725,13 +1708,14 @@ std::unique_ptr<cmGlobalGenerator> cmake::EvaluateDefaultGlobalGenerator()
}
}
}
- cmGlobalGenerator* gen = this->CreateGlobalGenerator(found);
+ auto gen = this->CreateGlobalGenerator(found);
if (!gen) {
- gen = new cmGlobalNMakeMakefileGenerator(this);
+ gen = cm::make_unique<cmGlobalNMakeMakefileGenerator>(this);
}
- return std::unique_ptr<cmGlobalGenerator>(gen);
+ return std::unique_ptr<cmGlobalGenerator>(std::move(gen));
#else
- return cm::make_unique<cmGlobalUnixMakefileGenerator3>(this);
+ return std::unique_ptr<cmGlobalGenerator>(
+ cm::make_unique<cmGlobalUnixMakefileGenerator3>(this));
#endif
}
@@ -1742,7 +1726,7 @@ void cmake::CreateDefaultGlobalGenerator()
// This print could be unified for all platforms
std::cout << "-- Building for: " << gen->GetName() << "\n";
#endif
- this->SetGlobalGenerator(gen.release());
+ this->SetGlobalGenerator(std::move(gen));
}
void cmake::PreLoadCMakeFiles()
@@ -1845,10 +1829,11 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
cmSystemTools::Message("CMake Configure step failed. "
"Build files cannot be regenerated correctly. "
"Attempting to stop IDE build.");
- cmGlobalVisualStudioGenerator* gg =
- static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
- gg->CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop,
- this->VSSolutionFile);
+ cmGlobalVisualStudioGenerator& gg =
+ cm::static_reference_cast<cmGlobalVisualStudioGenerator>(
+ this->GlobalGenerator);
+ gg.CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop,
+ this->VSSolutionFile);
}
#endif
return ret;
@@ -2104,7 +2089,7 @@ void cmake::AppendGlobalGeneratorsDocumentation(
const std::string defaultName = defaultGenerator->GetName();
bool foundDefaultOne = false;
- for (cmGlobalGeneratorFactory* g : this->Generators) {
+ for (const auto& g : this->Generators) {
cmDocumentationEntry e;
g->GetDocumentation(e);
if (!foundDefaultOne && cmHasPrefix(e.Name, defaultName)) {
@@ -2244,8 +2229,8 @@ int cmake::CheckBuildSystem()
}
// Create the generator and use it to clear the dependencies.
- std::unique_ptr<cmGlobalGenerator> ggd(
- this->CreateGlobalGenerator(genName));
+ std::unique_ptr<cmGlobalGenerator> ggd =
+ this->CreateGlobalGenerator(genName);
if (ggd) {
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmMakefile mfd(ggd.get(), cm.GetCurrentSnapshot());
@@ -2458,12 +2443,12 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
}
value = args[i];
}
- cmGlobalGenerator* gen = this->CreateGlobalGenerator(value);
+ auto gen = this->CreateGlobalGenerator(value);
if (!gen) {
cmSystemTools::Error("Could not create named generator " + value);
this->PrintGeneratorList();
} else {
- this->SetGlobalGenerator(gen);
+ this->SetGlobalGenerator(std::move(gen));
}
}
// no option assume it is the output file
@@ -2675,34 +2660,37 @@ int cmake::Build(int jobs, const std::string& dir,
std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
return 1;
}
- cmGlobalGenerator* gen = this->CreateGlobalGenerator(cachedGenerator);
+ auto gen = this->CreateGlobalGenerator(cachedGenerator);
if (!gen) {
std::cerr << "Error: could create CMAKE_GENERATOR \"" << cachedGenerator
<< "\"\n";
return 1;
}
- this->SetGlobalGenerator(gen);
+ this->SetGlobalGenerator(std::move(gen));
const char* cachedGeneratorInstance =
this->State->GetCacheEntryValue("CMAKE_GENERATOR_INSTANCE");
if (cachedGeneratorInstance) {
- cmMakefile mf(gen, this->GetCurrentSnapshot());
- if (!gen->SetGeneratorInstance(cachedGeneratorInstance, &mf)) {
+ cmMakefile mf(this->GetGlobalGenerator(), this->GetCurrentSnapshot());
+ if (!this->GlobalGenerator->SetGeneratorInstance(cachedGeneratorInstance,
+ &mf)) {
return 1;
}
}
const char* cachedGeneratorPlatform =
this->State->GetCacheEntryValue("CMAKE_GENERATOR_PLATFORM");
if (cachedGeneratorPlatform) {
- cmMakefile mf(gen, this->GetCurrentSnapshot());
- if (!gen->SetGeneratorPlatform(cachedGeneratorPlatform, &mf)) {
+ cmMakefile mf(this->GetGlobalGenerator(), this->GetCurrentSnapshot());
+ if (!this->GlobalGenerator->SetGeneratorPlatform(cachedGeneratorPlatform,
+ &mf)) {
return 1;
}
}
const char* cachedGeneratorToolset =
this->State->GetCacheEntryValue("CMAKE_GENERATOR_TOOLSET");
if (cachedGeneratorToolset) {
- cmMakefile mf(gen, this->GetCurrentSnapshot());
- if (!gen->SetGeneratorToolset(cachedGeneratorToolset, true, &mf)) {
+ cmMakefile mf(this->GetGlobalGenerator(), this->GetCurrentSnapshot());
+ if (!this->GlobalGenerator->SetGeneratorToolset(cachedGeneratorToolset,
+ true, &mf)) {
return 1;
}
}
@@ -2777,10 +2765,11 @@ int cmake::Build(int jobs, const std::string& dir,
}
#endif
- gen->PrintBuildCommandAdvice(std::cerr, jobs);
- return gen->Build(jobs, "", dir, projName, targets, output, "", config,
- clean, false, verbose, cmDuration::zero(),
- cmSystemTools::OUTPUT_PASSTHROUGH, nativeOptions);
+ this->GlobalGenerator->PrintBuildCommandAdvice(std::cerr, jobs);
+ return this->GlobalGenerator->Build(
+ jobs, "", dir, projName, targets, output, "", config, clean, false,
+ verbose, cmDuration::zero(), cmSystemTools::OUTPUT_PASSTHROUGH,
+ nativeOptions);
}
bool cmake::Open(const std::string& dir, bool dryRun)
@@ -2808,8 +2797,8 @@ bool cmake::Open(const std::string& dir, bool dryRun)
cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
genName, extraGenName ? *extraGenName : "");
- std::unique_ptr<cmGlobalGenerator> gen(
- this->CreateGlobalGenerator(fullName));
+ std::unique_ptr<cmGlobalGenerator> gen =
+ this->CreateGlobalGenerator(fullName);
if (!gen) {
std::cerr << "Error: could create CMAKE_GENERATOR \"" << fullName
<< "\"\n";