CheckFortranFunctionExists

該模組提供了一個檢查 Fortran 函數是否存在的命令。

在 CMake 專案中使用以下命令載入該模組:

include(CheckFortranFunctionExists)

命令

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.

影響檢查的變數

可以在呼叫此命令之前設定以下變數,以修改檢查的執行方式:

CMAKE_REQUIRED_LINK_OPTIONS

在 3.14 版被加入.

一個要新增到連結命令的選項的分號分隔列表(詳情請參見 try_compile())。

CMAKE_REQUIRED_LIBRARIES

一個要新增到連結命令的程式庫的分號分隔列表。這些可以是系統程式庫的名稱,也可以是 Imported Targets`(詳情請參見 :command:`try_compile)。

CMAKE_REQUIRED_LINK_DIRECTORIES

在 3.31 版被加入.

一個要傳遞給連結器的程式庫搜尋路徑的分號分隔列表(詳情請參見 try_compile())。

範例

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()

另請參見