mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 15:32:10 +08:00
Fortran: Restore support for TARGET_OBJECTS providing modules
Continue b665966933
(cmComputeLinkInformation: track OBJECT library
dependencies, 2023-07-22) which added explicitly listed `OBJECT`
libraries to the list of targets which the collator needs to consider.
Now also consider targets which provide objects directly to the target
via a `$<TARGET_OBJECT>` source lists.
Also add tests which use target objects directly and through an
`INTERFACE` library with target objects in its own sources.
Fixes: #25365
This commit is contained in:
@@ -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.
|
||||
@@ -701,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)
|
||||
|
@@ -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);
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
@@ -0,0 +1,11 @@
|
||||
module m1
|
||||
|
||||
implicit none
|
||||
|
||||
contains
|
||||
|
||||
pure real function pi()
|
||||
pi = 4*atan(1.)
|
||||
end function
|
||||
|
||||
end module m1
|
13
Tests/FortranModules/Issue25365-target-objects-iface/lib.f90
Normal file
13
Tests/FortranModules/Issue25365-target-objects-iface/lib.f90
Normal file
@@ -0,0 +1,13 @@
|
||||
module lib
|
||||
|
||||
use m1, only : pi
|
||||
|
||||
implicit none
|
||||
|
||||
contains
|
||||
|
||||
pure real function func()
|
||||
func = pi()
|
||||
end function
|
||||
|
||||
end module
|
@@ -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
Tests/FortranModules/Issue25365-target-objects/iface.f90
Normal file
11
Tests/FortranModules/Issue25365-target-objects/iface.f90
Normal file
@@ -0,0 +1,11 @@
|
||||
module m1
|
||||
|
||||
implicit none
|
||||
|
||||
contains
|
||||
|
||||
pure real function pi()
|
||||
pi = 4*atan(1.)
|
||||
end function
|
||||
|
||||
end module m1
|
13
Tests/FortranModules/Issue25365-target-objects/lib.f90
Normal file
13
Tests/FortranModules/Issue25365-target-objects/lib.f90
Normal file
@@ -0,0 +1,13 @@
|
||||
module lib
|
||||
|
||||
use m1, only : pi
|
||||
|
||||
implicit none
|
||||
|
||||
contains
|
||||
|
||||
pure real function func()
|
||||
func = pi()
|
||||
end function
|
||||
|
||||
end module
|
Reference in New Issue
Block a user