CheckCSourceCompiles.cmake 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. CheckCSourceCompiles
  5. --------------------
  6. Check once if C source code can be built.
  7. .. command:: check_c_source_compiles
  8. .. code-block:: cmake
  9. check_c_source_compiles(<code> <resultVar>
  10. [FAIL_REGEX <regex1> [<regex2>...]])
  11. Check once that the source supplied in ``<code>`` can be built. The result is
  12. stored in the internal cache variable specified by ``<resultVar>``, with
  13. boolean ``true`` for success and boolean ``false`` for failure.
  14. If ``FAIL_REGEX`` is provided, then failure is determined by checking
  15. if anything in the compiler output matches any of the specified regular
  16. expressions.
  17. Internally, :command:`try_compile` is used to compile the source. If
  18. :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to ``EXECUTABLE`` (default),
  19. the source is compiled and linked as an executable program. If set to
  20. ``STATIC_LIBRARY``, the source is compiled but not linked. In any case, all
  21. functions must be declared as usual.
  22. See also :command:`check_source_compiles` for a more general command syntax.
  23. See also :command:`check_source_runs` to run compiled source.
  24. The compile and link commands can be influenced by setting any of the
  25. following variables prior to calling ``check_c_source_compiles()``:
  26. .. include:: /module/include/CMAKE_REQUIRED_FLAGS.rst
  27. .. include:: /module/include/CMAKE_REQUIRED_DEFINITIONS.rst
  28. .. include:: /module/include/CMAKE_REQUIRED_INCLUDES.rst
  29. .. include:: /module/include/CMAKE_REQUIRED_LINK_OPTIONS.rst
  30. .. include:: /module/include/CMAKE_REQUIRED_LIBRARIES.rst
  31. .. include:: /module/include/CMAKE_REQUIRED_LINK_DIRECTORIES.rst
  32. .. include:: /module/include/CMAKE_REQUIRED_QUIET.rst
  33. #]=======================================================================]
  34. include_guard(GLOBAL)
  35. include(Internal/CheckSourceCompiles)
  36. macro(CHECK_C_SOURCE_COMPILES SOURCE VAR)
  37. cmake_check_source_compiles(C "${SOURCE}" ${VAR} ${ARGN})
  38. endmacro()