mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-16 03:32:18 -06:00
cmGeneratorTarget: modernize memory management
This commit is contained in:
@@ -10,11 +10,11 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <memory>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include <cm/memory>
|
||||||
#include <cm/string_view>
|
#include <cm/string_view>
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
@@ -162,7 +162,8 @@ private:
|
|||||||
cmListFileBacktrace Backtrace;
|
cmListFileBacktrace Backtrace;
|
||||||
};
|
};
|
||||||
|
|
||||||
cmGeneratorTarget::TargetPropertyEntry* CreateTargetPropertyEntry(
|
std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>
|
||||||
|
CreateTargetPropertyEntry(
|
||||||
const std::string& propertyValue,
|
const std::string& propertyValue,
|
||||||
cmListFileBacktrace backtrace = cmListFileBacktrace(),
|
cmListFileBacktrace backtrace = cmListFileBacktrace(),
|
||||||
bool evaluateForBuildsystem = false)
|
bool evaluateForBuildsystem = false)
|
||||||
@@ -172,15 +173,18 @@ cmGeneratorTarget::TargetPropertyEntry* CreateTargetPropertyEntry(
|
|||||||
std::unique_ptr<cmCompiledGeneratorExpression> cge =
|
std::unique_ptr<cmCompiledGeneratorExpression> cge =
|
||||||
ge.Parse(propertyValue);
|
ge.Parse(propertyValue);
|
||||||
cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
|
cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
|
||||||
return new TargetPropertyEntryGenex(std::move(cge));
|
return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>(
|
||||||
|
cm::make_unique<TargetPropertyEntryGenex>(std::move(cge)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TargetPropertyEntryString(propertyValue, std::move(backtrace));
|
return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>(
|
||||||
|
cm::make_unique<TargetPropertyEntryString>(propertyValue,
|
||||||
|
std::move(backtrace)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatePropertyGeneratorExpressions(
|
void CreatePropertyGeneratorExpressions(
|
||||||
cmStringRange entries, cmBacktraceRange backtraces,
|
cmStringRange entries, cmBacktraceRange backtraces,
|
||||||
std::vector<cmGeneratorTarget::TargetPropertyEntry*>& items,
|
std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>>& items,
|
||||||
bool evaluateForBuildsystem = false)
|
bool evaluateForBuildsystem = false)
|
||||||
{
|
{
|
||||||
auto btIt = backtraces.begin();
|
auto btIt = backtraces.begin();
|
||||||
@@ -219,13 +223,13 @@ struct EvaluatedTargetPropertyEntry
|
|||||||
EvaluatedTargetPropertyEntry EvaluateTargetPropertyEntry(
|
EvaluatedTargetPropertyEntry EvaluateTargetPropertyEntry(
|
||||||
cmGeneratorTarget const* thisTarget, std::string const& config,
|
cmGeneratorTarget const* thisTarget, std::string const& config,
|
||||||
std::string const& lang, cmGeneratorExpressionDAGChecker* dagChecker,
|
std::string const& lang, cmGeneratorExpressionDAGChecker* dagChecker,
|
||||||
cmGeneratorTarget::TargetPropertyEntry* entry)
|
cmGeneratorTarget::TargetPropertyEntry& entry)
|
||||||
{
|
{
|
||||||
EvaluatedTargetPropertyEntry ee(entry->LinkImplItem, entry->GetBacktrace());
|
EvaluatedTargetPropertyEntry ee(entry.LinkImplItem, entry.GetBacktrace());
|
||||||
cmExpandList(entry->Evaluate(thisTarget->GetLocalGenerator(), config,
|
cmExpandList(entry.Evaluate(thisTarget->GetLocalGenerator(), config,
|
||||||
thisTarget, dagChecker, lang),
|
thisTarget, dagChecker, lang),
|
||||||
ee.Values);
|
ee.Values);
|
||||||
if (entry->GetHadContextSensitiveCondition()) {
|
if (entry.GetHadContextSensitiveCondition()) {
|
||||||
ee.ContextDependent = true;
|
ee.ContextDependent = true;
|
||||||
}
|
}
|
||||||
return ee;
|
return ee;
|
||||||
@@ -234,13 +238,14 @@ EvaluatedTargetPropertyEntry EvaluateTargetPropertyEntry(
|
|||||||
std::vector<EvaluatedTargetPropertyEntry> EvaluateTargetPropertyEntries(
|
std::vector<EvaluatedTargetPropertyEntry> EvaluateTargetPropertyEntries(
|
||||||
cmGeneratorTarget const* thisTarget, std::string const& config,
|
cmGeneratorTarget const* thisTarget, std::string const& config,
|
||||||
std::string const& lang, cmGeneratorExpressionDAGChecker* dagChecker,
|
std::string const& lang, cmGeneratorExpressionDAGChecker* dagChecker,
|
||||||
std::vector<cmGeneratorTarget::TargetPropertyEntry*> const& in)
|
std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>> const&
|
||||||
|
in)
|
||||||
{
|
{
|
||||||
std::vector<EvaluatedTargetPropertyEntry> out;
|
std::vector<EvaluatedTargetPropertyEntry> out;
|
||||||
out.reserve(in.size());
|
out.reserve(in.size());
|
||||||
for (cmGeneratorTarget::TargetPropertyEntry* entry : in) {
|
for (auto& entry : in) {
|
||||||
out.emplace_back(EvaluateTargetPropertyEntry(thisTarget, config, lang,
|
out.emplace_back(EvaluateTargetPropertyEntry(thisTarget, config, lang,
|
||||||
dagChecker, entry));
|
dagChecker, *entry));
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@@ -304,23 +309,12 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
|
|||||||
this->PolicyMap = t->GetPolicyMap();
|
this->PolicyMap = t->GetPolicyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
cmGeneratorTarget::~cmGeneratorTarget()
|
cmGeneratorTarget::~cmGeneratorTarget() = default;
|
||||||
{
|
|
||||||
cmDeleteAll(this->IncludeDirectoriesEntries);
|
|
||||||
cmDeleteAll(this->CompileOptionsEntries);
|
|
||||||
cmDeleteAll(this->CompileFeaturesEntries);
|
|
||||||
cmDeleteAll(this->CompileDefinitionsEntries);
|
|
||||||
cmDeleteAll(this->LinkOptionsEntries);
|
|
||||||
cmDeleteAll(this->LinkDirectoriesEntries);
|
|
||||||
cmDeleteAll(this->PrecompileHeadersEntries);
|
|
||||||
cmDeleteAll(this->SourceEntries);
|
|
||||||
cmDeleteAll(this->LinkInformation);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* cmGeneratorTarget::GetSourcesProperty() const
|
const char* cmGeneratorTarget::GetSourcesProperty() const
|
||||||
{
|
{
|
||||||
std::vector<std::string> values;
|
std::vector<std::string> values;
|
||||||
for (TargetPropertyEntry* se : this->SourceEntries) {
|
for (auto& se : this->SourceEntries) {
|
||||||
values.push_back(se->GetInput());
|
values.push_back(se->GetInput());
|
||||||
}
|
}
|
||||||
static std::string value;
|
static std::string value;
|
||||||
@@ -3288,10 +3282,10 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
|
|||||||
CM_FALLTHROUGH;
|
CM_FALLTHROUGH;
|
||||||
}
|
}
|
||||||
case cmPolicies::OLD: {
|
case cmPolicies::OLD: {
|
||||||
std::unique_ptr<TargetPropertyEntry> entry(
|
std::unique_ptr<TargetPropertyEntry> entry =
|
||||||
CreateTargetPropertyEntry(configProp));
|
CreateTargetPropertyEntry(configProp);
|
||||||
entries.emplace_back(EvaluateTargetPropertyEntry(
|
entries.emplace_back(EvaluateTargetPropertyEntry(
|
||||||
this, config, language, &dagChecker, entry.get()));
|
this, config, language, &dagChecker, *entry));
|
||||||
} break;
|
} break;
|
||||||
case cmPolicies::NEW:
|
case cmPolicies::NEW:
|
||||||
case cmPolicies::REQUIRED_ALWAYS:
|
case cmPolicies::REQUIRED_ALWAYS:
|
||||||
@@ -3778,10 +3772,10 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
|
|||||||
if (const char* linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) {
|
if (const char* linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) {
|
||||||
std::vector<std::string> options = cmExpandedList(linkOptions);
|
std::vector<std::string> options = cmExpandedList(linkOptions);
|
||||||
for (const auto& option : options) {
|
for (const auto& option : options) {
|
||||||
std::unique_ptr<TargetPropertyEntry> entry(
|
std::unique_ptr<TargetPropertyEntry> entry =
|
||||||
CreateTargetPropertyEntry(option));
|
CreateTargetPropertyEntry(option);
|
||||||
entries.emplace_back(EvaluateTargetPropertyEntry(
|
entries.emplace_back(EvaluateTargetPropertyEntry(this, config, language,
|
||||||
this, config, language, &dagChecker, entry.get()));
|
&dagChecker, *entry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
processOptions(this, entries, result, uniqueOptions, false,
|
processOptions(this, entries, result, uniqueOptions, false,
|
||||||
@@ -3932,10 +3926,10 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
|
|||||||
if (const char* linkDepends = this->GetProperty("LINK_DEPENDS")) {
|
if (const char* linkDepends = this->GetProperty("LINK_DEPENDS")) {
|
||||||
std::vector<std::string> depends = cmExpandedList(linkDepends);
|
std::vector<std::string> depends = cmExpandedList(linkDepends);
|
||||||
for (const auto& depend : depends) {
|
for (const auto& depend : depends) {
|
||||||
std::unique_ptr<TargetPropertyEntry> entry(
|
std::unique_ptr<TargetPropertyEntry> entry =
|
||||||
CreateTargetPropertyEntry(depend));
|
CreateTargetPropertyEntry(depend);
|
||||||
entries.emplace_back(EvaluateTargetPropertyEntry(
|
entries.emplace_back(EvaluateTargetPropertyEntry(this, config, language,
|
||||||
this, config, language, &dagChecker, entry.get()));
|
&dagChecker, *entry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS", language,
|
AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS", language,
|
||||||
@@ -4719,9 +4713,9 @@ std::string intersect(const std::set<std::string>& s1,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cmGeneratorTarget::CheckPropertyCompatibility(
|
void cmGeneratorTarget::CheckPropertyCompatibility(
|
||||||
cmComputeLinkInformation* info, const std::string& config) const
|
cmComputeLinkInformation& info, const std::string& config) const
|
||||||
{
|
{
|
||||||
const cmComputeLinkInformation::ItemVector& deps = info->GetItems();
|
const cmComputeLinkInformation::ItemVector& deps = info.GetItems();
|
||||||
|
|
||||||
std::set<std::string> emittedBools;
|
std::set<std::string> emittedBools;
|
||||||
static const std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
|
static const std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
|
||||||
@@ -5066,10 +5060,11 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string interfaceProperty = "INTERFACE_" + p;
|
std::string interfaceProperty = "INTERFACE_" + p;
|
||||||
std::unique_ptr<cmGeneratorExpressionInterpreter> genexInterpreter(
|
std::unique_ptr<cmGeneratorExpressionInterpreter> genexInterpreter;
|
||||||
p == "POSITION_INDEPENDENT_CODE" ? new cmGeneratorExpressionInterpreter(
|
if (p == "POSITION_INDEPENDENT_CODE") {
|
||||||
tgt->GetLocalGenerator(), config, tgt)
|
genexInterpreter = cm::make_unique<cmGeneratorExpressionInterpreter>(
|
||||||
: nullptr);
|
tgt->GetLocalGenerator(), config, tgt);
|
||||||
|
}
|
||||||
|
|
||||||
for (cmGeneratorTarget const* theTarget : deps) {
|
for (cmGeneratorTarget const* theTarget : deps) {
|
||||||
// An error should be reported if one dependency
|
// An error should be reported if one dependency
|
||||||
@@ -5216,22 +5211,19 @@ cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation(
|
|||||||
auto i = this->LinkInformation.find(key);
|
auto i = this->LinkInformation.find(key);
|
||||||
if (i == this->LinkInformation.end()) {
|
if (i == this->LinkInformation.end()) {
|
||||||
// Compute information for this configuration.
|
// Compute information for this configuration.
|
||||||
cmComputeLinkInformation* info =
|
auto info = cm::make_unique<cmComputeLinkInformation>(this, config);
|
||||||
new cmComputeLinkInformation(this, config);
|
if (info && !info->Compute()) {
|
||||||
if (!info || !info->Compute()) {
|
info.reset();
|
||||||
delete info;
|
|
||||||
info = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the information for this configuration.
|
// Store the information for this configuration.
|
||||||
cmTargetLinkInformationMap::value_type entry(key, info);
|
i = this->LinkInformation.emplace(key, std::move(info)).first;
|
||||||
i = this->LinkInformation.insert(entry).first;
|
|
||||||
|
|
||||||
if (info) {
|
if (i->second) {
|
||||||
this->CheckPropertyCompatibility(info, config);
|
this->CheckPropertyCompatibility(*i->second, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return i->second;
|
return i->second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
|
void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@@ -815,10 +816,10 @@ private:
|
|||||||
mutable std::map<std::string, CompatibleInterfaces> CompatibleInterfacesMap;
|
mutable std::map<std::string, CompatibleInterfaces> CompatibleInterfacesMap;
|
||||||
|
|
||||||
using cmTargetLinkInformationMap =
|
using cmTargetLinkInformationMap =
|
||||||
std::map<std::string, cmComputeLinkInformation*>;
|
std::map<std::string, std::unique_ptr<cmComputeLinkInformation>>;
|
||||||
mutable cmTargetLinkInformationMap LinkInformation;
|
mutable cmTargetLinkInformationMap LinkInformation;
|
||||||
|
|
||||||
void CheckPropertyCompatibility(cmComputeLinkInformation* info,
|
void CheckPropertyCompatibility(cmComputeLinkInformation& info,
|
||||||
const std::string& config) const;
|
const std::string& config) const;
|
||||||
|
|
||||||
struct LinkImplClosure : public std::vector<cmGeneratorTarget const*>
|
struct LinkImplClosure : public std::vector<cmGeneratorTarget const*>
|
||||||
@@ -881,14 +882,17 @@ private:
|
|||||||
bool MaybeHaveInterfaceProperty(std::string const& prop,
|
bool MaybeHaveInterfaceProperty(std::string const& prop,
|
||||||
cmGeneratorExpressionContext* context) const;
|
cmGeneratorExpressionContext* context) const;
|
||||||
|
|
||||||
std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
|
using TargetPropertyEntryVector =
|
||||||
std::vector<TargetPropertyEntry*> CompileOptionsEntries;
|
std::vector<std::unique_ptr<TargetPropertyEntry>>;
|
||||||
std::vector<TargetPropertyEntry*> CompileFeaturesEntries;
|
|
||||||
std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
|
TargetPropertyEntryVector IncludeDirectoriesEntries;
|
||||||
std::vector<TargetPropertyEntry*> LinkOptionsEntries;
|
TargetPropertyEntryVector CompileOptionsEntries;
|
||||||
std::vector<TargetPropertyEntry*> LinkDirectoriesEntries;
|
TargetPropertyEntryVector CompileFeaturesEntries;
|
||||||
std::vector<TargetPropertyEntry*> PrecompileHeadersEntries;
|
TargetPropertyEntryVector CompileDefinitionsEntries;
|
||||||
std::vector<TargetPropertyEntry*> SourceEntries;
|
TargetPropertyEntryVector LinkOptionsEntries;
|
||||||
|
TargetPropertyEntryVector LinkDirectoriesEntries;
|
||||||
|
TargetPropertyEntryVector PrecompileHeadersEntries;
|
||||||
|
TargetPropertyEntryVector SourceEntries;
|
||||||
mutable std::set<std::string> LinkImplicitNullProperties;
|
mutable std::set<std::string> LinkImplicitNullProperties;
|
||||||
mutable std::map<std::string, std::string> PchHeaders;
|
mutable std::map<std::string, std::string> PchHeaders;
|
||||||
mutable std::map<std::string, std::string> PchSources;
|
mutable std::map<std::string, std::string> PchSources;
|
||||||
|
|||||||
Reference in New Issue
Block a user