Skip to content

Commit dde4d1b

Browse files
committed
Add support for imported targets
1 parent 0b87ddb commit dde4d1b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

FindFortran.cmake

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ These variables may be set to choose which compiler executable is looked up.
3030
is not in the ``PATH``, this variable may be set to ensure it is
3131
discovered.
3232
33+
.. variable:: Fortran_IMPORTED_TARGET_NAMESPACE
34+
35+
This variable may be set to add imported targets for each implicit
36+
link libraries and define the :variable:`<Fortran_IMPORTED_TARGET_NAMESPACE>_Fortran_SUPPORT_LIBRARIES`.
37+
3338
3439
The module may be used multiple times to find different compilers.
3540
@@ -78,6 +83,20 @@ This module will set the following variables in your project:
7883
7984
This list of directories may be used to configure a launcher.
8085
86+
.. variable:: <Fortran_IMPORTED_TARGET_NAMESPACE>_Fortran_SUPPORT_LIBRARIES
87+
88+
This variable may be set to the list of :variable:`<Fortran_IMPORTED_TARGET_NAMESPACE>::Fortran_<Fortran_COMPILER_ID>_<IMPLICIT_LIBRARY_NAME>`.
89+
90+
IMPORTED Targets
91+
^^^^^^^^^^^^^^^^
92+
93+
.. variable:: <Fortran_IMPORTED_TARGET_NAMESPACE>::Fortran_<Fortran_COMPILER_ID>_<IMPLICIT_LIBRARY_NAME>
94+
95+
If :variable:`Fortran_IMPORTED_TARGET_NAMESPACE` is set, this module defines :prop_tgt:`IMPORTED` targets
96+
for each implicit link libraries. Each target is named following the pattern
97+
``<Fortran_IMPORTED_TARGET_NAMESPACE>::Fortran_<Fortran_COMPILER_ID>_<IMPLICIT_LIBRARY_NAME>``
98+
OpenCL has been found.
99+
81100
#]=======================================================================]
82101

83102
function(_fortran_assert)
@@ -396,6 +415,26 @@ if(Fortran_${_id}_RUNTIME_LIBRARIES)
396415
list(APPEND _additional_required_vars Fortran_${_id}_RUNTIME_DIRECTORIES)
397416
endif()
398417

418+
# imported targets
419+
if(Fortran_IMPORTED_TARGET_NAMESPACE)
420+
set(_imported_targets)
421+
if(Fortran_${_id}_IMPLICIT_LINK_LIBRARIES)
422+
set(_link_libs ${Fortran_${_id}_IMPLICIT_LINK_LIBRARIES})
423+
list(REMOVE_ITEM _link_libs c crypt dl gcc_s m nsl rt util pthread stdc++)
424+
foreach(_lib IN LISTS _link_libs)
425+
find_library(Fortran_${_id}_${_lib}_IMPLICIT_LINK_LIBRARY ${_lib} PATHS ${Fortran_${_id}_IMPLICIT_LINK_DIRECTORIES})
426+
427+
add_library(${Fortran_IMPORTED_TARGET_NAMESPACE}::Fortran_${_id}_${_lib} UNKNOWN IMPORTED)
428+
set_target_properties(${Fortran_IMPORTED_TARGET_NAMESPACE}::Fortran_${_id}_${_lib} PROPERTIES
429+
IMPORTED_LOCATION "${Fortran_${_id}_${_lib}_IMPLICIT_LINK_LIBRARY}"
430+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
431+
)
432+
list(APPEND _imported_targets ${Fortran_IMPORTED_TARGET_NAMESPACE}::Fortran_${_id}_${_lib})
433+
endforeach()
434+
endif()
435+
set(${Fortran_IMPORTED_TARGET_NAMESPACE}_Fortran_SUPPORT_LIBRARIES ${_imported_targets})
436+
endif()
437+
399438
# outputs
400439
include(FindPackageHandleStandardArgs)
401440
find_package_handle_standard_args(Fortran

0 commit comments

Comments
 (0)