1# Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2# file Copyright.txt or https://cmake.org/licensing for details. 3 4#[=======================================================================[.rst: 5CheckFortranSourceCompiles 6-------------------------- 7 8.. versionadded:: 3.1 9 10Check if given Fortran source compiles and links into an executable. 11 12.. command:: check_fortran_source_compiles 13 14 .. code-block:: cmake 15 16 check_fortran_source_compiles(<code> <resultVar> 17 [FAIL_REGEX <regex>...] 18 [SRC_EXT <extension>] 19 ) 20 21 Checks that the source supplied in ``<code>`` can be compiled as a Fortran 22 source file and linked as an executable. The ``<code>`` must be a Fortran program 23 containing at least an ``end`` statement--for example: 24 25 .. code-block:: cmake 26 27 check_fortran_source_compiles("character :: b; error stop b; end" F2018ESTOPOK SRC_EXT F90) 28 29 This command can help avoid costly build processes when a compiler lacks support 30 for a necessary feature, or a particular vendor library is not compatible with 31 the Fortran compiler version being used. This generate-time check may advise the 32 user of such before the main build process. See also the 33 :command:`check_fortran_source_runs` command to actually run the compiled code. 34 35 The result will be stored in the internal cache 36 variable ``<resultVar>``, with a boolean true value for success and boolean 37 false for failure. 38 39 If ``FAIL_REGEX`` is provided, then failure is determined by checking 40 if anything in the output matches any of the specified regular expressions. 41 42 By default, the test source file will be given a ``.F`` file extension. The 43 ``SRC_EXT`` option can be used to override this with ``.<extension>`` instead-- 44 ``.F90`` is a typical choice. 45 46 The underlying check is performed by the :command:`try_compile` command. The 47 compile and link commands can be influenced by setting any of the following 48 variables prior to calling ``check_fortran_source_compiles()``: 49 50 ``CMAKE_REQUIRED_FLAGS`` 51 Additional flags to pass to the compiler. Note that the contents of 52 :variable:`CMAKE_Fortran_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated 53 configuration-specific variable are automatically added to the compiler 54 command before the contents of ``CMAKE_REQUIRED_FLAGS``. 55 56 ``CMAKE_REQUIRED_DEFINITIONS`` 57 A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form 58 ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by 59 ``<resultVar>`` will also be added automatically. 60 61 ``CMAKE_REQUIRED_INCLUDES`` 62 A :ref:`;-list <CMake Language Lists>` of header search paths to pass to 63 the compiler. These will be the only header search paths used by 64 ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES` 65 directory property will be ignored. 66 67 ``CMAKE_REQUIRED_LINK_OPTIONS`` 68 .. versionadded:: 3.14 69 70 A :ref:`;-list <CMake Language Lists>` of options to add to the link 71 command (see :command:`try_compile` for further details). 72 73 ``CMAKE_REQUIRED_LIBRARIES`` 74 A :ref:`;-list <CMake Language Lists>` of libraries to add to the link 75 command. These can be the name of system libraries or they can be 76 :ref:`Imported Targets <Imported Targets>` (see :command:`try_compile` for 77 further details). 78 79 ``CMAKE_REQUIRED_QUIET`` 80 If this variable evaluates to a boolean true value, all status messages 81 associated with the check will be suppressed. 82 83 The check is only performed once, with the result cached in the variable 84 named by ``<resultVar>``. Every subsequent CMake run will re-use this cached 85 value rather than performing the check again, even if the ``<code>`` changes. 86 In order to force the check to be re-evaluated, the variable named by 87 ``<resultVar>`` must be manually removed from the cache. 88 89#]=======================================================================] 90 91include_guard(GLOBAL) 92include(Internal/CheckSourceCompiles) 93 94macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR) 95 # Pass the SRC_EXT we used by default historically. 96 # A user-provided SRC_EXT argument in ARGN will override ours. 97 cmake_check_source_compiles(Fortran "${SOURCE}" ${VAR} SRC_EXT "F" ${ARGN}) 98endmacro() 99