CheckCSourceCompiles.cmake 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. CheckCSourceCompiles
  5. --------------------
  6. Check if given C source compiles and links into an executable.
  7. .. command:: check_c_source_compiles
  8. .. code-block:: cmake
  9. check_c_source_compiles(<code> <resultVar>
  10. [FAIL_REGEX <regex1> [<regex2>...]])
  11. Check that the source supplied in ``<code>`` can be compiled as a C source
  12. file and linked as an executable (so it must contain at least a ``main()``
  13. function). The result will be stored in the internal cache variable specified
  14. by ``<resultVar>``, with a boolean true value for success and boolean false
  15. for failure. If ``FAIL_REGEX`` is provided, then failure is determined by
  16. checking if anything in the output matches any of the specified regular
  17. expressions.
  18. The check is only performed once, with the result cached in the variable named
  19. by ``<resultVar>``. Every subsequent CMake run will reuse this cached value
  20. rather than performing the check again, even if the ``<code>`` changes. In
  21. order to force the check to be re-evaluated, the variable named by
  22. ``<resultVar>`` must be manually removed from the cache.
  23. The compile and link commands can be influenced by setting any of the
  24. following variables prior to calling ``check_c_source_compiles()``:
  25. .. include:: /module/CMAKE_REQUIRED_FLAGS.txt
  26. .. include:: /module/CMAKE_REQUIRED_DEFINITIONS.txt
  27. .. include:: /module/CMAKE_REQUIRED_INCLUDES.txt
  28. .. include:: /module/CMAKE_REQUIRED_LINK_OPTIONS.txt
  29. .. include:: /module/CMAKE_REQUIRED_LIBRARIES.txt
  30. .. include:: /module/CMAKE_REQUIRED_QUIET.txt
  31. #]=======================================================================]
  32. include_guard(GLOBAL)
  33. include(Internal/CheckSourceCompiles)
  34. macro(CHECK_C_SOURCE_COMPILES SOURCE VAR)
  35. cmake_check_source_compiles(C "${SOURCE}" ${VAR} ${ARGN})
  36. endmacro()