summaryrefslogtreecommitdiffstats
path: root/Source/cmGeneratorTarget.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-06-01 12:35:49 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-06-01 12:35:56 (GMT)
commit5eb2aa1f57e99f30be5ea145ce9af5fd9652392f (patch)
tree20ec33b57ee8da2737aa53376aa46032bf8860a8 /Source/cmGeneratorTarget.cxx
parent54cc20137cb5ea304a298dc63e68c86ebe6a2b89 (diff)
parent3941555d935afad8343c66f39579bfc611201a6f (diff)
downloadCMake-5eb2aa1f57e99f30be5ea145ce9af5fd9652392f.zip
CMake-5eb2aa1f57e99f30be5ea145ce9af5fd9652392f.tar.gz
CMake-5eb2aa1f57e99f30be5ea145ce9af5fd9652392f.tar.bz2
Merge topic 'link-objects-first'
3941555d93 target_link_libraries: Place $<TARGET_OBJECTS> before libraries f530b3a267 OpenWatcom: Add infrastructure to link to object files 8a4ca110e4 cmComputeLinkInformation: Improve type safety of item IsPath member 83ad066ed1 cmComputeTargetDepends: Factor out helper to add object library dependency 7f506b95a7 cmGeneratorTarget: Refactor link item lookup 96809a8541 cmGeneratorTarget: Give temporary link impl item an explicit name ddffbb8adb cmMakefile: Register explicit object sources more efficiently 18e42d3e63 cmGeneratorExpressionNode: Constify local variable Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6166
Diffstat (limited to 'Source/cmGeneratorTarget.cxx')
-rw-r--r--Source/cmGeneratorTarget.cxx79
1 files changed, 58 insertions, 21 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index a7d825d..5deb2df 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -6255,29 +6255,28 @@ bool cmGeneratorTarget::IsLinkLookupScope(std::string const& n,
return false;
}
-void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
- cmListFileBacktrace const& bt,
- std::vector<cmLinkItem>& items) const
+cm::optional<cmLinkItem> cmGeneratorTarget::LookupLinkItem(
+ std::string const& n, cmListFileBacktrace const& bt) const
{
+ cm::optional<cmLinkItem> maybeItem;
cmLocalGenerator const* lg = this->LocalGenerator;
- for (std::string const& n : names) {
- if (this->IsLinkLookupScope(n, lg)) {
- continue;
- }
+ if (this->IsLinkLookupScope(n, lg)) {
+ return maybeItem;
+ }
- std::string name = this->CheckCMP0004(n);
- if (name == this->GetName() || name.empty()) {
- continue;
- }
- items.push_back(this->ResolveLinkItem(name, bt, lg));
+ std::string name = this->CheckCMP0004(n);
+ if (name == this->GetName() || name.empty()) {
+ return maybeItem;
}
+ maybeItem = this->ResolveLinkItem(name, bt, lg);
+ return maybeItem;
}
void cmGeneratorTarget::ExpandLinkItems(
std::string const& prop, std::string const& value, std::string const& config,
cmGeneratorTarget const* headTarget, bool usage_requirements_only,
- std::vector<cmLinkItem>& items, bool& hadHeadSensitiveCondition,
- bool& hadContextSensitiveCondition,
+ std::vector<cmLinkItem>& items, std::vector<cmLinkItem>& objects,
+ bool& hadHeadSensitiveCondition, bool& hadContextSensitiveCondition,
bool& hadLinkLanguageSensitiveCondition) const
{
// Keep this logic in sync with ComputeLinkImplementationLibraries.
@@ -6295,7 +6294,25 @@ void cmGeneratorTarget::ExpandLinkItems(
cmExpandList(cge->Evaluate(this->LocalGenerator, config, headTarget,
&dagChecker, this, headTarget->LinkerLanguage),
libs);
- this->LookupLinkItems(libs, cge->GetBacktrace(), items);
+ cmMakefile const* mf = this->LocalGenerator->GetMakefile();
+ for (std::string const& lib : libs) {
+ if (cm::optional<cmLinkItem> maybeItem =
+ this->LookupLinkItem(lib, cge->GetBacktrace())) {
+ if (!maybeItem->Target) {
+ // Report explicitly linked object files separately.
+ std::string const& maybeObj = maybeItem->AsStr();
+ if (cmSystemTools::FileIsFullPath(maybeObj)) {
+ cmSourceFile const* sf =
+ mf->GetSource(maybeObj, cmSourceFileLocationKind::Known);
+ if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
+ objects.emplace_back(std::move(*maybeItem));
+ continue;
+ }
+ }
+ }
+ items.emplace_back(std::move(*maybeItem));
+ }
+ }
hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
hadContextSensitiveCondition = cge->GetHadContextSensitiveCondition();
hadLinkLanguageSensitiveCondition =
@@ -6800,7 +6817,7 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
// The interface libraries have been explicitly set.
this->ExpandLinkItems(linkIfaceProp, *explicitLibraries, config,
headTarget, usage_requirements_only, iface.Libraries,
- iface.HadHeadSensitiveCondition,
+ iface.Objects, iface.HadHeadSensitiveCondition,
iface.HadContextSensitiveCondition,
iface.HadLinkLanguageSensitiveCondition);
return;
@@ -6824,6 +6841,7 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
// Compare the link implementation fallback link interface to the
// preferred new link interface property and warn if different.
std::vector<cmLinkItem> ifaceLibs;
+ std::vector<cmLinkItem> ifaceObjects;
static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
if (cmProp newExplicitLibraries = this->GetProperty(newProp)) {
bool hadHeadSensitiveConditionDummy = false;
@@ -6831,7 +6849,7 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
bool hadLinkLanguageSensitiveConditionDummy = false;
this->ExpandLinkItems(newProp, *newExplicitLibraries, config,
headTarget, usage_requirements_only, ifaceLibs,
- hadHeadSensitiveConditionDummy,
+ ifaceObjects, hadHeadSensitiveConditionDummy,
hadContextSensitiveConditionDummy,
hadLinkLanguageSensitiveConditionDummy);
}
@@ -6899,11 +6917,16 @@ const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
cmExpandList(info->Languages, iface.Languages);
this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
headTarget, usage_requirements_only, iface.Libraries,
- iface.HadHeadSensitiveCondition,
+ iface.Objects, iface.HadHeadSensitiveCondition,
iface.HadContextSensitiveCondition,
iface.HadLinkLanguageSensitiveCondition);
std::vector<std::string> deps = cmExpandedList(info->SharedDeps);
- this->LookupLinkItems(deps, cmListFileBacktrace(), iface.SharedDeps);
+ for (std::string const& dep : deps) {
+ if (cm::optional<cmLinkItem> maybeItem =
+ this->LookupLinkItem(dep, cmListFileBacktrace())) {
+ iface.SharedDeps.emplace_back(std::move(*maybeItem));
+ }
+ }
}
return &iface;
@@ -7416,6 +7439,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
cmGeneratorTarget const* head) const
{
cmLocalGenerator const* lg = this->LocalGenerator;
+ cmMakefile const* mf = lg->GetMakefile();
cmStringRange entryRange = this->Target->GetLinkImplementationEntries();
cmBacktraceRange btRange = this->Target->GetLinkImplementationBacktraces();
cmBacktraceRange::const_iterator btIt = btRange.begin();
@@ -7490,8 +7514,21 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
}
// The entry is meant for this configuration.
- impl.Libraries.emplace_back(this->ResolveLinkItem(name, *btIt, lg),
- evaluated != *le);
+ cmLinkItem item = this->ResolveLinkItem(name, *btIt, lg);
+ if (!item.Target) {
+ // Report explicitly linked object files separately.
+ std::string const& maybeObj = item.AsStr();
+ if (cmSystemTools::FileIsFullPath(maybeObj)) {
+ cmSourceFile const* sf =
+ mf->GetSource(maybeObj, cmSourceFileLocationKind::Known);
+ if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
+ impl.Objects.emplace_back(std::move(item));
+ continue;
+ }
+ }
+ }
+
+ impl.Libraries.emplace_back(std::move(item), evaluated != *le);
}
std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();