diff options
author | Brad King <brad.king@kitware.com> | 2023-10-31 13:13:25 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-10-31 13:13:25 (GMT) |
commit | aa7f1416f901c43023a0c7d95db54e9498df7627 (patch) | |
tree | 2028d36a3b2ef55c389cae0b97da7504e786ed77 | |
parent | e298ffb3ff77164c8a513c628b143dae90b29c5c (diff) | |
parent | 22da18b9953f1ec9dff039572b5e8903009e4afb (diff) | |
download | CMake-aa7f1416f901c43023a0c7d95db54e9498df7627.zip CMake-aa7f1416f901c43023a0c7d95db54e9498df7627.tar.gz CMake-aa7f1416f901c43023a0c7d95db54e9498df7627.tar.bz2 |
Merge branch 'modules-depends-via-target-objects' into release-3.27
Merge-request: !8923
-rw-r--r-- | Source/cmComputeLinkDepends.cxx | 20 | ||||
-rw-r--r-- | Source/cmComputeLinkDepends.h | 1 | ||||
-rw-r--r-- | Source/cmComputeLinkInformation.cxx | 2 | ||||
-rw-r--r-- | Tests/FortranModules/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/FortranModules/Issue25365-target-objects-iface/CMakeLists.txt | 11 | ||||
-rw-r--r-- | Tests/FortranModules/Issue25365-target-objects-iface/iface.f90 | 11 | ||||
-rw-r--r-- | Tests/FortranModules/Issue25365-target-objects-iface/lib.f90 | 13 | ||||
-rw-r--r-- | Tests/FortranModules/Issue25365-target-objects/CMakeLists.txt | 5 | ||||
-rw-r--r-- | Tests/FortranModules/Issue25365-target-objects/iface.f90 | 11 | ||||
-rw-r--r-- | Tests/FortranModules/Issue25365-target-objects/lib.f90 | 13 | ||||
-rw-r--r-- | Tests/ObjectLibrary/CMakeLists.txt | 2 |
11 files changed, 90 insertions, 2 deletions
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index f51a1c8..4100135 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -26,6 +26,7 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmRange.h" +#include "cmSourceFile.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" #include "cmTarget.h" @@ -319,6 +320,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. @@ -512,6 +516,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); @@ -700,6 +705,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) diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h index 22c4e2a..63c289c 100644 --- a/Source/cmComputeLinkDepends.h +++ b/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); diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 7d3675e..f06e96f 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -1220,7 +1220,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); } diff --git a/Tests/FortranModules/CMakeLists.txt b/Tests/FortranModules/CMakeLists.txt index 00f3e57..16ea0d4 100644 --- a/Tests/FortranModules/CMakeLists.txt +++ b/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) diff --git a/Tests/FortranModules/Issue25365-target-objects-iface/CMakeLists.txt b/Tests/FortranModules/Issue25365-target-objects-iface/CMakeLists.txt new file mode 100644 index 0000000..819ac05 --- /dev/null +++ b/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) diff --git a/Tests/FortranModules/Issue25365-target-objects-iface/iface.f90 b/Tests/FortranModules/Issue25365-target-objects-iface/iface.f90 new file mode 100644 index 0000000..6b5ddd5 --- /dev/null +++ b/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 diff --git a/Tests/FortranModules/Issue25365-target-objects-iface/lib.f90 b/Tests/FortranModules/Issue25365-target-objects-iface/lib.f90 new file mode 100644 index 0000000..f971909 --- /dev/null +++ b/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 diff --git a/Tests/FortranModules/Issue25365-target-objects/CMakeLists.txt b/Tests/FortranModules/Issue25365-target-objects/CMakeLists.txt new file mode 100644 index 0000000..64e36cb --- /dev/null +++ b/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>") diff --git a/Tests/FortranModules/Issue25365-target-objects/iface.f90 b/Tests/FortranModules/Issue25365-target-objects/iface.f90 new file mode 100644 index 0000000..6b5ddd5 --- /dev/null +++ b/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 diff --git a/Tests/FortranModules/Issue25365-target-objects/lib.f90 b/Tests/FortranModules/Issue25365-target-objects/lib.f90 new file mode 100644 index 0000000..f971909 --- /dev/null +++ b/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 diff --git a/Tests/ObjectLibrary/CMakeLists.txt b/Tests/ObjectLibrary/CMakeLists.txt index 05a35bb..b57761b 100644 --- a/Tests/ObjectLibrary/CMakeLists.txt +++ b/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) |