CheckOBJCSourceRuns.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. CheckOBJCSourceRuns
  5. -------------------
  6. .. versionadded:: 3.16
  7. This module provides a command to check whether an Objective-C source can
  8. be built and run.
  9. Load this module in a CMake project with:
  10. .. code-block:: cmake
  11. include(CheckOBJCSourceRuns)
  12. Commands
  13. ^^^^^^^^
  14. This module provides the following command:
  15. .. command:: check_objc_source_runs
  16. Checks once whether the given Objective-C source code compiles and links
  17. into an executable that can subsequently be run:
  18. .. code-block:: cmake
  19. check_objc_source_runs(<code> <variable>)
  20. The Objective-C source supplied in ``<code>`` must contain at least a
  21. ``main()`` function. The result of the check is stored in the internal
  22. cache variable specified by ``<variable>``. If the code builds and runs
  23. with exit code ``0``, success is indicated by a boolean true value.
  24. Failure to build or run is indicated by a boolean false value, such as an
  25. empty string or an error message.
  26. .. rubric:: Variables Affecting the Check
  27. The following variables may be set before calling this command to modify
  28. the way the check is run:
  29. .. include:: /module/include/CMAKE_REQUIRED_FLAGS.rst
  30. .. include:: /module/include/CMAKE_REQUIRED_DEFINITIONS.rst
  31. .. include:: /module/include/CMAKE_REQUIRED_INCLUDES.rst
  32. .. include:: /module/include/CMAKE_REQUIRED_LINK_OPTIONS.rst
  33. .. include:: /module/include/CMAKE_REQUIRED_LIBRARIES.rst
  34. .. include:: /module/include/CMAKE_REQUIRED_LINK_DIRECTORIES.rst
  35. .. include:: /module/include/CMAKE_REQUIRED_QUIET.rst
  36. Examples
  37. ^^^^^^^^
  38. In the following example, this module is used to check whether the provided
  39. Objective-C source code builds and runs. Result of the check is stored in
  40. an internal cache variable ``HAVE_WORKING_CODE``.
  41. .. code-block:: cmake
  42. include(CheckOBJCSourceRuns)
  43. check_objc_source_runs("
  44. #import <Foundation/Foundation.h>
  45. int main()
  46. {
  47. NSObject *foo;
  48. return 0;
  49. }
  50. " HAVE_WORKING_CODE)
  51. See Also
  52. ^^^^^^^^
  53. * The :module:`CheckSourceRuns` module for a more general command syntax.
  54. * The :module:`CheckSourceCompiles` module to check whether a source code
  55. can be built.
  56. #]=======================================================================]
  57. include_guard(GLOBAL)
  58. include(Internal/CheckSourceRuns)
  59. macro(CHECK_OBJC_SOURCE_RUNS SOURCE VAR)
  60. set(_CheckSourceRuns_old_signature 1)
  61. cmake_check_source_runs(OBJC "${SOURCE}" ${VAR} ${ARGN})
  62. unset(_CheckSourceRuns_old_signature)
  63. endmacro()