Merge topic 'cxx-checks-tolerate-unused-arguments'
[kiteware-cmake.git] / Modules / CheckCSourceRuns.cmake
blobe06bcca6feb538e02cee4860483f5faaaa14fc16
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 CheckCSourceRuns
6 ----------------
8 Check if given C source compiles and links into an executable and can
9 subsequently be run.
11 .. command:: check_c_source_runs
13   .. code-block:: cmake
15     check_c_source_runs(<code> <resultVar>)
17   Check that the source supplied in ``<code>`` can be compiled as a C source
18   file, linked as an executable and then run. The ``<code>`` must contain at
19   least a ``main()`` function. If the ``<code>`` could be built and run
20   successfully, the internal cache variable specified by ``<resultVar>`` will
21   be set to 1, otherwise it will be set to an value that evaluates to boolean
22   false (e.g. an empty string or an error message).
24   The check is only performed once, with the result cached in the variable named
25   by ``<resultVar>``. Every subsequent CMake run will reuse this cached value
26   rather than performing the check again, even if the ``<code>`` changes. In
27   order to force the check to be re-evaluated, the variable named by
28   ``<resultVar>`` must be manually removed from the cache.
30   The compile and link commands can be influenced by setting any of the
31   following variables prior to calling ``check_c_source_runs()``:
33 .. include:: /module/CMAKE_REQUIRED_FLAGS.txt
35 .. include:: /module/CMAKE_REQUIRED_DEFINITIONS.txt
37 .. include:: /module/CMAKE_REQUIRED_INCLUDES.txt
39 .. include:: /module/CMAKE_REQUIRED_LINK_OPTIONS.txt
41 .. include:: /module/CMAKE_REQUIRED_LIBRARIES.txt
43 .. include:: /module/CMAKE_REQUIRED_QUIET.txt
45 #]=======================================================================]
47 include_guard(GLOBAL)
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)
54 endmacro()