Merge topic 'cpack-innosetup-linux'
[kiteware-cmake.git] / Modules / CheckFortranSourceRuns.cmake
blob9bf9fb2ee2eac535c6dea0c0eba0c630303c02c3
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 CheckFortranSourceRuns
6 ----------------------
8 .. versionadded:: 3.14
10 Check if given Fortran source compiles and links into an executable and can
11 subsequently be run.
13 .. command:: check_fortran_source_runs
15   .. code-block:: cmake
17     check_fortran_source_runs(<code> <resultVar>
18         [SRC_EXT <extension>])
20   Check that the source supplied in ``<code>`` can be compiled as a Fortran source
21   file, linked as an executable and then run. The ``<code>`` must be a Fortran
22   ``program``.
24   .. code-block:: cmake
26     check_fortran_source_runs("program test
27     real :: x[*]
28     call co_sum(x)
29     end program"
30     HAVE_COARRAY)
32   This command can help avoid costly build processes when a compiler lacks support
33   for a necessary feature, or a particular vendor library is not compatible with
34   the Fortran compiler version being used. Some of these failures only occur at runtime
35   instead of linktime, and a trivial runtime example can catch the issue before the
36   main build process.
38   If the ``<code>`` could be built and run
39   successfully, the internal cache variable specified by ``<resultVar>`` will
40   be set to 1, otherwise it will be set to an value that evaluates to boolean
41   false (e.g. an empty string or an error message).
43   By default, the test source file will be given a ``.F90`` file extension. The
44   ``SRC_EXT`` option can be used to override this with ``.<extension>`` instead.
46   The check is only performed once, with the result cached in the variable named
47   by ``<resultVar>``. Every subsequent CMake run will reuse this cached value
48   rather than performing the check again, even if the ``<code>`` changes. In
49   order to force the check to be re-evaluated, the variable named by
50   ``<resultVar>`` must be manually removed from the cache.
52   The compile and link commands can be influenced by setting any of the
53   following variables prior to calling ``check_fortran_source_runs()``:
55 .. include:: /module/CMAKE_REQUIRED_FLAGS.txt
57 .. include:: /module/CMAKE_REQUIRED_DEFINITIONS.txt
59 .. include:: /module/CMAKE_REQUIRED_INCLUDES.txt
61 .. include:: /module/CMAKE_REQUIRED_LINK_OPTIONS.txt
63 .. include:: /module/CMAKE_REQUIRED_LIBRARIES.txt
65 .. include:: /module/CMAKE_REQUIRED_QUIET.txt
67 #]=======================================================================]
69 include_guard(GLOBAL)
70 include(Internal/CheckSourceRuns)
72 macro(CHECK_Fortran_SOURCE_RUNS SOURCE VAR)
73   # Pass the SRC_EXT we used by default historically.
74   # A user-provided SRC_EXT argument in ARGN will override ours.
75   cmake_check_source_runs(Fortran "${SOURCE}" ${VAR} SRC_EXT "F90" ${ARGN})
76 endmacro()