瀏覽代碼

Merge topic 'modules-depends-via-target-objects' into release-3.28

22da18b995 Fortran: Restore support for TARGET_OBJECTS providing modules
64d9240564 cmComputeLinkInformation: skip over linking to items for object purposes
035302b7e3 cmComputeLinkDepends: also copy the target from object link items
861876b936 Tests/ObjectLibrary: fix comment

Acked-by: Kitware Robot <[email protected]>
Tested-by: buildbot <[email protected]>
Acked-by: scivision <[email protected]>
Merge-request: !8923
Brad King 2 年之前
父節點
當前提交
3a515b31b3

+ 20 - 0
Source/cmComputeLinkDepends.cxx

@@ -27,6 +27,7 @@
 #include "cmMakefile.h"
 #include "cmMessageType.h"
 #include "cmRange.h"
+#include "cmSourceFile.h"
 #include "cmStateTypes.h"
 #include "cmStringAlgorithms.h"
 #include "cmTarget.h"
@@ -320,6 +321,9 @@ cmComputeLinkDepends::Compute()
   // Follow the link dependencies of the target to be linked.
   this->AddDirectLinkEntries();
 
+  // Add dependencies on targets named by $<TARGET_OBJECTS:...> sources.
+  this->AddTargetObjectEntries();
+
   // Complete the breadth-first search of dependencies.
   while (!this->BFSQueue.empty()) {
     // Get the next entry.
@@ -513,6 +517,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.Target = item.Target;
 
   // Record explicitly linked object files separately.
   this->ObjectEntries.emplace_back(index);
@@ -701,6 +706,21 @@ void cmComputeLinkDepends::AddDirectLinkEntries()
   }
 }
 
+void cmComputeLinkDepends::AddTargetObjectEntries()
+{
+  std::vector<cmSourceFile const*> externalObjects;
+  this->Target->GetExternalObjects(externalObjects, this->Config);
+  for (auto const* externalObject : externalObjects) {
+    std::string const& objLib = externalObject->GetObjectLibrary();
+    if (objLib.empty()) {
+      continue;
+    }
+    cmLinkItem const& objItem =
+      this->Target->ResolveLinkItem(BT<std::string>(objLib));
+    this->AddLinkObject(objItem);
+  }
+}
+
 template <typename T>
 void cmComputeLinkDepends::AddLinkEntries(size_t depender_index,
                                           std::vector<T> const& libs)

+ 1 - 0
Source/cmComputeLinkDepends.h

@@ -100,6 +100,7 @@ private:
   void AddLinkObject(cmLinkItem const& item);
   void AddVarLinkEntries(size_t depender_index, const char* value);
   void AddDirectLinkEntries();
+  void AddTargetObjectEntries();
   template <typename T>
   void AddLinkEntries(size_t depender_index, std::vector<T> const& libs);
   void AddLinkObjects(std::vector<cmLinkItem> const& objs);

+ 1 - 1
Source/cmComputeLinkInformation.cxx

@@ -1252,7 +1252,7 @@ void cmComputeLinkInformation::AddItem(LinkEntry const& entry)
         this->AddFullItem(entry);
         this->AddLibraryRuntimeInfo(item.Value);
       }
-    } else {
+    } else if (entry.Kind != cmComputeLinkDepends::LinkEntry::Object) {
       // This is a library or option specified by the user.
       this->AddUserItem(entry, true);
     }

+ 3 - 0
Tests/FortranModules/CMakeLists.txt

@@ -134,3 +134,6 @@ if( # Intel Fortran VS Integration breaks on custom targets with Fortran sources
   add_subdirectory(Issue25252-iface-target)
 endif()
 add_subdirectory(Issue25252-iface-sources)
+
+add_subdirectory(Issue25365-target-objects)
+add_subdirectory(Issue25365-target-objects-iface)

+ 11 - 0
Tests/FortranModules/Issue25365-target-objects-iface/CMakeLists.txt

@@ -0,0 +1,11 @@
+enable_language(C)
+
+add_library(fortran_target_objects_sources_iface STATIC "${CMAKE_CURRENT_SOURCE_DIR}/iface.f90")
+
+add_library(fortran_target_objects_sources_iface_bridge INTERFACE)
+target_sources(fortran_target_objects_sources_iface_bridge
+  INTERFACE
+    "$<TARGET_OBJECTS:fortran_target_objects_sources_iface>")
+
+add_library(lib25365-target-objects-iface lib.f90)
+target_link_libraries(lib25365-target-objects-iface PRIVATE fortran_target_objects_sources_iface_bridge)

+ 11 - 0
Tests/FortranModules/Issue25365-target-objects-iface/iface.f90

@@ -0,0 +1,11 @@
+module m1
+
+implicit none
+
+contains
+
+pure real function pi()
+pi = 4*atan(1.)
+end function
+
+end module m1

+ 13 - 0
Tests/FortranModules/Issue25365-target-objects-iface/lib.f90

@@ -0,0 +1,13 @@
+module lib
+
+use m1, only : pi
+
+implicit none
+
+contains
+
+pure real function func()
+func = pi()
+end function
+
+end module

+ 5 - 0
Tests/FortranModules/Issue25365-target-objects/CMakeLists.txt

@@ -0,0 +1,5 @@
+enable_language(C)
+
+add_library(fortran_target_objects_sources STATIC "${CMAKE_CURRENT_SOURCE_DIR}/iface.f90")
+
+add_library(lib25365-target-objects lib.f90 "$<TARGET_OBJECTS:fortran_target_objects_sources>")

+ 11 - 0
Tests/FortranModules/Issue25365-target-objects/iface.f90

@@ -0,0 +1,11 @@
+module m1
+
+implicit none
+
+contains
+
+pure real function pi()
+pi = 4*atan(1.)
+end function
+
+end module m1

+ 13 - 0
Tests/FortranModules/Issue25365-target-objects/lib.f90

@@ -0,0 +1,13 @@
+module lib
+
+use m1, only : pi
+
+implicit none
+
+contains
+
+pure real function func()
+func = pi()
+end function
+
+end module

+ 1 - 1
Tests/ObjectLibrary/CMakeLists.txt

@@ -68,7 +68,7 @@ add_library(UseCstaticObjs STATIC $<TARGET_OBJECTS:Cstatic> $<TARGET_OBJECTS:A>
 # Test a shared library with sources from a different shared library
 add_library(UseCsharedObjs SHARED $<TARGET_OBJECTS:Cshared> $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:Bexport>)
 
-# Test a shared executable with sources from a different shared library
+# Test a shared executable with sources from a different executable
 add_executable(UseABstaticObjs $<TARGET_OBJECTS:UseABstatic>)
 target_link_libraries(UseABstaticObjs ABstatic)