Merge topic 'cuda_add_12.8_new_sm_support'
[kiteware-cmake.git] / Modules / CheckSourceRuns.cmake
blob52e7c7b7d3f486a4def688c5117fa8ca6b67cf84
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
5 #[=======================================================================[.rst:
6 CheckSourceRuns
7 -------------------
9 .. versionadded:: 3.19
11 Check if given source compiles and links into an executable and can
12 subsequently be run.
14 .. command:: check_source_runs
16   .. code-block:: cmake
18     check_source_runs(<lang> <code> <resultVar>
19                       [SRC_EXT <extension>])
21   Check once that the ``<lang>`` source supplied in ``<code>`` can be built,
22   linked as an executable, and then run. The ``<code>`` must contain at least
23   a ``main()`` function, or in Fortran a ``program``.
25   The result is stored in the internal cache variable specified by
26   ``<resultVar>``. If the code builds and runs with exit code ``0``, success is
27   indicated by boolean ``true``. Failure to build or run is indicated by boolean
28   ``false``, such as an empty string or an error message.
30   By default, the test source file will be given a file extension that matches
31   the requested language. The ``SRC_EXT`` option can be used to override this
32   with ``.<extension>`` instead.
34   The ``<code>`` must contain a valid main program. For example:
36   .. code-block:: cmake
38     check_source_runs(C
39     "#include <stdlib.h>
40     #include <stdnoreturn.h>
41     noreturn void f(){ exit(0); }
42     int main(void) { f(); return 1; }"
43     HAVE_NORETURN)
45     check_source_runs(Fortran
46     "program test
47     real :: x[*]
48     call co_sum(x)
49     end program"
50     HAVE_COARRAY)
52   The compile and link commands can be influenced by setting any of the
53   following variables prior to calling ``check_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_LINK_DIRECTORIES.txt
67 .. include:: /module/CMAKE_REQUIRED_QUIET.txt
69 #]=======================================================================]
71 include_guard(GLOBAL)
72 include(Internal/CheckSourceRuns)
74 function(CHECK_SOURCE_RUNS _lang _source _var)
75   cmake_check_source_runs(${_lang} "${_source}" ${_var} ${ARGN})
76 endfunction()