CheckOBJCSourceRuns.cmake 3.1 KB

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