1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
5 CheckFortranFunctionExists
6 --------------------------
8 Check if a Fortran function exists.
10 .. command:: CHECK_FORTRAN_FUNCTION_EXISTS
14 CHECK_FORTRAN_FUNCTION_EXISTS(<function> <result>)
19 the name of the Fortran function
21 variable to store the result; will be created as an internal cache variable.
25 This command does not detect functions in Fortran modules. In general it is
26 recommended to use :module:`CheckSourceCompiles` instead to determine if a
27 Fortran function or subroutine is available.
29 The following variables may be set before calling this macro to modify
30 the way the check is run:
32 ``CMAKE_REQUIRED_LINK_OPTIONS``
33 .. versionadded:: 3.14
34 A :ref:`;-list <CMake Language Lists>` of options to add to the link
35 command (see :command:`try_compile` for further details).
37 ``CMAKE_REQUIRED_LIBRARIES``
38 A :ref:`;-list <CMake Language Lists>` of libraries to add to the link
39 command. These can be the name of system libraries or they can be
40 :ref:`Imported Targets <Imported Targets>` (see :command:`try_compile` for
42 #]=======================================================================]
46 macro(CHECK_FORTRAN_FUNCTION_EXISTS FUNCTION VARIABLE)
47 if(NOT DEFINED ${VARIABLE})
48 message(CHECK_START "Looking for Fortran ${FUNCTION}")
49 if(CMAKE_REQUIRED_LINK_OPTIONS)
50 set(CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS
51 LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
53 set(CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS)
55 if(CMAKE_REQUIRED_LIBRARIES)
56 set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
57 LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
59 set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES)
62 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
67 end program TESTFortran
70 try_compile(${VARIABLE}
72 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
73 ${CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS}
74 ${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}
75 OUTPUT_VARIABLE OUTPUT
78 set(${VARIABLE} 1 CACHE INTERNAL "Have Fortran function ${FUNCTION}")
79 message(CHECK_PASS "found")
80 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
81 "Determining if the Fortran ${FUNCTION} exists passed with the following output:\n"
84 message(CHECK_FAIL "not found")
85 set(${VARIABLE} "" CACHE INTERNAL "Have Fortran function ${FUNCTION}")
86 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
87 "Determining if the Fortran ${FUNCTION} exists failed with the following output:\n"