1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-23 00:48:55 +08:00

cmComputeLinkDepends: Replace depender index sentinel value with cm::optional

This commit is contained in:
Brad King
2024-09-17 14:05:43 -04:00
parent 6c9d8dc243
commit dccdd030cd
2 changed files with 24 additions and 25 deletions

View File

@@ -941,8 +941,8 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
} }
} }
void cmComputeLinkDepends::AddVarLinkEntries(size_t depender_index, void cmComputeLinkDepends::AddVarLinkEntries(
const char* value) cm::optional<size_t> const& depender_index, const char* value)
{ {
// This is called to add the dependencies named by // This is called to add the dependencies named by
// <item>_LIB_DEPENDS. The variable contains a semicolon-separated // <item>_LIB_DEPENDS. The variable contains a semicolon-separated
@@ -1003,15 +1003,13 @@ void cmComputeLinkDepends::AddDirectLinkEntries()
// Add direct link dependencies in this configuration. // Add direct link dependencies in this configuration.
cmLinkImplementation const* impl = this->Target->GetLinkImplementation( cmLinkImplementation const* impl = this->Target->GetLinkImplementation(
this->Config, cmGeneratorTarget::UseTo::Link); this->Config, cmGeneratorTarget::UseTo::Link);
this->AddLinkEntries(cmComputeComponentGraph::INVALID_COMPONENT, this->AddLinkEntries(cm::nullopt, impl->Libraries);
impl->Libraries);
this->AddLinkObjects(impl->Objects); this->AddLinkObjects(impl->Objects);
for (auto const& language : impl->Languages) { for (auto const& language : impl->Languages) {
auto runtimeEntries = impl->LanguageRuntimeLibraries.find(language); auto runtimeEntries = impl->LanguageRuntimeLibraries.find(language);
if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) { if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) {
this->AddLinkEntries(cmComputeComponentGraph::INVALID_COMPONENT, this->AddLinkEntries(cm::nullopt, runtimeEntries->second);
runtimeEntries->second);
} }
} }
for (cmLinkItem const& wi : impl->WrongConfigLibraries) { for (cmLinkItem const& wi : impl->WrongConfigLibraries) {
@@ -1020,8 +1018,8 @@ void cmComputeLinkDepends::AddDirectLinkEntries()
} }
template <typename T> template <typename T>
void cmComputeLinkDepends::AddLinkEntries(size_t depender_index, void cmComputeLinkDepends::AddLinkEntries(
std::vector<T> const& libs) cm::optional<size_t> const& depender_index, std::vector<T> const& libs)
{ {
// Track inferred dependency sets implied by this list. // Track inferred dependency sets implied by this list.
std::map<size_t, DependSet> dependSets; std::map<size_t, DependSet> dependSets;
@@ -1040,9 +1038,8 @@ void cmComputeLinkDepends::AddLinkEntries(size_t depender_index,
// emit a warning if an undefined feature is used as part of // emit a warning if an undefined feature is used as part of
// an imported target // an imported target
if (item.Feature != LinkEntry::DEFAULT && if (item.Feature != LinkEntry::DEFAULT && depender_index) {
depender_index != cmComputeComponentGraph::INVALID_COMPONENT) { const auto& depender = this->EntryList[*depender_index];
const auto& depender = this->EntryList[depender_index];
if (depender.Target && depender.Target->IsImported() && if (depender.Target && depender.Target->IsImported() &&
!IsFeatureSupported(this->Makefile, this->LinkLanguage, !IsFeatureSupported(this->Makefile, this->LinkLanguage,
item.Feature)) { item.Feature)) {
@@ -1068,8 +1065,8 @@ void cmComputeLinkDepends::AddLinkEntries(size_t depender_index,
LinkEntry& entry = this->EntryList[group->first]; LinkEntry& entry = this->EntryList[group->first];
entry.Feature = ExtractGroupFeature(item.AsStr()); entry.Feature = ExtractGroupFeature(item.AsStr());
} }
if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT) { if (depender_index) {
this->EntryConstraintGraph[depender_index].emplace_back( this->EntryConstraintGraph[*depender_index].emplace_back(
group->first, false, false, cmListFileBacktrace()); group->first, false, false, cmListFileBacktrace());
} else { } else {
// This is a direct dependency of the target being linked. // This is a direct dependency of the target being linked.
@@ -1091,9 +1088,8 @@ void cmComputeLinkDepends::AddLinkEntries(size_t depender_index,
continue; continue;
} }
if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT && if (depender_index && group) {
group) { const auto& depender = this->EntryList[*depender_index];
const auto& depender = this->EntryList[depender_index];
const auto& groupFeature = this->EntryList[group->first].Feature; const auto& groupFeature = this->EntryList[group->first].Feature;
if (depender.Target && depender.Target->IsImported() && if (depender.Target && depender.Target->IsImported() &&
!IsGroupFeatureSupported(this->Makefile, this->LinkLanguage, !IsGroupFeatureSupported(this->Makefile, this->LinkLanguage,
@@ -1261,8 +1257,8 @@ void cmComputeLinkDepends::AddLinkEntries(size_t depender_index,
for (auto index : indexes) { for (auto index : indexes) {
// The dependee must come after the depender. // The dependee must come after the depender.
if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT) { if (depender_index) {
this->EntryConstraintGraph[depender_index].emplace_back( this->EntryConstraintGraph[*depender_index].emplace_back(
index, false, false, cmListFileBacktrace()); index, false, false, cmListFileBacktrace());
} else { } else {
// This is a direct dependency of the target being linked. // This is a direct dependency of the target being linked.
@@ -1305,14 +1301,14 @@ void cmComputeLinkDepends::AddLinkObjects(std::vector<cmLinkItem> const& objs)
} }
} }
cmLinkItem cmComputeLinkDepends::ResolveLinkItem(size_t depender_index, cmLinkItem cmComputeLinkDepends::ResolveLinkItem(
const std::string& name) cm::optional<size_t> const& depender_index, const std::string& name)
{ {
// Look for a target in the scope of the depender. // Look for a target in the scope of the depender.
cmGeneratorTarget const* from = this->Target; cmGeneratorTarget const* from = this->Target;
if (depender_index != cmComputeComponentGraph::INVALID_COMPONENT) { if (depender_index) {
if (cmGeneratorTarget const* depender = if (cmGeneratorTarget const* depender =
this->EntryList[depender_index].Target) { this->EntryList[*depender_index].Target) {
from = depender; from = depender;
} }
} }

View File

@@ -103,12 +103,15 @@ private:
std::pair<size_t, bool> AddLinkEntry(cmLinkItem const& item, std::pair<size_t, bool> AddLinkEntry(cmLinkItem const& item,
cm::optional<size_t> const& groupIndex); cm::optional<size_t> const& groupIndex);
void AddLinkObject(cmLinkItem const& item); void AddLinkObject(cmLinkItem const& item);
void AddVarLinkEntries(size_t depender_index, const char* value); void AddVarLinkEntries(cm::optional<size_t> const& depender_index,
const char* value);
void AddDirectLinkEntries(); void AddDirectLinkEntries();
template <typename T> template <typename T>
void AddLinkEntries(size_t depender_index, std::vector<T> const& libs); void AddLinkEntries(cm::optional<size_t> const& depender_index,
std::vector<T> const& libs);
void AddLinkObjects(std::vector<cmLinkItem> const& objs); void AddLinkObjects(std::vector<cmLinkItem> const& objs);
cmLinkItem ResolveLinkItem(size_t depender_index, const std::string& name); cmLinkItem ResolveLinkItem(cm::optional<size_t> const& depender_index,
const std::string& name);
// One entry for each unique item. // One entry for each unique item.
std::vector<LinkEntry> EntryList; std::vector<LinkEntry> EntryList;