CheckFortranFunctionExists

This module provides a command to check whether a Fortran function exists.

Load this module in a CMake project with:

include(CheckFortranFunctionExists)

Commands

This module provides the following command:

check_fortran_function_exists

Checks once whether a Fortran function exists:

check_fortran_function_exists(<function> <variable>)
<function>

The name of the Fortran function.

<variable>

The name of the variable in which to store the check result. This variable will be created as an internal cache variable.

備註

This command does not detect functions provided by Fortran modules. In general, it is recommended to use CheckSourceCompiles instead to determine whether a Fortran function or subroutine is available.

Variables Affecting the Check

The following variables may be set before calling this command to modify the way the check is run:

CMAKE_REQUIRED_LINK_OPTIONS

在 3.14 版被加入.

A semicolon-separated list of options to add to the link command (see try_compile() for further details).

CMAKE_REQUIRED_LIBRARIES

A semicolon-separated list of libraries to add to the link command. These can be the names of system libraries, or they can be Imported Targets (see try_compile() for further details).

CMAKE_REQUIRED_LINK_DIRECTORIES

在 3.31 版被加入.

A semicolon-separated list of library search paths to pass to the linker (see try_compile() for further details).

範例

Example: Isolated Check With Linked Libraries

In the following example, this module is used in combination with the CMakePushCheckState module to temporarily modify the required linked libraries (via CMAKE_REQUIRED_LIBRARIES) and verify whether the Fortran function dgesv is available for linking. The result is stored in the internal cache variable PROJECT_HAVE_DGESV:

include(CheckFortranFunctionExists)
include(CMakePushCheckState)

find_package(LAPACK)

if(TARGET LAPACK::LAPACK)
  cmake_push_check_state(RESET)

  set(CMAKE_REQUIRED_LIBRARIES LAPACK::LAPACK)
  check_fortran_function_exists(dgesv PROJECT_HAVE_DGESV)

  cmake_pop_check_state()
endif()

另請參見