File: FindStandardFortran.cmake

package info (click to toggle)
ga 5.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,472 kB
  • sloc: ansic: 192,963; fortran: 53,761; f90: 11,218; cpp: 5,784; makefile: 2,248; sh: 1,945; python: 1,734; perl: 534; csh: 134; asm: 106
file content (47 lines) | stat: -rw-r--r-- 2,130 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
# This module will locate the Fortran standard libraries so that a Fortran
# object or library can be linked against using a C/C++ compiler.
#
# After calling this module the following will be set:
#    STANDARDFORTRAN_LIBRARIES : A list of libraries to link against
#    StandardFortran_FOUND     : True if we found the standard Fortran libraries
#
# Implemenation note.  CMake provides a variable
# CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES which is a list of all libraries a
# compiler implicitly links against.  Unfortunately, at least for GNU, this
# list includes a lot of extra libraries that we don't necessarily want to
# link against (including both static and shared versions of libgcc).  This is
# why we've hardcoded the list per compiler.
#
enable_language(Fortran)
include(FindPackageHandleStandardArgs)

if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
    set(STANDARDFORTRAN_LIBS gfortran)
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
    set(STANDARDFORTRAN_LIBS ifcore)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
    set(STANDARDFORTRAN_LIBS FortranRuntime FortranDecimal)
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Flang")
    set(STANDARDFORTRAN_LIBS flang flangrti pgmath)
    #CMAKE_Fortran_COMPILER_ID does not give "ArmFlang"
    if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
        set(STANDARDFORTRAN_LIBS armflang amath_a64fx)
    endif()
else()
    message(FATAL_ERROR "${CMAKE_Fortran_COMPILER_ID} is not yet supported by this module.")
endif()

foreach(STANDARDFORTRAN_LIB ${STANDARDFORTRAN_LIBS})
    set(STANDARDFORTRAN_LIB_NAMES
            lib${STANDARDFORTRAN_LIB}${CMAKE_SHARED_LIBRARY_SUFFIX} lib${STANDARDFORTRAN_LIB}.a)
    find_library(${STANDARDFORTRAN_LIB}_LIBRARY
                 ${STANDARDFORTRAN_LIB_NAMES}
                 HINTS ${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES}
            )
    list(APPEND STANDARDFORTRAN_LIBRARIES ${${STANDARDFORTRAN_LIB}_LIBRARY})
endforeach()

find_package_handle_standard_args(StandardFortran DEFAULT_MSG
                                                      STANDARDFORTRAN_LIBRARIES)
set(STANDARDFORTRAN_FOUND ${StandardFortran_FOUND})