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:
5CheckOBJCSourceCompiles
6-----------------------
7
8.. versionadded:: 3.16
9
10Check if given Objective-C source compiles and links into an executable.
11
12.. command:: check_objc_source_compiles
13
14  .. code-block:: cmake
15
16    check_objc_source_compiles(<code> <resultVar>
17                               [FAIL_REGEX <regex1> [<regex2>...]])
18
19  Check that the source supplied in ``<code>`` can be compiled as a Objectie-C source
20  file and linked as an executable (so it must contain at least a ``main()``
21  function). The result will be stored in the internal cache variable specified
22  by ``<resultVar>``, with a boolean true value for success and boolean false
23  for failure. If ``FAIL_REGEX`` is provided, then failure is determined by
24  checking if anything in the output matches any of the specified regular
25  expressions.
26
27  The underlying check is performed by the :command:`try_compile` command. The
28  compile and link commands can be influenced by setting any of the following
29  variables prior to calling ``check_objc_source_compiles()``:
30
31  ``CMAKE_REQUIRED_FLAGS``
32    Additional flags to pass to the compiler. Note that the contents of
33    :variable:`CMAKE_OBJC_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated
34    configuration-specific variable are automatically added to the compiler
35    command before the contents of ``CMAKE_REQUIRED_FLAGS``.
36
37  ``CMAKE_REQUIRED_DEFINITIONS``
38    A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form
39    ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by
40    ``<resultVar>`` will also be added automatically.
41
42  ``CMAKE_REQUIRED_INCLUDES``
43    A :ref:`;-list <CMake Language Lists>` of header search paths to pass to
44    the compiler. These will be the only header search paths used by
45    ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES`
46    directory property will be ignored.
47
48  ``CMAKE_REQUIRED_LINK_OPTIONS``
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    If this variable evaluates to a boolean true value, all status messages
60    associated with the check will be suppressed.
61
62  The check is only performed once, with the result cached in the variable
63  named by ``<resultVar>``. Every subsequent CMake run will re-use this cached
64  value rather than performing the check again, even if the ``<code>`` changes.
65  In order to force the check to be re-evaluated, the variable named by
66  ``<resultVar>`` must be manually removed from the cache.
67
68#]=======================================================================]
69
70include_guard(GLOBAL)
71include(Internal/CheckSourceCompiles)
72
73macro(CHECK_OBJC_SOURCE_COMPILES SOURCE VAR)
74  cmake_check_source_compiles(OBJC "${SOURCE}" ${VAR} ${ARGN})
75endmacro()
76