CheckCXXSourceRuns.cmake 2.0 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. CheckCXXSourceRuns
  5. ------------------
  6. Check if given C++ source compiles and links into an executable and can
  7. subsequently be run.
  8. .. command:: check_cxx_source_runs
  9. .. code-block:: cmake
  10. check_cxx_source_runs(<code> <resultVar>)
  11. Check that the source supplied in ``<code>`` can be compiled as a C++ source
  12. file, linked as an executable and then run. The ``<code>`` must contain at
  13. least a ``main()`` function. If the ``<code>`` could be built and run
  14. successfully, the internal cache variable specified by ``<resultVar>`` will
  15. be set to 1, otherwise it will be set to an value that evaluates to boolean
  16. false (e.g. an empty string or an error message).
  17. The check is only performed once, with the result cached in the variable named
  18. by ``<resultVar>``. Every subsequent CMake run will reuse this cached value
  19. rather than performing the check again, even if the ``<code>`` changes. In
  20. order to force the check to be re-evaluated, the variable named by
  21. ``<resultVar>`` must be manually removed from the cache.
  22. The compile and link commands can be influenced by setting any of the
  23. following variables prior to calling ``check_cxx_source_runs()``:
  24. .. include:: /module/CMAKE_REQUIRED_FLAGS.txt
  25. .. include:: /module/CMAKE_REQUIRED_DEFINITIONS.txt
  26. .. include:: /module/CMAKE_REQUIRED_INCLUDES.txt
  27. .. include:: /module/CMAKE_REQUIRED_LINK_OPTIONS.txt
  28. .. include:: /module/CMAKE_REQUIRED_LIBRARIES.txt
  29. .. include:: /module/CMAKE_REQUIRED_QUIET.txt
  30. #]=======================================================================]
  31. include_guard(GLOBAL)
  32. include(Internal/CheckSourceRuns)
  33. macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR)
  34. set(_CheckSourceRuns_old_signature 1)
  35. cmake_check_source_runs(CXX "${SOURCE}" ${VAR} ${ARGN})
  36. unset(_CheckSourceRuns_old_signature)
  37. endmacro()