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:
11 Check if given source compiles and links into an executable and can
14 .. command:: check_source_runs
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:
40 #include <stdnoreturn.h>
41 noreturn void f(){ exit(0); }
42 int main(void) { f(); return 1; }"
45 check_source_runs(Fortran
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 #]=======================================================================]
72 include(Internal/CheckSourceRuns)
74 function(CHECK_SOURCE_RUNS _lang _source _var)
75 cmake_check_source_runs(${_lang} "${_source}" ${_var} ${ARGN})