浏览代码

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.
Ben Boeckel 1 年之前
父节点
当前提交
1175f1c874

+ 1 - 0
Source/cmComputeLinkDepends.cxx

@@ -515,6 +515,7 @@ void cmComputeLinkDepends::AddLinkObject(cmLinkItem const& item)
   LinkEntry& entry = this->EntryList[index];
   LinkEntry& entry = this->EntryList[index];
   entry.Item = BT<std::string>(item.AsStr(), item.Backtrace);
   entry.Item = BT<std::string>(item.AsStr(), item.Backtrace);
   entry.Kind = LinkEntry::Object;
   entry.Kind = LinkEntry::Object;
+  entry.ObjectSource = item.ObjectSource;
 
 
   // Record explicitly linked object files separately.
   // Record explicitly linked object files separately.
   this->ObjectEntries.emplace_back(index);
   this->ObjectEntries.emplace_back(index);

+ 4 - 0
Source/cmComputeLinkDepends.h

@@ -22,6 +22,7 @@
 class cmGeneratorTarget;
 class cmGeneratorTarget;
 class cmGlobalGenerator;
 class cmGlobalGenerator;
 class cmMakefile;
 class cmMakefile;
+class cmSourceFile;
 class cmake;
 class cmake;
 
 
 /** \class cmComputeLinkDepends
 /** \class cmComputeLinkDepends
@@ -63,6 +64,9 @@ public:
 
 
     BT<std::string> Item;
     BT<std::string> Item;
     cmGeneratorTarget const* Target = nullptr;
     cmGeneratorTarget const* Target = nullptr;
+    // The source file representing the external object (used when linking
+    // `$<TARGET_OBJECTS>`)
+    cmSourceFile const* ObjectSource = nullptr;
     EntryKind Kind = Library;
     EntryKind Kind = Library;
     // The following member is for the management of items specified
     // The following member is for the management of items specified
     // through genex $<LINK_LIBRARY:...>
     // through genex $<LINK_LIBRARY:...>

+ 13 - 13
Source/cmComputeLinkInformation.cxx

@@ -1176,7 +1176,7 @@ void cmComputeLinkInformation::AddItem(LinkEntry const& entry)
         : cmStateEnums::RuntimeBinaryArtifact;
         : cmStateEnums::RuntimeBinaryArtifact;
       std::string exe = tgt->GetFullPath(config, artifact, true);
       std::string exe = tgt->GetFullPath(config, artifact, true);
       this->Items.emplace_back(
       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
         this->FindLibraryFeature(entry.Feature == DEFAULT
                                    ? "__CMAKE_LINK_EXECUTABLE"
                                    ? "__CMAKE_LINK_EXECUTABLE"
                                    : entry.Feature));
                                    : entry.Feature));
@@ -1197,7 +1197,7 @@ void cmComputeLinkInformation::AddItem(LinkEntry const& entry)
     } else if (this->GlobalGenerator->IsXcode() &&
     } else if (this->GlobalGenerator->IsXcode() &&
                !tgt->GetImportedXcFrameworkPath(config).empty()) {
                !tgt->GetImportedXcFrameworkPath(config).empty()) {
       this->Items.emplace_back(
       this->Items.emplace_back(
-        tgt->GetImportedXcFrameworkPath(config), ItemIsPath::Yes, tgt,
+        tgt->GetImportedXcFrameworkPath(config), ItemIsPath::Yes, tgt, nullptr,
         this->FindLibraryFeature(entry.Feature == DEFAULT
         this->FindLibraryFeature(entry.Feature == DEFAULT
                                    ? "__CMAKE_LINK_XCFRAMEWORK"
                                    ? "__CMAKE_LINK_XCFRAMEWORK"
                                    : entry.Feature));
                                    : entry.Feature));
@@ -1679,15 +1679,15 @@ void cmComputeLinkInformation::AddTargetItem(LinkEntry const& entry)
       if (isImportedFrameworkFolderOnApple) {
       if (isImportedFrameworkFolderOnApple) {
         if (entry.Feature == DEFAULT) {
         if (entry.Feature == DEFAULT) {
           this->AddLibraryFeature("FRAMEWORK");
           this->AddLibraryFeature("FRAMEWORK");
-          this->Items.emplace_back(item, ItemIsPath::Yes, target,
+          this->Items.emplace_back(item, ItemIsPath::Yes, target, nullptr,
                                    this->FindLibraryFeature("FRAMEWORK"));
                                    this->FindLibraryFeature("FRAMEWORK"));
         } else {
         } else {
-          this->Items.emplace_back(item, ItemIsPath::Yes, target,
+          this->Items.emplace_back(item, ItemIsPath::Yes, target, nullptr,
                                    this->FindLibraryFeature(entry.Feature));
                                    this->FindLibraryFeature(entry.Feature));
         }
         }
       } else {
       } else {
         this->Items.emplace_back(
         this->Items.emplace_back(
-          item, ItemIsPath::Yes, target,
+          item, ItemIsPath::Yes, target, nullptr,
           this->FindLibraryFeature(entry.Feature == DEFAULT
           this->FindLibraryFeature(entry.Feature == DEFAULT
                                      ? "__CMAKE_LINK_FRAMEWORK"
                                      ? "__CMAKE_LINK_FRAMEWORK"
                                      : entry.Feature));
                                      : entry.Feature));
@@ -1695,17 +1695,17 @@ void cmComputeLinkInformation::AddTargetItem(LinkEntry const& entry)
     } else {
     } else {
       if (cmHasSuffix(entry.Feature, "FRAMEWORK"_s)) {
       if (cmHasSuffix(entry.Feature, "FRAMEWORK"_s)) {
         this->Items.emplace_back(fwDescriptor->GetLinkName(), ItemIsPath::Yes,
         this->Items.emplace_back(fwDescriptor->GetLinkName(), ItemIsPath::Yes,
-                                 target,
+                                 target, nullptr,
                                  this->FindLibraryFeature(entry.Feature));
                                  this->FindLibraryFeature(entry.Feature));
       } else if (entry.Feature == DEFAULT &&
       } else if (entry.Feature == DEFAULT &&
                  isImportedFrameworkFolderOnApple) {
                  isImportedFrameworkFolderOnApple) {
         this->AddLibraryFeature("FRAMEWORK");
         this->AddLibraryFeature("FRAMEWORK");
         this->Items.emplace_back(fwDescriptor->GetLinkName(), ItemIsPath::Yes,
         this->Items.emplace_back(fwDescriptor->GetLinkName(), ItemIsPath::Yes,
-                                 target,
+                                 target, nullptr,
                                  this->FindLibraryFeature("FRAMEWORK"));
                                  this->FindLibraryFeature("FRAMEWORK"));
       } else {
       } else {
         this->Items.emplace_back(
         this->Items.emplace_back(
-          item, ItemIsPath::Yes, target,
+          item, ItemIsPath::Yes, target, nullptr,
           this->FindLibraryFeature(entry.Feature == DEFAULT
           this->FindLibraryFeature(entry.Feature == DEFAULT
                                      ? "__CMAKE_LINK_LIBRARY"
                                      ? "__CMAKE_LINK_LIBRARY"
                                      : entry.Feature));
                                      : entry.Feature));
@@ -1714,7 +1714,7 @@ void cmComputeLinkInformation::AddTargetItem(LinkEntry const& entry)
   } else {
   } else {
     // Now add the full path to the library.
     // Now add the full path to the library.
     this->Items.emplace_back(
     this->Items.emplace_back(
-      item, ItemIsPath::Yes, target,
+      item, ItemIsPath::Yes, target, nullptr,
       this->FindLibraryFeature(
       this->FindLibraryFeature(
         entry.Feature == DEFAULT ? "__CMAKE_LINK_LIBRARY" : entry.Feature));
         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.
   // Now add the full path to the library.
   this->Items.emplace_back(
   this->Items.emplace_back(
-    item, ItemIsPath::Yes, nullptr,
+    item, ItemIsPath::Yes, nullptr, entry.ObjectSource,
     this->FindLibraryFeature(
     this->FindLibraryFeature(
       entry.Feature == DEFAULT
       entry.Feature == DEFAULT
         ? (entry.Kind == cmComputeLinkDepends::LinkEntry::Object
         ? (entry.Kind == cmComputeLinkDepends::LinkEntry::Object
@@ -2000,13 +2000,13 @@ void cmComputeLinkInformation::AddFrameworkItem(LinkEntry const& entry)
   if (this->GlobalGenerator->IsXcode()) {
   if (this->GlobalGenerator->IsXcode()) {
     // Add framework path - it will be handled by Xcode after it's added to
     // Add framework path - it will be handled by Xcode after it's added to
     // "Link Binary With Libraries" build phase
     // "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
                              this->FindLibraryFeature(entry.Feature == DEFAULT
                                                         ? "FRAMEWORK"
                                                         ? "FRAMEWORK"
                                                         : entry.Feature));
                                                         : entry.Feature));
   } else {
   } else {
     this->Items.emplace_back(
     this->Items.emplace_back(
-      fwDescriptor->GetLinkName(), ItemIsPath::Yes, nullptr,
+      fwDescriptor->GetLinkName(), ItemIsPath::Yes, nullptr, nullptr,
       this->FindLibraryFeature(entry.Feature == DEFAULT ? "FRAMEWORK"
       this->FindLibraryFeature(entry.Feature == DEFAULT ? "FRAMEWORK"
                                                         : entry.Feature));
                                                         : entry.Feature));
   }
   }
@@ -2024,7 +2024,7 @@ void cmComputeLinkInformation::AddXcFrameworkItem(LinkEntry const& entry)
         plist->SelectSuitableLibrary(*this->Makefile, entry.Item.Backtrace)) {
         plist->SelectSuitableLibrary(*this->Makefile, entry.Item.Backtrace)) {
     if (this->GlobalGenerator->IsXcode()) {
     if (this->GlobalGenerator->IsXcode()) {
       this->Items.emplace_back(
       this->Items.emplace_back(
-        entry.Item.Value, ItemIsPath::Yes, nullptr,
+        entry.Item.Value, ItemIsPath::Yes, nullptr, nullptr,
         this->FindLibraryFeature(entry.Feature == DEFAULT
         this->FindLibraryFeature(entry.Feature == DEFAULT
                                    ? "__CMAKE_LINK_XCFRAMEWORK"
                                    ? "__CMAKE_LINK_XCFRAMEWORK"
                                    : entry.Feature));
                                    : entry.Feature));

+ 6 - 0
Source/cmComputeLinkInformation.h

@@ -22,6 +22,7 @@ class cmGeneratorTarget;
 class cmGlobalGenerator;
 class cmGlobalGenerator;
 class cmMakefile;
 class cmMakefile;
 class cmOrderDirectories;
 class cmOrderDirectories;
+class cmSourceFile;
 class cmake;
 class cmake;
 
 
 /** \class cmComputeLinkInformation
 /** \class cmComputeLinkInformation
@@ -51,16 +52,21 @@ public:
   {
   {
     Item(BT<std::string> v, ItemIsPath isPath,
     Item(BT<std::string> v, ItemIsPath isPath,
          cmGeneratorTarget const* target = nullptr,
          cmGeneratorTarget const* target = nullptr,
+         cmSourceFile const* objectSource = nullptr,
          FeatureDescriptor const* feature = nullptr)
          FeatureDescriptor const* feature = nullptr)
       : Value(std::move(v))
       : Value(std::move(v))
       , IsPath(isPath)
       , IsPath(isPath)
       , Target(target)
       , Target(target)
+      , ObjectSource(objectSource)
       , Feature(feature)
       , Feature(feature)
     {
     {
     }
     }
     BT<std::string> Value;
     BT<std::string> Value;
     ItemIsPath IsPath = ItemIsPath::No;
     ItemIsPath IsPath = ItemIsPath::No;
     cmGeneratorTarget const* Target = nullptr;
     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; }
     bool HasFeature() const { return this->Feature != nullptr; }
     const std::string& GetFeatureName() const
     const std::string& GetFeatureName() const

+ 2 - 0
Source/cmGeneratorTarget.cxx

@@ -6898,6 +6898,7 @@ void cmGeneratorTarget::ExpandLinkItems(
             cmSourceFile const* sf =
             cmSourceFile const* sf =
               mf->GetSource(maybeObj, cmSourceFileLocationKind::Known);
               mf->GetSource(maybeObj, cmSourceFileLocationKind::Known);
             if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
             if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
+              item.ObjectSource = sf;
               iface.Objects.emplace_back(std::move(item));
               iface.Objects.emplace_back(std::move(item));
               continue;
               continue;
             }
             }
@@ -8489,6 +8490,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
           cmSourceFile const* sf =
           cmSourceFile const* sf =
             mf->GetSource(maybeObj, cmSourceFileLocationKind::Known);
             mf->GetSource(maybeObj, cmSourceFileLocationKind::Known);
           if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
           if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
+            item.ObjectSource = sf;
             impl.Objects.emplace_back(std::move(item));
             impl.Objects.emplace_back(std::move(item));
             continue;
             continue;
           }
           }

+ 4 - 0
Source/cmLinkItem.h

@@ -17,6 +17,7 @@
 #include "cmTargetLinkLibraryType.h"
 #include "cmTargetLinkLibraryType.h"
 
 
 class cmGeneratorTarget;
 class cmGeneratorTarget;
+class cmSourceFile;
 
 
 // Basic information about each link item.
 // Basic information about each link item.
 class cmLinkItem
 class cmLinkItem
@@ -29,6 +30,9 @@ public:
   cmLinkItem(cmGeneratorTarget const* t, bool c, cmListFileBacktrace bt);
   cmLinkItem(cmGeneratorTarget const* t, bool c, cmListFileBacktrace bt);
   std::string const& AsStr() const;
   std::string const& AsStr() const;
   cmGeneratorTarget const* Target = nullptr;
   cmGeneratorTarget const* Target = nullptr;
+  // The source file representing the external object (used when linking
+  // `$<TARGET_OBJECTS>`)
+  cmSourceFile const* ObjectSource = nullptr;
   bool Cross = false;
   bool Cross = false;
   cmListFileBacktrace Backtrace;
   cmListFileBacktrace Backtrace;
   friend bool operator<(cmLinkItem const& l, cmLinkItem const& r);
   friend bool operator<(cmLinkItem const& l, cmLinkItem const& r);