1# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2# file Copyright.txt or https://cmake.org/licensing for details.
3
4#[=======================================================================[.rst:
5CheckCXXSourceCompiles
6----------------------
7
8Check if given C++ source compiles and links into an executable.
9
10.. command:: check_cxx_source_compiles
11
12  .. code-block:: cmake
13
14    check_cxx_source_compiles(<code> <resultVar>
15                              [FAIL_REGEX <regex1> [<regex2>...]])
16
17  Check that the source supplied in ``<code>`` can be compiled as a C++ source
18  file and linked as an executable (so it must contain at least a ``main()``
19  function). The result will be stored in the internal cache variable specified
20  by ``<resultVar>``, with a boolean true value for success and boolean false
21  for failure. If ``FAIL_REGEX`` is provided, then failure is determined by
22  checking if anything in the output matches any of the specified regular
23  expressions.
24
25  The underlying check is performed by the :command:`try_compile` command. The
26  compile and link commands can be influenced by setting any of the following
27  variables prior to calling ``check_cxx_source_compiles()``:
28
29  ``CMAKE_REQUIRED_FLAGS``
30    Additional flags to pass to the compiler. Note that the contents of
31    :variable:`CMAKE_CXX_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated
32    configuration-specific variable are automatically added to the compiler
33    command before the contents of ``CMAKE_REQUIRED_FLAGS``.
34
35  ``CMAKE_REQUIRED_DEFINITIONS``
36    A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form
37    ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by
38    ``<resultVar>`` will also be added automatically.
39
40  ``CMAKE_REQUIRED_INCLUDES``
41    A :ref:`;-list <CMake Language Lists>` of header search paths to pass to
42    the compiler. These will be the only header search paths used by
43    ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES`
44    directory property will be ignored.
45
46  ``CMAKE_REQUIRED_LINK_OPTIONS``
47    .. versionadded:: 3.14
48
49    A :ref:`;-list <CMake Language Lists>` of options to add to the link
50    command (see :command:`try_compile` for further details).
51
52  ``CMAKE_REQUIRED_LIBRARIES``
53    A :ref:`;-list <CMake Language Lists>` of libraries to add to the link
54    command. These can be the name of system libraries or they can be
55    :ref:`Imported Targets <Imported Targets>` (see :command:`try_compile` for
56    further details).
57
58  ``CMAKE_REQUIRED_QUIET``
59    .. versionadded:: 3.1
60
61    If this variable evaluates to a boolean true value, all status messages
62    associated with the check will be suppressed.
63
64  The check is only performed once, with the result cached in the variable
65  named by ``<resultVar>``. Every subsequent CMake run will re-use this cached
66  value rather than performing the check again, even if the ``<code>`` changes.
67  In order to force the check to be re-evaluated, the variable named by
68  ``<resultVar>`` must be manually removed from the cache.
69
70#]=======================================================================]
71
72include_guard(GLOBAL)
73include(Internal/CheckSourceCompiles)
74
75macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
76  cmake_check_source_compiles(CXX "${SOURCE}" ${VAR} ${ARGN})
77endmacro()
78