Commit ccd2c282 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'modernize-memory-management'

f9338528 cmLocalGenerator: modernize memory management
101b5288

 cmAlgorithm: Extend cmAppend capabilities
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !4028
parents aec81b30 f9338528
Pipeline #151059 passed with stage
in 0 seconds
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <iterator> #include <iterator>
#include <memory>
#include <unordered_set> #include <unordered_set>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -144,6 +145,13 @@ void cmDeleteAll(Range const& r) ...@@ -144,6 +145,13 @@ void cmDeleteAll(Range const& r)
ContainerAlgorithms::DefaultDeleter<Range>()); ContainerAlgorithms::DefaultDeleter<Range>());
} }
template <typename T>
void cmAppend(std::vector<T*>& v, std::vector<std::unique_ptr<T>> const& r)
{
std::transform(r.begin(), r.end(), std::back_inserter(v),
[](const std::unique_ptr<T>& item) { return item.get(); });
}
template <typename T, typename Range> template <typename T, typename Range>
void cmAppend(std::vector<T>& v, Range const& r) void cmAppend(std::vector<T>& v, Range const& r)
{ {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <cassert> #include <cassert>
#include <cstdio> #include <cstdio>
#include <memory>
#include <sstream> #include <sstream>
#include <utility> #include <utility>
...@@ -160,12 +161,10 @@ void cmComputeTargetDepends::CollectTargets() ...@@ -160,12 +161,10 @@ void cmComputeTargetDepends::CollectTargets()
std::vector<cmLocalGenerator*> const& lgens = std::vector<cmLocalGenerator*> const& lgens =
this->GlobalGenerator->GetLocalGenerators(); this->GlobalGenerator->GetLocalGenerators();
for (cmLocalGenerator* lgen : lgens) { for (cmLocalGenerator* lgen : lgens) {
const std::vector<cmGeneratorTarget*>& targets = for (const auto& ti : lgen->GetGeneratorTargets()) {
lgen->GetGeneratorTargets();
for (cmGeneratorTarget const* ti : targets) {
int index = static_cast<int>(this->Targets.size()); int index = static_cast<int>(this->Targets.size());
this->TargetIndex[ti] = index; this->TargetIndex[ti.get()] = index;
this->Targets.push_back(ti); this->Targets.push_back(ti.get());
} }
} }
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "cmExtraCodeBlocksGenerator.h" #include "cmExtraCodeBlocksGenerator.h"
#include <map> #include <map>
#include <memory>
#include <ostream> #include <ostream>
#include <set> #include <set>
#include <utility> #include <utility>
...@@ -283,8 +284,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( ...@@ -283,8 +284,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
// add all executable and library targets and some of the GLOBAL // add all executable and library targets and some of the GLOBAL
// and UTILITY targets // and UTILITY targets
for (cmLocalGenerator* lg : lgs) { for (cmLocalGenerator* lg : lgs) {
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets(); const auto& targets = lg->GetGeneratorTargets();
for (cmGeneratorTarget* target : targets) { for (const auto& target : targets) {
std::string targetName = target->GetName(); std::string targetName = target->GetName();
switch (target->GetType()) { switch (target->GetType()) {
case cmStateEnums::GLOBAL_TARGET: { case cmStateEnums::GLOBAL_TARGET: {
...@@ -315,7 +316,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( ...@@ -315,7 +316,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
case cmStateEnums::SHARED_LIBRARY: case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY: case cmStateEnums::MODULE_LIBRARY:
case cmStateEnums::OBJECT_LIBRARY: { case cmStateEnums::OBJECT_LIBRARY: {
cmGeneratorTarget* gt = target; cmGeneratorTarget* gt = target.get();
this->AppendTarget(xml, targetName, gt, make, lg, compiler, this->AppendTarget(xml, targetName, gt, make, lg, compiler,
makeArgs); makeArgs);
std::string fastTarget = cmStrCat(targetName, "/fast"); std::string fastTarget = cmStrCat(targetName, "/fast");
...@@ -341,8 +342,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( ...@@ -341,8 +342,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
for (cmLocalGenerator* lg : lgs) { for (cmLocalGenerator* lg : lgs) {
cmMakefile* makefile = lg->GetMakefile(); cmMakefile* makefile = lg->GetMakefile();
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets(); const auto& targets = lg->GetGeneratorTargets();
for (cmGeneratorTarget* target : targets) { for (const auto& target : targets) {
switch (target->GetType()) { switch (target->GetType()) {
case cmStateEnums::EXECUTABLE: case cmStateEnums::EXECUTABLE:
case cmStateEnums::STATIC_LIBRARY: case cmStateEnums::STATIC_LIBRARY:
...@@ -352,13 +353,12 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( ...@@ -352,13 +353,12 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
case cmStateEnums::UTILITY: // can have sources since 2.6.3 case cmStateEnums::UTILITY: // can have sources since 2.6.3
{ {
std::vector<cmSourceFile*> sources; std::vector<cmSourceFile*> sources;
cmGeneratorTarget* gt = target; target->GetSourceFiles(
gt->GetSourceFiles(sources, sources, makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
for (cmSourceFile* s : sources) { for (cmSourceFile* s : sources) {
// don't add source files from UTILITY target which have the // don't add source files from UTILITY target which have the
// GENERATED property set: // GENERATED property set:
if (gt->GetType() == cmStateEnums::UTILITY && if (target->GetType() == cmStateEnums::UTILITY &&
s->GetIsGenerated()) { s->GetIsGenerated()) {
continue; continue;
} }
...@@ -391,7 +391,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( ...@@ -391,7 +391,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
} }
CbpUnit& cbpUnit = allFiles[fullPath]; CbpUnit& cbpUnit = allFiles[fullPath];
cbpUnit.Targets.push_back(target); cbpUnit.Targets.push_back(target.get());
} }
} }
default: // intended fallthrough default: // intended fallthrough
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <cstring> #include <cstring>
#include <map> #include <map>
#include <memory>
#include <set> #include <set>
#include <sstream> #include <sstream>
#include <utility> #include <utility>
...@@ -119,7 +120,7 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByTarget( ...@@ -119,7 +120,7 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByTarget(
const std::vector<cmLocalGenerator*>& lgs = const std::vector<cmLocalGenerator*>& lgs =
this->GlobalGenerator->GetLocalGenerators(); this->GlobalGenerator->GetLocalGenerators();
for (cmLocalGenerator* lg : lgs) { for (cmLocalGenerator* lg : lgs) {
for (cmGeneratorTarget* lt : lg->GetGeneratorTargets()) { for (const auto& lt : lg->GetGeneratorTargets()) {
cmStateEnums::TargetType type = lt->GetType(); cmStateEnums::TargetType type = lt->GetType();
std::string const& outputDir = lg->GetCurrentBinaryDirectory(); std::string const& outputDir = lg->GetCurrentBinaryDirectory();
std::string targetName = lt->GetName(); std::string targetName = lt->GetName();
...@@ -142,7 +143,7 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByTarget( ...@@ -142,7 +143,7 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByTarget(
xml->Attribute("Active", "No"); xml->Attribute("Active", "No");
xml->EndElement(); xml->EndElement();
CreateNewProjectFile(lt, filename); CreateNewProjectFile(lt.get(), filename);
break; break;
default: default:
break; break;
...@@ -269,9 +270,9 @@ void cmExtraCodeLiteGenerator::CreateNewProjectFile( ...@@ -269,9 +270,9 @@ void cmExtraCodeLiteGenerator::CreateNewProjectFile(
for (cmLocalGenerator* lg : lgs) { for (cmLocalGenerator* lg : lgs) {
cmMakefile* makefile = lg->GetMakefile(); cmMakefile* makefile = lg->GetMakefile();
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets(); for (const auto& target : lg->GetGeneratorTargets()) {
for (cmGeneratorTarget* target : targets) { projectType =
projectType = CollectSourceFiles(makefile, target, cFiles, otherFiles); CollectSourceFiles(makefile, target.get(), cFiles, otherFiles);
} }
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <cassert> #include <cassert>
#include <cstdio> #include <cstdio>
#include <map> #include <map>
#include <memory>
#include <sstream> #include <sstream>
#include <utility> #include <utility>
...@@ -496,9 +497,9 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml) ...@@ -496,9 +497,9 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml)
for (cmLocalGenerator* lg : this->GlobalGenerator->GetLocalGenerators()) { for (cmLocalGenerator* lg : this->GlobalGenerator->GetLocalGenerators()) {
cmMakefile* makefile = lg->GetMakefile(); cmMakefile* makefile = lg->GetMakefile();
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets(); const auto& targets = lg->GetGeneratorTargets();
for (cmGeneratorTarget* target : targets) { for (const auto& target : targets) {
std::string linkName2 = cmStrCat(linkName, '/'); std::string linkName2 = cmStrCat(linkName, '/');
switch (target->GetType()) { switch (target->GetType()) {
case cmStateEnums::EXECUTABLE: case cmStateEnums::EXECUTABLE:
...@@ -519,10 +520,9 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml) ...@@ -519,10 +520,9 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml)
std::vector<cmSourceGroup> sourceGroups = std::vector<cmSourceGroup> sourceGroups =
makefile->GetSourceGroups(); makefile->GetSourceGroups();
// get the files from the source lists then add them to the groups // get the files from the source lists then add them to the groups
cmGeneratorTarget* gt = const_cast<cmGeneratorTarget*>(target);
std::vector<cmSourceFile*> files; std::vector<cmSourceFile*> files;
gt->GetSourceFiles(files, target->GetSourceFiles(
makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); files, makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
for (cmSourceFile* sf : files) { for (cmSourceFile* sf : files) {
// Add the file to the list of sources. // Add the file to the list of sources.
std::string const& source = sf->ResolveFullPath(); std::string const& source = sf->ResolveFullPath();
...@@ -860,15 +860,14 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const ...@@ -860,15 +860,14 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
// include dirs // include dirs
emmited.clear(); emmited.clear();
for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) { for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
const std::vector<cmGeneratorTarget*>& targets = const auto& targets = lgen->GetGeneratorTargets();
lgen->GetGeneratorTargets(); for (const auto& target : targets) {
for (cmGeneratorTarget* target : targets) {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue; continue;
} }
std::vector<std::string> includeDirs; std::vector<std::string> includeDirs;
std::string config = mf->GetSafeDefinition("CMAKE_BUILD_TYPE"); std::string config = mf->GetSafeDefinition("CMAKE_BUILD_TYPE");
lgen->GetIncludeDirectories(includeDirs, target, "C", config); lgen->GetIncludeDirectories(includeDirs, target.get(), "C", config);
this->AppendIncludeDirectories(xml, includeDirs, emmited); this->AppendIncludeDirectories(xml, includeDirs, emmited);
} }
} }
...@@ -916,15 +915,14 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const ...@@ -916,15 +915,14 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
// add all executable and library targets and some of the GLOBAL // add all executable and library targets and some of the GLOBAL
// and UTILITY targets // and UTILITY targets
for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) { for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
const std::vector<cmGeneratorTarget*>& targets = const auto& targets = lgen->GetGeneratorTargets();
lgen->GetGeneratorTargets();
std::string subdir = lgen->MaybeConvertToRelativePath( std::string subdir = lgen->MaybeConvertToRelativePath(
this->HomeOutputDirectory, lgen->GetCurrentBinaryDirectory()); this->HomeOutputDirectory, lgen->GetCurrentBinaryDirectory());
if (subdir == ".") { if (subdir == ".") {
subdir.clear(); subdir.clear();
} }
for (cmGeneratorTarget* target : targets) { for (const auto& target : targets) {
std::string targetName = target->GetName(); std::string targetName = target->GetName();
switch (target->GetType()) { switch (target->GetType()) {
case cmStateEnums::GLOBAL_TARGET: { case cmStateEnums::GLOBAL_TARGET: {
...@@ -975,8 +973,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const ...@@ -975,8 +973,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
std::string cleanArgs = std::string cleanArgs =
cmStrCat("-E chdir \"", lgen->GetCurrentBinaryDirectory(), cmStrCat("-E chdir \"", lgen->GetCurrentBinaryDirectory(),
"\" \"", cmSystemTools::GetCMakeCommand(), "\" -P \""); "\" \"", cmSystemTools::GetCMakeCommand(), "\" -P \"");
cmGeneratorTarget* gt = target; cleanArgs += lgen->GetTargetDirectory(target.get());
cleanArgs += lgen->GetTargetDirectory(gt);
cleanArgs += "/cmake_clean.cmake\""; cleanArgs += "/cmake_clean.cmake\"";
cmExtraEclipseCDT4Generator::AppendTarget( cmExtraEclipseCDT4Generator::AppendTarget(
xml, "Clean", cmSystemTools::GetCMakeCommand(), cleanArgs, xml, "Clean", cmSystemTools::GetCMakeCommand(), cleanArgs,
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "cmExtraKateGenerator.h" #include "cmExtraKateGenerator.h"
#include <cstring> #include <cstring>
#include <memory>
#include <ostream> #include <ostream>
#include <set> #include <set>
#include <vector> #include <vector>
...@@ -111,12 +112,11 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg, ...@@ -111,12 +112,11 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg,
// and UTILITY targets // and UTILITY targets
for (cmLocalGenerator* localGen : for (cmLocalGenerator* localGen :
this->GlobalGenerator->GetLocalGenerators()) { this->GlobalGenerator->GetLocalGenerators()) {
const std::vector<cmGeneratorTarget*>& targets = const auto& targets = localGen->GetGeneratorTargets();
localGen->GetGeneratorTargets();
std::string currentDir = localGen->GetCurrentBinaryDirectory(); std::string currentDir = localGen->GetCurrentBinaryDirectory();
bool topLevel = (currentDir == localGen->GetBinaryDirectory()); bool topLevel = (currentDir == localGen->GetBinaryDirectory());
for (cmGeneratorTarget* target : targets) { for (const auto& target : targets) {
std::string const& targetName = target->GetName(); std::string const& targetName = target->GetName();
switch (target->GetType()) { switch (target->GetType()) {
case cmStateEnums::GLOBAL_TARGET: { case cmStateEnums::GLOBAL_TARGET: {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "cmExtraSublimeTextGenerator.h" #include "cmExtraSublimeTextGenerator.h"
#include <cstring> #include <cstring>
#include <memory>
#include <set> #include <set>
#include <sstream> #include <sstream>
#include <utility> #include <utility>
...@@ -182,8 +183,8 @@ void cmExtraSublimeTextGenerator::AppendAllTargets( ...@@ -182,8 +183,8 @@ void cmExtraSublimeTextGenerator::AppendAllTargets(
// and UTILITY targets // and UTILITY targets
for (cmLocalGenerator* lg : lgs) { for (cmLocalGenerator* lg : lgs) {
cmMakefile* makefile = lg->GetMakefile(); cmMakefile* makefile = lg->GetMakefile();
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets(); const auto& targets = lg->GetGeneratorTargets();
for (cmGeneratorTarget* target : targets) { for (const auto& target : targets) {
std::string targetName = target->GetName(); std::string targetName = target->GetName();
switch (target->GetType()) { switch (target->GetType()) {
case cmStateEnums::GLOBAL_TARGET: { case cmStateEnums::GLOBAL_TARGET: {
...@@ -216,11 +217,11 @@ void cmExtraSublimeTextGenerator::AppendAllTargets( ...@@ -216,11 +217,11 @@ void cmExtraSublimeTextGenerator::AppendAllTargets(
case cmStateEnums::SHARED_LIBRARY: case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY: case cmStateEnums::MODULE_LIBRARY:
case cmStateEnums::OBJECT_LIBRARY: { case cmStateEnums::OBJECT_LIBRARY: {
this->AppendTarget(fout, targetName, lg, target, make.c_str(), this->AppendTarget(fout, targetName, lg, target.get(), make.c_str(),
makefile, compiler.c_str(), sourceFileFlags, makefile, compiler.c_str(), sourceFileFlags,
false); false);
std::string fastTarget = cmStrCat(targetName, "/fast"); std::string fastTarget = cmStrCat(targetName, "/fast");
this->AppendTarget(fout, fastTarget, lg, target, make.c_str(), this->AppendTarget(fout, fastTarget, lg, target.get(), make.c_str(),
makefile, compiler.c_str(), sourceFileFlags, makefile, compiler.c_str(), sourceFileFlags,
false); false);
} break; } break;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGlobalCommonGenerator.h" #include "cmGlobalCommonGenerator.h"
#include <memory>
#include <utility> #include <utility>
#include "cmGeneratorTarget.h" #include "cmGeneratorTarget.h"
...@@ -32,7 +33,7 @@ cmGlobalCommonGenerator::ComputeDirectoryTargets() const ...@@ -32,7 +33,7 @@ cmGlobalCommonGenerator::ComputeDirectoryTargets() const
// The directory-level rule should depend on the target-level rules // The directory-level rule should depend on the target-level rules
// for all targets in the directory. // for all targets in the directory.
for (auto gt : lg->GetGeneratorTargets()) { for (const auto& gt : lg->GetGeneratorTargets()) {
cmStateEnums::TargetType const type = gt->GetType(); cmStateEnums::TargetType const type = gt->GetType();
if (type != cmStateEnums::EXECUTABLE && if (type != cmStateEnums::EXECUTABLE &&
type != cmStateEnums::STATIC_LIBRARY && type != cmStateEnums::STATIC_LIBRARY &&
...@@ -43,7 +44,7 @@ cmGlobalCommonGenerator::ComputeDirectoryTargets() const ...@@ -43,7 +44,7 @@ cmGlobalCommonGenerator::ComputeDirectoryTargets() const
continue; continue;
} }
DirectoryTarget::Target t; DirectoryTarget::Target t;
t.GT = gt; t.GT = gt.get();
if (const char* exclude = gt->GetProperty("EXCLUDE_FROM_ALL")) { if (const char* exclude = gt->GetProperty("EXCLUDE_FROM_ALL")) {
if (cmIsOn(exclude)) { if (cmIsOn(exclude)) {
// This target has been explicitly excluded. // This target has been explicitly excluded.
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#include <initializer_list> #include <initializer_list>
#include <iterator> #include <iterator>
#include <sstream> #include <sstream>
#include <utility>
#include <cm/memory>
#include "cmsys/Directory.hxx" #include "cmsys/Directory.hxx"
#include "cmsys/FStream.hxx" #include "cmsys/FStream.hxx"
...@@ -296,7 +299,7 @@ bool cmGlobalGenerator::CheckTargetsForMissingSources() const ...@@ -296,7 +299,7 @@ bool cmGlobalGenerator::CheckTargetsForMissingSources() const
{ {
bool failed = false; bool failed = false;
for (cmLocalGenerator* localGen : this->LocalGenerators) { for (cmLocalGenerator* localGen : this->LocalGenerators) {
for (cmGeneratorTarget* target : localGen->GetGeneratorTargets()) { for (const auto& target : localGen->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET || if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET ||
target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY || target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY ||
target->GetType() == cmStateEnums::TargetType::UTILITY || target->GetType() == cmStateEnums::TargetType::UTILITY ||
...@@ -336,7 +339,7 @@ bool cmGlobalGenerator::CheckTargetsForType() const ...@@ -336,7 +339,7 @@ bool cmGlobalGenerator::CheckTargetsForType() const
} }
bool failed = false; bool failed = false;
for (cmLocalGenerator* generator : this->LocalGenerators) { for (cmLocalGenerator* generator : this->LocalGenerators) {
for (cmGeneratorTarget* target : generator->GetGeneratorTargets()) { for (const auto& target : generator->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::EXECUTABLE && if (target->GetType() == cmStateEnums::EXECUTABLE &&
target->GetPropertyAsBool("WIN32_EXECUTABLE")) { target->GetPropertyAsBool("WIN32_EXECUTABLE")) {
std::vector<std::string> const& configs = std::vector<std::string> const& configs =
...@@ -364,7 +367,7 @@ bool cmGlobalGenerator::CheckTargetsForPchCompilePdb() const ...@@ -364,7 +367,7 @@ bool cmGlobalGenerator::CheckTargetsForPchCompilePdb() const
} }
bool failed = false; bool failed = false;
for (cmLocalGenerator* generator : this->LocalGenerators) { for (cmLocalGenerator* generator : this->LocalGenerators) {
for (cmGeneratorTarget* target : generator->GetGeneratorTargets()) { for (const auto& target : generator->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET || if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET ||
target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY || target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY ||
target->GetType() == cmStateEnums::TargetType::UTILITY || target->GetType() == cmStateEnums::TargetType::UTILITY ||
...@@ -1557,12 +1560,12 @@ bool cmGlobalGenerator::AddAutomaticSources() ...@@ -1557,12 +1560,12 @@ bool cmGlobalGenerator::AddAutomaticSources()
{ {
for (cmLocalGenerator* lg : this->LocalGenerators) { for (cmLocalGenerator* lg : this->LocalGenerators) {
lg->CreateEvaluationFileOutputs(); lg->CreateEvaluationFileOutputs();
for (cmGeneratorTarget* gt : lg->GetGeneratorTargets()) { for (const auto& gt : lg->GetGeneratorTargets()) {
if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) { if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue; continue;
} }
lg->AddUnityBuild(gt); lg->AddUnityBuild(gt.get());
lg->AddPchDependencies(gt); lg->AddPchDependencies(gt.get());
} }
} }
return true; return true;
...@@ -1650,8 +1653,7 @@ void cmGlobalGenerator::CreateGeneratorTargets( ...@@ -1650,8 +1653,7 @@ void cmGlobalGenerator::CreateGeneratorTargets(
if (targetTypes == AllTargets) { if (targetTypes == AllTargets) {
for (auto& target : mf->GetTargets()) { for (auto& target : mf->GetTargets()) {
cmTarget* t = &target.second; cmTarget* t = &target.second;
cmGeneratorTarget* gt = new cmGeneratorTarget(t, lg); lg->AddGeneratorTarget(cm::make_unique<cmGeneratorTarget>(t, lg));
lg->AddGeneratorTarget(gt);
} }
} }
...@@ -1667,9 +1669,9 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes) ...@@ -1667,9 +1669,9 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes)
cmMakefile* mf = this->Makefiles[i]; cmMakefile* mf = this->Makefiles[i];
for (cmTarget* ownedImpTgt : mf->GetOwnedImportedTargets()) { for (cmTarget* ownedImpTgt : mf->GetOwnedImportedTargets()) {
cmLocalGenerator* lg = this->LocalGenerators[i]; cmLocalGenerator* lg = this->LocalGenerators[i];
cmGeneratorTarget* gt = new cmGeneratorTarget(ownedImpTgt, lg); auto gt = cm::make_unique<cmGeneratorTarget>(ownedImpTgt, lg);
lg->AddOwnedImportedGeneratorTarget(gt); importedMap[ownedImpTgt] = gt.get();
importedMap[ownedImpTgt] = gt; lg->AddOwnedImportedGeneratorTarget(std::move(gt));
} }
} }
...@@ -2766,15 +2768,15 @@ void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets, ...@@ -2766,15 +2768,15 @@ void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
continue; continue;
} }
// loop over all the generator targets in the makefile // loop over all the generator targets in the makefile
for (cmGeneratorTarget* target : generator->GetGeneratorTargets()) { for (const auto& target : generator->GetGeneratorTargets()) {
if (this->IsRootOnlyTarget(target) && if (this->IsRootOnlyTarget(target.get()) &&
target->GetLocalGenerator() != root) { target->GetLocalGenerator() != root) {
continue; continue;
} }
// put the target in the set of original targets // put the target in the set of original targets
originalTargets.insert(target); originalTargets.insert(target.get());
// Get the set of targets that depend on target // Get the set of targets that depend on target