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:
8 Check once if given C source compiles and links into an executable and can
11 .. command:: check_c_source_runs
15 check_c_source_runs(<code> <resultVar>)
17 Check once that the source supplied in ``<code>`` can be built, linked as an
18 executable, and then run. The ``<code>`` must contain at least a ``main()``
21 The result is stored in the internal cache variable specified by
22 ``<resultVar>``. If the code builds and runs with exit code ``0``, success is
23 indicated by boolean ``true``. Failure to build or run is indicated by boolean
24 ``false``, such as an empty string or an error message.
26 See also :command:`check_source_runs` for a more general command syntax.
28 The compile and link commands can be influenced by setting any of the
29 following variables prior to calling ``check_c_source_runs()``:
31 .. include:: /module/CMAKE_REQUIRED_FLAGS.txt
33 .. include:: /module/CMAKE_REQUIRED_DEFINITIONS.txt
35 .. include:: /module/CMAKE_REQUIRED_INCLUDES.txt
37 .. include:: /module/CMAKE_REQUIRED_LINK_OPTIONS.txt
39 .. include:: /module/CMAKE_REQUIRED_LIBRARIES.txt
41 .. include:: /module/CMAKE_REQUIRED_LINK_DIRECTORIES.txt
43 .. include:: /module/CMAKE_REQUIRED_QUIET.txt
45 #]=======================================================================]
48 include(Internal/CheckSourceRuns)
50 macro(CHECK_C_SOURCE_RUNS SOURCE VAR)
51 set(_CheckSourceRuns_old_signature 1)
52 cmake_check_source_runs(C "${SOURCE}" ${VAR} ${ARGN})
53 unset(_CheckSourceRuns_old_signature)