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:
5CheckOBJCSourceRuns
6-------------------
7
8.. versionadded:: 3.16
9
10Check if given Objective-C source compiles and links into an executable and can
11subsequently be run.
12
13.. command:: check_objc_source_runs
14
15  .. code-block:: cmake
16
17    check_objc_source_runs(<code> <resultVar>)
18
19  Check that the source supplied in ``<code>`` can be compiled as a Objective-C source
20  file, linked as an executable and then run. The ``<code>`` must contain at
21  least a ``main()`` function. If the ``<code>`` could be built and run
22  successfully, the internal cache variable specified by ``<resultVar>`` will
23  be set to 1, otherwise it will be set to an value that evaluates to boolean
24  false (e.g. an empty string or an error message).
25
26  The underlying check is performed by the :command:`try_run` command. The
27  compile and link commands can be influenced by setting any of the following
28  variables prior to calling ``check_objc_source_runs()``:
29
30  ``CMAKE_REQUIRED_FLAGS``
31    Additional flags to pass to the compiler. Note that the contents of
32    :variable:`CMAKE_OBJC_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated
33    configuration-specific variable are automatically added to the compiler
34    command before the contents of ``CMAKE_REQUIRED_FLAGS``.
35
36  ``CMAKE_REQUIRED_DEFINITIONS``
37    A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form
38    ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by
39    ``<resultVar>`` will also be added automatically.
40
41  ``CMAKE_REQUIRED_INCLUDES``
42    A :ref:`;-list <CMake Language Lists>` of header search paths to pass to
43    the compiler. These will be the only header search paths used by
44    ``try_run()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES`
45    directory property will be ignored.
46
47  ``CMAKE_REQUIRED_LINK_OPTIONS``
48    A :ref:`;-list <CMake Language Lists>` of options to add to the link
49    command (see :command:`try_run` for further details).
50
51  ``CMAKE_REQUIRED_LIBRARIES``
52    A :ref:`;-list <CMake Language Lists>` of libraries to add to the link
53    command. These can be the name of system libraries or they can be
54    :ref:`Imported Targets <Imported Targets>` (see :command:`try_run` for
55    further details).
56
57  ``CMAKE_REQUIRED_QUIET``
58    If this variable evaluates to a boolean true value, all status messages
59    associated with the check will be suppressed.
60
61  The check is only performed once, with the result cached in the variable
62  named by ``<resultVar>``. Every subsequent CMake run will re-use this cached
63  value rather than performing the check again, even if the ``<code>`` changes.
64  In order to force the check to be re-evaluated, the variable named by
65  ``<resultVar>`` must be manually removed from the cache.
66
67#]=======================================================================]
68
69include_guard(GLOBAL)
70include(Internal/CheckSourceRuns)
71
72macro(CHECK_OBJC_SOURCE_RUNS SOURCE VAR)
73  set(_CheckSourceRuns_old_signature 1)
74  cmake_check_source_runs(OBJC "${SOURCE}" ${VAR} ${ARGN})
75  unset(_CheckSourceRuns_old_signature)
76endmacro()
77