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

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
......@@ -8,6 +8,7 @@
#include <algorithm>
#include <functional>
#include <iterator>
#include <memory>
#include <unordered_set>
#include <utility>
#include <vector>
......@@ -144,6 +145,13 @@ void cmDeleteAll(Range const& r)
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>
void cmAppend(std::vector<T>& v, Range const& r)
{
......
......@@ -4,6 +4,7 @@
#include <cassert>
#include <cstdio>
#include <memory>
#include <sstream>
#include <utility>
......@@ -160,12 +161,10 @@ void cmComputeTargetDepends::CollectTargets()
std::vector<cmLocalGenerator*> const& lgens =
this->GlobalGenerator->GetLocalGenerators();
for (cmLocalGenerator* lgen : lgens) {
const std::vector<cmGeneratorTarget*>& targets =
lgen->GetGeneratorTargets();
for (cmGeneratorTarget const* ti : targets) {
for (const auto& ti : lgen->GetGeneratorTargets()) {
int index = static_cast<int>(this->Targets.size());
this->TargetIndex[ti] = index;
this->Targets.push_back(ti);
this->TargetIndex[ti.get()] = index;
this->Targets.push_back(ti.get());
}
}
}
......
......@@ -3,6 +3,7 @@
#include "cmExtraCodeBlocksGenerator.h"
#include <map>
#include <memory>
#include <ostream>
#include <set>
#include <utility>
......@@ -283,8 +284,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
// add all executable and library targets and some of the GLOBAL
// and UTILITY targets
for (cmLocalGenerator* lg : lgs) {
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
for (cmGeneratorTarget* target : targets) {
const auto& targets = lg->GetGeneratorTargets();
for (const auto& target : targets) {
std::string targetName = target->GetName();
switch (target->GetType()) {
case cmStateEnums::GLOBAL_TARGET: {
......@@ -315,7 +316,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY:
case cmStateEnums::OBJECT_LIBRARY: {
cmGeneratorTarget* gt = target;
cmGeneratorTarget* gt = target.get();
this->AppendTarget(xml, targetName, gt, make, lg, compiler,
makeArgs);
std::string fastTarget = cmStrCat(targetName, "/fast");
......@@ -341,8 +342,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
for (cmLocalGenerator* lg : lgs) {
cmMakefile* makefile = lg->GetMakefile();
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
for (cmGeneratorTarget* target : targets) {
const auto& targets = lg->GetGeneratorTargets();
for (const auto& target : targets) {
switch (target->GetType()) {
case cmStateEnums::EXECUTABLE:
case cmStateEnums::STATIC_LIBRARY:
......@@ -352,13 +353,12 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
case cmStateEnums::UTILITY: // can have sources since 2.6.3
{
std::vector<cmSourceFile*> sources;
cmGeneratorTarget* gt = target;
gt->GetSourceFiles(sources,
makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
target->GetSourceFiles(
sources, makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
for (cmSourceFile* s : sources) {
// don't add source files from UTILITY target which have the
// GENERATED property set:
if (gt->GetType() == cmStateEnums::UTILITY &&
if (target->GetType() == cmStateEnums::UTILITY &&
s->GetIsGenerated()) {
continue;
}
......@@ -391,7 +391,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
}
CbpUnit& cbpUnit = allFiles[fullPath];
cbpUnit.Targets.push_back(target);
cbpUnit.Targets.push_back(target.get());
}
}
default: // intended fallthrough
......
......@@ -4,6 +4,7 @@
#include <cstring>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <utility>
......@@ -119,7 +120,7 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByTarget(
const std::vector<cmLocalGenerator*>& lgs =
this->GlobalGenerator->GetLocalGenerators();
for (cmLocalGenerator* lg : lgs) {
for (cmGeneratorTarget* lt : lg->GetGeneratorTargets()) {
for (const auto& lt : lg->GetGeneratorTargets()) {
cmStateEnums::TargetType type = lt->GetType();
std::string const& outputDir = lg->GetCurrentBinaryDirectory();
std::string targetName = lt->GetName();
......@@ -142,7 +143,7 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByTarget(
xml->Attribute("Active", "No");
xml->EndElement();
CreateNewProjectFile(lt, filename);
CreateNewProjectFile(lt.get(), filename);
break;
default:
break;
......@@ -269,9 +270,9 @@ void cmExtraCodeLiteGenerator::CreateNewProjectFile(
for (cmLocalGenerator* lg : lgs) {
cmMakefile* makefile = lg->GetMakefile();
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
for (cmGeneratorTarget* target : targets) {
projectType = CollectSourceFiles(makefile, target, cFiles, otherFiles);
for (const auto& target : lg->GetGeneratorTargets()) {
projectType =
CollectSourceFiles(makefile, target.get(), cFiles, otherFiles);
}
}
......
......@@ -6,6 +6,7 @@
#include <cassert>
#include <cstdio>
#include <map>
#include <memory>
#include <sstream>
#include <utility>
......@@ -496,9 +497,9 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml)
for (cmLocalGenerator* lg : this->GlobalGenerator->GetLocalGenerators()) {
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, '/');
switch (target->GetType()) {
case cmStateEnums::EXECUTABLE:
......@@ -519,10 +520,9 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml)
std::vector<cmSourceGroup> sourceGroups =
makefile->GetSourceGroups();
// get the files from the source lists then add them to the groups
cmGeneratorTarget* gt = const_cast<cmGeneratorTarget*>(target);
std::vector<cmSourceFile*> files;
gt->GetSourceFiles(files,
makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
target->GetSourceFiles(
files, makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
for (cmSourceFile* sf : files) {
// Add the file to the list of sources.
std::string const& source = sf->ResolveFullPath();
......@@ -860,15 +860,14 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
// include dirs
emmited.clear();
for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
const std::vector<cmGeneratorTarget*>& targets =
lgen->GetGeneratorTargets();
for (cmGeneratorTarget* target : targets) {
const auto& targets = lgen->GetGeneratorTargets();
for (const auto& target : targets) {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
std::vector<std::string> includeDirs;
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);
}
}
......@@ -916,15 +915,14 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
// add all executable and library targets and some of the GLOBAL
// and UTILITY targets
for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
const std::vector<cmGeneratorTarget*>& targets =
lgen->GetGeneratorTargets();
const auto& targets = lgen->GetGeneratorTargets();
std::string subdir = lgen->MaybeConvertToRelativePath(
this->HomeOutputDirectory, lgen->GetCurrentBinaryDirectory());
if (subdir == ".") {
subdir.clear();
}
for (cmGeneratorTarget* target : targets) {
for (const auto& target : targets) {
std::string targetName = target->GetName();
switch (target->GetType()) {
case cmStateEnums::GLOBAL_TARGET: {
......@@ -975,8 +973,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
std::string cleanArgs =
cmStrCat("-E chdir \"", lgen->GetCurrentBinaryDirectory(),
"\" \"", cmSystemTools::GetCMakeCommand(), "\" -P \"");
cmGeneratorTarget* gt = target;
cleanArgs += lgen->GetTargetDirectory(gt);
cleanArgs += lgen->GetTargetDirectory(target.get());
cleanArgs += "/cmake_clean.cmake\"";
cmExtraEclipseCDT4Generator::AppendTarget(
xml, "Clean", cmSystemTools::GetCMakeCommand(), cleanArgs,
......
......@@ -3,6 +3,7 @@
#include "cmExtraKateGenerator.h"
#include <cstring>
#include <memory>
#include <ostream>
#include <set>
#include <vector>
......@@ -111,12 +112,11 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg,
// and UTILITY targets
for (cmLocalGenerator* localGen :
this->GlobalGenerator->GetLocalGenerators()) {
const std::vector<cmGeneratorTarget*>& targets =
localGen->GetGeneratorTargets();
const auto& targets = localGen->GetGeneratorTargets();
std::string currentDir = localGen->GetCurrentBinaryDirectory();
bool topLevel = (currentDir == localGen->GetBinaryDirectory());
for (cmGeneratorTarget* target : targets) {
for (const auto& target : targets) {
std::string const& targetName = target->GetName();
switch (target->GetType()) {
case cmStateEnums::GLOBAL_TARGET: {
......
......@@ -3,6 +3,7 @@
#include "cmExtraSublimeTextGenerator.h"
#include <cstring>
#include <memory>
#include <set>
#include <sstream>
#include <utility>
......@@ -182,8 +183,8 @@ void cmExtraSublimeTextGenerator::AppendAllTargets(
// and UTILITY targets
for (cmLocalGenerator* lg : lgs) {
cmMakefile* makefile = lg->GetMakefile();
const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
for (cmGeneratorTarget* target : targets) {
const auto& targets = lg->GetGeneratorTargets();
for (const auto& target : targets) {
std::string targetName = target->GetName();
switch (target->GetType()) {
case cmStateEnums::GLOBAL_TARGET: {
......@@ -216,11 +217,11 @@ void cmExtraSublimeTextGenerator::AppendAllTargets(
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_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,
false);
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,
false);
} break;
......
......@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGlobalCommonGenerator.h"
#include <memory>
#include <utility>
#include "cmGeneratorTarget.h"
......@@ -32,7 +33,7 @@ cmGlobalCommonGenerator::ComputeDirectoryTargets() const
// The directory-level rule should depend on the target-level rules
// for all targets in the directory.
for (auto gt : lg->GetGeneratorTargets()) {
for (const auto& gt : lg->GetGeneratorTargets()) {
cmStateEnums::TargetType const type = gt->GetType();
if (type != cmStateEnums::EXECUTABLE &&
type != cmStateEnums::STATIC_LIBRARY &&
......@@ -43,7 +44,7 @@ cmGlobalCommonGenerator::ComputeDirectoryTargets() const
continue;
}
DirectoryTarget::Target t;
t.GT = gt;
t.GT = gt.get();
if (const char* exclude = gt->GetProperty("EXCLUDE_FROM_ALL")) {
if (cmIsOn(exclude)) {
// This target has been explicitly excluded.
......
......@@ -10,6 +10,9 @@
#include <initializer_list>
#include <iterator>
#include <sstream>
#include <utility>
#include <cm/memory>
#include "cmsys/Directory.hxx"
#include "cmsys/FStream.hxx"
......@@ -296,7 +299,7 @@ bool cmGlobalGenerator::CheckTargetsForMissingSources() const
{
bool failed = false;
for (cmLocalGenerator* localGen : this->LocalGenerators) {
for (cmGeneratorTarget* target : localGen->GetGeneratorTargets()) {
for (const auto& target : localGen->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET ||
target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY ||
target->GetType() == cmStateEnums::TargetType::UTILITY ||
......@@ -336,7 +339,7 @@ bool cmGlobalGenerator::CheckTargetsForType() const
}
bool failed = false;
for (cmLocalGenerator* generator : this->LocalGenerators) {
for (cmGeneratorTarget* target : generator->GetGeneratorTargets()) {
for (const auto& target : generator->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::EXECUTABLE &&
target->GetPropertyAsBool("WIN32_EXECUTABLE")) {
std::vector<std::string> const& configs =
......@@ -364,7 +367,7 @@ bool cmGlobalGenerator::CheckTargetsForPchCompilePdb() const
}
bool failed = false;
for (cmLocalGenerator* generator : this->LocalGenerators) {
for (cmGeneratorTarget* target : generator->GetGeneratorTargets()) {
for (const auto& target : generator->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET ||
target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY ||
target->GetType() == cmStateEnums::TargetType::UTILITY ||
......@@ -1557,12 +1560,12 @@ bool cmGlobalGenerator::AddAutomaticSources()
{
for (cmLocalGenerator* lg : this->LocalGenerators) {
lg->CreateEvaluationFileOutputs();
for (cmGeneratorTarget* gt : lg->GetGeneratorTargets()) {
for (const auto& gt : lg->GetGeneratorTargets()) {
if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
lg->AddUnityBuild(gt);
lg->AddPchDependencies(gt);
lg->AddUnityBuild(gt.get());
lg->AddPchDependencies(gt.get());
}
}
return true;
......@@ -1650,8 +1653,7 @@ void cmGlobalGenerator::CreateGeneratorTargets(
if (targetTypes == AllTargets) {
for (auto& target : mf->GetTargets()) {
cmTarget* t = &target.second;
cmGeneratorTarget* gt = new cmGeneratorTarget(t, lg);
lg->AddGeneratorTarget(gt);
lg->AddGeneratorTarget(cm::make_unique<cmGeneratorTarget>(t, lg));
}
}
......@@ -1667,9 +1669,9 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes)
cmMakefile* mf = this->Makefiles[i];
for (cmTarget* ownedImpTgt : mf->GetOwnedImportedTargets()) {
cmLocalGenerator* lg = this->LocalGenerators[i];
cmGeneratorTarget* gt = new cmGeneratorTarget(ownedImpTgt, lg);
lg->AddOwnedImportedGeneratorTarget(gt);
importedMap[ownedImpTgt] = gt;
auto gt = cm::make_unique<cmGeneratorTarget>(ownedImpTgt, lg);
importedMap[ownedImpTgt] = gt.get();
lg->AddOwnedImportedGeneratorTarget(std::move(gt));
}
}
......@@ -2766,15 +2768,15 @@ void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
continue;
}
// loop over all the generator targets in the makefile
for (cmGeneratorTarget* target : generator->GetGeneratorTargets()) {
if (this->IsRootOnlyTarget(target) &&
for (const auto& target : generator->GetGeneratorTargets()) {
if (this->IsRootOnlyTarget(target.get()) &&
target->GetLocalGenerator() != root) {
continue;
}
// 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
this->AddTargetDepends(target, projectTargets);
this->AddTargetDepends(target.get(), projectTargets);
}
}
}
......@@ -2951,11 +2953,11 @@ void cmGlobalGenerator::WriteSummary()
cmGeneratedFileStream fout(fname);
for (cmLocalGenerator* lg : this->LocalGenerators) {
for (cmGeneratorTarget* tgt : lg->GetGeneratorTargets()) {
for (const auto& tgt : lg->GetGeneratorTargets()) {
if (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
this->WriteSummary(tgt);
this->WriteSummary(tgt.get());
fout << tgt->GetSupportDirectory() << "\n";
}
}
......
......@@ -374,16 +374,15 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefileLanguageRules(
for (cmLocalGenerator* lGenerator : lGenerators) {
lg = static_cast<cmLocalUnixMakefileGenerator3*>(lGenerator);
// for all of out targets
for (cmGeneratorTarget* tgt : lg->GetGeneratorTargets()) {
for (const auto& tgt : lg->GetGeneratorTargets()) {
if ((tgt->GetType() == cmStateEnums::EXECUTABLE) ||
(tgt->GetType() == cmStateEnums::STATIC_LIBRARY) ||
(tgt->GetType() == cmStateEnums::SHARED_LIBRARY) ||
(tgt->GetType() == cmStateEnums::MODULE_LIBRARY) ||
(tgt->GetType() == cmStateEnums::OBJECT_LIBRARY) ||
(tgt->GetType() == cmStateEnums::UTILITY)) {
cmGeneratorTarget* gt = tgt;
std::string tname =
cmStrCat(lg->GetRelativeTargetDirectory(gt), "/DependInfo.cmake");
std::string tname = cmStrCat(lg->GetRelativeTargetDirectory(tgt.get()),
"/DependInfo.cmake");
cmSystemTools::ConvertToUnixSlashes(tname);
cmakefileStream << " \"" << tname << "\"\n";
}
......@@ -549,7 +548,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
cmLocalUnixMakefileGenerator3* lg =
static_cast<cmLocalUnixMakefileGenerator3*>(localGen);
// for each target Generate the rule files for each target.
for (cmGeneratorTarget* gtarget : lg->GetGeneratorTargets()) {
for (const auto& gtarget : lg->GetGeneratorTargets()) {
// Don't emit the same rule twice (e.g. two targets with the same
// simple name)
int type = gtarget->GetType();
......@@ -580,7 +579,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
depends, commands, true);
// Add a fast rule to build the target
std::string localName = lg->GetRelativeTargetDirectory(gtarget);
std::string localName = lg->GetRelativeTargetDirectory(gtarget.get());
std::string makefileName;
makefileName = cmStrCat(localName, "/build.make");
depends.clear();
......@@ -595,8 +594,8 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
// Add a local name for the rule to relink the target before
// installation.
if (gtarget->NeedRelinkBeforeInstall(lg->GetConfigName())) {
makeTargetName =
cmStrCat(lg->GetRelativeTargetDirectory(gtarget), "/preinstall");
makeTargetName = cmStrCat(
lg->GetRelativeTargetDirectory(gtarget.get()), "/preinstall");
localName = cmStrCat(name, "/preinstall");
depends.clear();
commands.clear();
......@@ -625,7 +624,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
}
// for each target Generate the rule files for each target.
for (cmGeneratorTarget* gtarget : lg->GetGeneratorTargets()) {
for (const auto& gtarget : lg->GetGeneratorTargets()) {
int type = gtarget->GetType();
std::string name = gtarget->GetName();
if (!name.empty() &&
......@@ -637,7 +636,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
(type == cmStateEnums::UTILITY))) {
std::string makefileName;
// Add a rule to build the target by name.
localName = lg->GetRelativeTargetDirectory(gtarget);
localName = lg->GetRelativeTargetDirectory(gtarget.get());
makefileName = cmStrCat(localName, "/build.make");
lg->WriteDivider(ruleFileStream);
......@@ -661,7 +660,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
{
std::ostringstream progressArg;
const char* sep = "";
for (unsigned long progFile : this->ProgressMap[gtarget].Marks) {
for (unsigned long progFile : this->ProgressMap[gtarget.get()].Marks) {
progressArg << sep << progFile;
sep = ",";
}
......@@ -680,7 +679,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
cmLocalUnixMakefileGenerator3::EchoNormal, &progress);
}
this->AppendGlobalTargetDepends(depends, gtarget);
this->AppendGlobalTargetDepends(depends, gtarget.get());
lg->WriteMakeRule(ruleFileStream, "All Build rule for target.",
localName, depends, commands, true);
......@@ -697,7 +696,8 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
cmOutputConverter::SHELL);
//
std::set<cmGeneratorTarget const*> emitted;
progCmd << " " << this->CountProgressMarksInTarget(gtarget, emitted);
progCmd << " "
<< this->CountProgressMarksInTarget(gtarget.get(), emitted);
commands.push_back(progCmd.str());
}
std::string tmp = "CMakeFiles/Makefile2";
......@@ -715,7 +715,8 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
if (regenerate) {
depends.emplace_back("cmake_check_build_system");
}
localName = cmStrCat(lg->GetRelativeTargetDirectory(gtarget), "/rule");
localName =
cmStrCat(lg->GetRelativeTargetDirectory(gtarget.get()), "/rule");
lg->WriteMakeRule(ruleFileStream,
"Build rule for subdir invocation for target.",
localName, depends, commands, true);
......@@ -729,8 +730,8 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
// Add rules to prepare the target for installation.
if (gtarget->NeedRelinkBeforeInstall(lg->GetConfigName())) {
localName =
cmStrCat(lg->GetRelativeTargetDirectory(gtarget), "/preinstall");
localName = cmStrCat(lg->GetRelativeTargetDirectory(gtarget.get()),
"/preinstall");
depends.clear();
commands.clear();
commands.push_back(lg->GetRecursiveMakeCall(makefileName, localName));
......@@ -740,7 +741,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
}
// add the clean rule
localName = lg->GetRelativeTargetDirectory(gtarget);
localName = lg->GetRelativeTargetDirectory(gtarget.get());
makeTargetName = cmStrCat(localName, "/clean");
depends.clear();
commands.clear();
......@@ -760,7 +761,7 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks()
this->DirectoryTargetsMap.clear();
// Loop over all targets in all local generators.
for (cmLocalGenerator* lg : this->LocalGenerators) {
for (cmGeneratorTarget* gt : lg->GetGeneratorTargets()) {
for (const auto& gt : lg->GetGeneratorTargets()) {
cmLocalGenerator* tlg = gt->GetLocalGenerator();
if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
......@@ -778,12 +779,13 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks()
// This local generator includes the target.
std::set<cmGeneratorTarget const*>& targetSet =
this->DirectoryTargetsMap[csnp];
targetSet.insert(gt);
targetSet.insert(gt.get());
// Add dependencies of the included target. An excluded
// target may still be included if it is a dependency of a
// non-excluded target.
for (cmTargetDepend const& tgtdep : this->GetTargetDirectDepends(gt)) {
for (cmTargetDepend const& tgtdep :
this->GetTargetDirectDepends(gt.get())) {
targetSet.insert(tgtdep);
}
}
......@@ -894,7 +896,7 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule(
// the targets
if (lg2 == lg || lg->IsRootMakefile()) {
// for each target Generate the rule files for each target.
for (cmGeneratorTarget* target : lg2->GetGeneratorTargets()) {
for (const auto& target : lg2->GetGeneratorTargets()) {
cmStateEnums::TargetType type = target->GetType();
if ((type == cmStateEnums::EXECUTABLE) ||
(type == cmStateEnums::STATIC_LIBRARY) ||
......
......@@ -2,6 +2,8 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGlobalVisualStudio8Generator.h"
#include <cm/memory>
#include "cmCustomCommand.h"
#include "cmCustomCommandLines.h"
#include "cmDocumentationEntry.h"
......@@ -109,8 +111,9 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmCommandOrigin::Generator, false,
no_working_directory, no_byproducts, no_depends, no_commands);
cmGeneratorTarget* gt = new cmGeneratorTarget(tgt, lg);
lg->AddGeneratorTarget(gt);
auto ptr = cm::make_unique<cmGeneratorTarget>(tgt, lg);
auto gt = ptr.get();
lg->AddGeneratorTarget(std::move(ptr));
// Organize in the "predefined targets" folder:
//
......@@ -203,10 +206,9 @@ void cmGlobalVisualStudio8Generator::AddExtraIDETargets()
cmGlobalVisualStudio7Generator::AddExtraIDETargets();
if (this->AddCheckTarget()) {
for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
const std::vector<cmGeneratorTarget*>& tgts =
this->LocalGenerators[i]->GetGeneratorTargets();
const auto& tgts = this->LocalGenerators[i]->GetGeneratorTargets();
// All targets depend on the build-system check target.
for (cmGeneratorTarget const* ti : tgts) {
for (const auto& ti : tgts) {
if (ti->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
ti->Target->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
}
......
......@@ -7,6 +7,7 @@
#include <iostream>
#include <cm/iterator>
#include <cm/memory>
#include <windows.h>
......@@ -200,8 +201,8 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets()
"ALL_BUILD", cmCommandOrigin::Generator, true, no_working_dir,
no_byproducts, no_depends, no_commands, false, "Build all projects");
cmGeneratorTarget* gt = new cmGeneratorTarget(allBuild, gen[0]);
gen[0]->AddGeneratorTarget(gt);
gen[0]->AddGeneratorTarget(
cm::make_unique<cmGeneratorTarget>(allBuild, gen[0]));
//
// Organize in the "predefined targets" folder:
......@@ -212,12 +213,12 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets()
// Now make all targets depend on the ALL_BUILD target
for (cmLocalGenerator const* i : gen) {
for (cmGeneratorTarget* tgt : i->GetGeneratorTargets()) {
for (const auto& tgt : i->GetGeneratorTargets()) {
if (tgt->GetType() == cmStateEnums::GLOBAL_TARGET ||
tgt->IsImported()) {
continue;
}
if (!this->IsExcluded(gen[0], tgt)) {
if (!this->IsExcluded(gen[0], tgt.get())) {
allBuild->AddUtility(tgt->GetName());
}
}
......@@ -389,8 +390,8 @@ bool cmGlobalVisualStudioGenerator::ComputeTargetDepends()
}
for (auto const& it : this->ProjectMap) {
for (const cmLocalGenerator* i : it.second) {
for (cmGeneratorTarget* ti : i->GetGeneratorTargets()) {
this->ComputeVSTargetDepends(ti);
for (const auto& ti : i->GetGeneratorTargets()) {
this->ComputeVSTargetDepends(ti.get());
}
}
}
......
......@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGlobalXCodeGenerator.h"
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
......@@ -412,10 +413,10 @@ void cmGlobalXCodeGenerator::ComputeTargetOrder()
{
size_t index = 0;
auto const& lgens = this->GetLocalGenerators();
for (cmLocalGenerator* lgen : lgens) {
auto const& targets = lgen->GetGeneratorTargets();
for (cmGeneratorTarget const* gt : targets) {
this->ComputeTargetOrder(gt, index);
for (auto const& lgen : lgens) {
const auto& targets = lgen->GetGeneratorTargets();
for (const auto& gt : targets) {
this->ComputeTargetOrder(gt.get(), index);
}
}
assert(index == this->TargetOrderIndex.size());
......@@ -511,8 +512,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
no_byproducts, no_depends,
cmMakeSingleCommandLine({ "echo", "Build all projects" }));
cmGeneratorTarget* allBuildGt = new cmGeneratorTarget(allbuild, root);
root->AddGeneratorTarget(allBuildGt);
root->AddGeneratorTarget(cm::make_unique<cmGeneratorTarget>(allbuild, root));
// Add XCODE depend helper
std::string dir = root->GetCurrentBinaryDirectory();
......@@ -536,14 +536,13 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
no_working_directory, no_byproducts, no_depends,
cmMakeSingleCommandLine({ "make", "-f", file }));
cmGeneratorTarget* checkGt = new cmGeneratorTarget(check, root);
root->AddGeneratorTarget(checkGt);
root->AddGeneratorTarget(cm::make_unique<cmGeneratorTarget>(check, root));
}
// now make the allbuild depend on all the non-utility targets
// in the project
for (auto& gen : gens) {
for (auto target : gen->GetGeneratorTargets()) {
for (const auto& target : gen->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::GLOBAL_TARGET) {
continue;
}
......@@ -567,7 +566,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
cmObjectLibraryCommands::Accept);
}
if (!this->IsExcluded(gens[0], target)) {
if (!this->IsExcluded(gens[0],</