CheckOBJCSourceCompiles.cmake 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. CheckOBJCSourceCompiles
  5. -----------------------
  6. .. versionadded:: 3.16
  7. This module provides a command to check whether an Objective-C source can
  8. be built.
  9. Load this module in a CMake project with:
  10. .. code-block:: cmake
  11. include(CheckOBJCSourceCompiles)
  12. Commands
  13. ^^^^^^^^
  14. This module provides the following command:
  15. .. command:: check_objc_source_compiles
  16. Checks once whether the given Objective-C source code can be built:
  17. .. code-block:: cmake
  18. check_objc_source_compiles(<code> <variable> [FAIL_REGEX <regexes>...])
  19. This command checks once that the source supplied in ``<code>`` can be
  20. compiled (and linked into an executable). The result of the check is
  21. stored in the internal cache variable specified by ``<variable>``.
  22. The arguments are:
  23. ``<code>``
  24. Source code to check. This must be an entire program, as written in a
  25. file containing the body block. All symbols used in the source code
  26. are expected to be declared as usual in their corresponding headers.
  27. ``<variable>``
  28. Variable name of an internal cache variable to store the result of the
  29. check, with boolean true for success and boolean false for failure.
  30. ``FAIL_REGEX <regexes>...``
  31. If this option is provided with one or more regular expressions, then
  32. failure is determined by checking if anything in the compiler output
  33. matches any of the specified regular expressions.
  34. .. rubric:: Variables Affecting the Check
  35. The following variables may be set before calling this command to modify
  36. the way the check is run:
  37. .. include:: /module/include/CMAKE_REQUIRED_FLAGS.rst
  38. .. include:: /module/include/CMAKE_REQUIRED_DEFINITIONS.rst
  39. .. include:: /module/include/CMAKE_REQUIRED_INCLUDES.rst
  40. .. include:: /module/include/CMAKE_REQUIRED_LINK_OPTIONS.rst
  41. .. include:: /module/include/CMAKE_REQUIRED_LIBRARIES.rst
  42. .. include:: /module/include/CMAKE_REQUIRED_LINK_DIRECTORIES.rst
  43. .. include:: /module/include/CMAKE_REQUIRED_QUIET.rst
  44. .. include:: /module/include/CMAKE_TRY_COMPILE_TARGET_TYPE.rst
  45. Examples
  46. ^^^^^^^^
  47. In the following example, this module is used to check whether the provided
  48. Objective-C source code compiles and links. Result of the check is stored in
  49. the internal cache variable ``HAVE_WORKING_CODE``.
  50. .. code-block:: cmake
  51. include(CheckOBJCSourceCompiles)
  52. check_objc_source_compiles("
  53. #import <Foundation/Foundation.h>
  54. int main()
  55. {
  56. NSObject *foo;
  57. return 0;
  58. }
  59. " HAVE_WORKING_CODE)
  60. See Also
  61. ^^^^^^^^
  62. * The :module:`CheckSourceCompiles` module for a more general command to
  63. check whether source can be built.
  64. * The :module:`CheckSourceRuns` module to check whether source can be built
  65. and run.
  66. #]=======================================================================]
  67. include_guard(GLOBAL)
  68. include(Internal/CheckSourceCompiles)
  69. macro(CHECK_OBJC_SOURCE_COMPILES SOURCE VAR)
  70. cmake_check_source_compiles(OBJC "${SOURCE}" ${VAR} ${ARGN})
  71. endmacro()