CheckCSourceRuns.cmake 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. CheckCSourceRuns
  5. ----------------
  6. Check once if given C source compiles and links into an executable and can
  7. subsequently be run.
  8. .. command:: check_c_source_runs
  9. .. code-block:: cmake
  10. check_c_source_runs(<code> <resultVar>)
  11. Check once that the source supplied in ``<code>`` can be built, linked as an
  12. executable, and then run. The ``<code>`` must contain at least a ``main()``
  13. function.
  14. The result is stored in the internal cache variable specified by
  15. ``<resultVar>``. Success of build and run is indicated by boolean ``true``.
  16. Failure to build or run is indicated by boolean ``false`` such as an empty
  17. string or an error message.
  18. See also :command:`check_source_runs` for a more general command syntax.
  19. The compile and link commands can be influenced by setting any of the
  20. following variables prior to calling ``check_c_source_runs()``:
  21. .. include:: /module/CMAKE_REQUIRED_FLAGS.txt
  22. .. include:: /module/CMAKE_REQUIRED_DEFINITIONS.txt
  23. .. include:: /module/CMAKE_REQUIRED_INCLUDES.txt
  24. .. include:: /module/CMAKE_REQUIRED_LINK_OPTIONS.txt
  25. .. include:: /module/CMAKE_REQUIRED_LIBRARIES.txt
  26. .. include:: /module/CMAKE_REQUIRED_LINK_DIRECTORIES.txt
  27. .. include:: /module/CMAKE_REQUIRED_QUIET.txt
  28. #]=======================================================================]
  29. include_guard(GLOBAL)
  30. include(Internal/CheckSourceRuns)
  31. macro(CHECK_C_SOURCE_RUNS SOURCE VAR)
  32. set(_CheckSourceRuns_old_signature 1)
  33. cmake_check_source_runs(C "${SOURCE}" ${VAR} ${ARGN})
  34. unset(_CheckSourceRuns_old_signature)
  35. endmacro()