diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-11-18 04:04:35 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-11-23 19:26:31 (GMT) |
commit | 1175f1c874a7cd34d643902bc428df92bce3471a (patch) | |
tree | 58011c63b67ff637e27fe212e1447a9116f0288c | |
parent | d2fa56772f290c61925a70161c77be5f4334fd77 (diff) | |
download | CMake-1175f1c874a7cd34d643902bc428df92bce3471a.zip CMake-1175f1c874a7cd34d643902bc428df92bce3471a.tar.gz CMake-1175f1c874a7cd34d643902bc428df92bce3471a.tar.bz2 |
LinkItem: track `cmSourceFile` instances for external objects
The target may be required in order to provide Fortran modules, so track
the source file so that the target may be looked up when needed.
-rw-r--r-- | Source/cmComputeLinkDepends.cxx | 1 | ||||
-rw-r--r-- | Source/cmComputeLinkDepends.h | 4 | ||||
-rw-r--r-- | Source/cmComputeLinkInformation.cxx | 26 | ||||
-rw-r--r-- | Source/cmComputeLinkInformation.h | 6 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 2 | ||||
-rw-r--r-- | Source/cmLinkItem.h | 4 |
6 files changed, 30 insertions, 13 deletions
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index 1b1f640..320c57c 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -515,6 +515,7 @@ void cmComputeLinkDepends::AddLinkObject(cmLinkItem const& item) LinkEntry& entry = this->EntryList[index]; entry.Item = BT<std::string>(item.AsStr(), item.Backtrace); entry.Kind = LinkEntry::Object; + entry.ObjectSource = item.ObjectSource; // Record explicitly linked object files separately. this->ObjectEntries.emplace_back(index); diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h index 22c4e2a..3233217 100644 --- a/Source/cmComputeLinkDepends.h +++ b/Source/cmComputeLinkDepends.h @@ -22,6 +22,7 @@ class cmGeneratorTarget; class cmGlobalGenerator; class cmMakefile; +class cmSourceFile; class cmake; /** \class cmComputeLinkDepends @@ -63,6 +64,9 @@ public: BT<std::string> Item; cmGeneratorTarget const* Target = nullptr; + // The source file representing the external object (used when linking + // `$<TARGET_OBJECTS>`) + cmSourceFile const* ObjectSource = nullptr; EntryKind Kind = Library; // The following member is for the management of items specified // through genex $<LINK_LIBRARY:...> diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 297ae1d..c58dc68 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -1176,7 +1176,7 @@ void cmComputeLinkInformation::AddItem(LinkEntry const& entry) : cmStateEnums::RuntimeBinaryArtifact; std::string exe = tgt->GetFullPath(config, artifact, true); this->Items.emplace_back( - BT<std::string>(exe, item.Backtrace), ItemIsPath::Yes, tgt, + BT<std::string>(exe, item.Backtrace), ItemIsPath::Yes, tgt, nullptr, this->FindLibraryFeature(entry.Feature == DEFAULT ? "__CMAKE_LINK_EXECUTABLE" : entry.Feature)); @@ -1197,7 +1197,7 @@ void cmComputeLinkInformation::AddItem(LinkEntry const& entry) } else if (this->GlobalGenerator->IsXcode() && !tgt->GetImportedXcFrameworkPath(config).empty()) { this->Items.emplace_back( - tgt->GetImportedXcFrameworkPath(config), ItemIsPath::Yes, tgt, + tgt->GetImportedXcFrameworkPath(config), ItemIsPath::Yes, tgt, nullptr, this->FindLibraryFeature(entry.Feature == DEFAULT ? "__CMAKE_LINK_XCFRAMEWORK" : entry.Feature)); @@ -1679,15 +1679,15 @@ void cmComputeLinkInformation::AddTargetItem(LinkEntry const& entry) if (isImportedFrameworkFolderOnApple) { if (entry.Feature == DEFAULT) { this->AddLibraryFeature("FRAMEWORK"); - this->Items.emplace_back(item, ItemIsPath::Yes, target, + this->Items.emplace_back(item, ItemIsPath::Yes, target, nullptr, this->FindLibraryFeature("FRAMEWORK")); } else { - this->Items.emplace_back(item, ItemIsPath::Yes, target, + this->Items.emplace_back(item, ItemIsPath::Yes, target, nullptr, this->FindLibraryFeature(entry.Feature)); } } else { this->Items.emplace_back( - item, ItemIsPath::Yes, target, + item, ItemIsPath::Yes, target, nullptr, this->FindLibraryFeature(entry.Feature == DEFAULT ? "__CMAKE_LINK_FRAMEWORK" : entry.Feature)); @@ -1695,17 +1695,17 @@ void cmComputeLinkInformation::AddTargetItem(LinkEntry const& entry) } else { if (cmHasSuffix(entry.Feature, "FRAMEWORK"_s)) { this->Items.emplace_back(fwDescriptor->GetLinkName(), ItemIsPath::Yes, - target, + target, nullptr, this->FindLibraryFeature(entry.Feature)); } else if (entry.Feature == DEFAULT && isImportedFrameworkFolderOnApple) { this->AddLibraryFeature("FRAMEWORK"); this->Items.emplace_back(fwDescriptor->GetLinkName(), ItemIsPath::Yes, - target, + target, nullptr, this->FindLibraryFeature("FRAMEWORK")); } else { this->Items.emplace_back( - item, ItemIsPath::Yes, target, + item, ItemIsPath::Yes, target, nullptr, this->FindLibraryFeature(entry.Feature == DEFAULT ? "__CMAKE_LINK_LIBRARY" : entry.Feature)); @@ -1714,7 +1714,7 @@ void cmComputeLinkInformation::AddTargetItem(LinkEntry const& entry) } else { // Now add the full path to the library. this->Items.emplace_back( - item, ItemIsPath::Yes, target, + item, ItemIsPath::Yes, target, nullptr, this->FindLibraryFeature( entry.Feature == DEFAULT ? "__CMAKE_LINK_LIBRARY" : entry.Feature)); } @@ -1774,7 +1774,7 @@ void cmComputeLinkInformation::AddFullItem(LinkEntry const& entry) // Now add the full path to the library. this->Items.emplace_back( - item, ItemIsPath::Yes, nullptr, + item, ItemIsPath::Yes, nullptr, entry.ObjectSource, this->FindLibraryFeature( entry.Feature == DEFAULT ? (entry.Kind == cmComputeLinkDepends::LinkEntry::Object @@ -2000,13 +2000,13 @@ void cmComputeLinkInformation::AddFrameworkItem(LinkEntry const& entry) if (this->GlobalGenerator->IsXcode()) { // Add framework path - it will be handled by Xcode after it's added to // "Link Binary With Libraries" build phase - this->Items.emplace_back(item, ItemIsPath::Yes, nullptr, + this->Items.emplace_back(item, ItemIsPath::Yes, nullptr, nullptr, this->FindLibraryFeature(entry.Feature == DEFAULT ? "FRAMEWORK" : entry.Feature)); } else { this->Items.emplace_back( - fwDescriptor->GetLinkName(), ItemIsPath::Yes, nullptr, + fwDescriptor->GetLinkName(), ItemIsPath::Yes, nullptr, nullptr, this->FindLibraryFeature(entry.Feature == DEFAULT ? "FRAMEWORK" : entry.Feature)); } @@ -2024,7 +2024,7 @@ void cmComputeLinkInformation::AddXcFrameworkItem(LinkEntry const& entry) plist->SelectSuitableLibrary(*this->Makefile, entry.Item.Backtrace)) { if (this->GlobalGenerator->IsXcode()) { this->Items.emplace_back( - entry.Item.Value, ItemIsPath::Yes, nullptr, + entry.Item.Value, ItemIsPath::Yes, nullptr, nullptr, this->FindLibraryFeature(entry.Feature == DEFAULT ? "__CMAKE_LINK_XCFRAMEWORK" : entry.Feature)); diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h index 1e8556d..3ee995f 100644 --- a/Source/cmComputeLinkInformation.h +++ b/Source/cmComputeLinkInformation.h @@ -22,6 +22,7 @@ class cmGeneratorTarget; class cmGlobalGenerator; class cmMakefile; class cmOrderDirectories; +class cmSourceFile; class cmake; /** \class cmComputeLinkInformation @@ -51,16 +52,21 @@ public: { Item(BT<std::string> v, ItemIsPath isPath, cmGeneratorTarget const* target = nullptr, + cmSourceFile const* objectSource = nullptr, FeatureDescriptor const* feature = nullptr) : Value(std::move(v)) , IsPath(isPath) , Target(target) + , ObjectSource(objectSource) , Feature(feature) { } BT<std::string> Value; ItemIsPath IsPath = ItemIsPath::No; cmGeneratorTarget const* Target = nullptr; + // The source file representing the external object (used when linking + // `$<TARGET_OBJECTS>`) + cmSourceFile const* ObjectSource = nullptr; bool HasFeature() const { return this->Feature != nullptr; } const std::string& GetFeatureName() const diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 146319a..8d21e63 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -6898,6 +6898,7 @@ void cmGeneratorTarget::ExpandLinkItems( cmSourceFile const* sf = mf->GetSource(maybeObj, cmSourceFileLocationKind::Known); if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) { + item.ObjectSource = sf; iface.Objects.emplace_back(std::move(item)); continue; } @@ -8489,6 +8490,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( cmSourceFile const* sf = mf->GetSource(maybeObj, cmSourceFileLocationKind::Known); if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) { + item.ObjectSource = sf; impl.Objects.emplace_back(std::move(item)); continue; } diff --git a/Source/cmLinkItem.h b/Source/cmLinkItem.h index 262728b..e4444d3 100644 --- a/Source/cmLinkItem.h +++ b/Source/cmLinkItem.h @@ -17,6 +17,7 @@ #include "cmTargetLinkLibraryType.h" class cmGeneratorTarget; +class cmSourceFile; // Basic information about each link item. class cmLinkItem @@ -29,6 +30,9 @@ public: cmLinkItem(cmGeneratorTarget const* t, bool c, cmListFileBacktrace bt); std::string const& AsStr() const; cmGeneratorTarget const* Target = nullptr; + // The source file representing the external object (used when linking + // `$<TARGET_OBJECTS>`) + cmSourceFile const* ObjectSource = nullptr; bool Cross = false; cmListFileBacktrace Backtrace; friend bool operator<(cmLinkItem const& l, cmLinkItem const& r); |