CheckCCompilerFlag.cmake 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. CheckCCompilerFlag
  5. ------------------
  6. Check whether the C compiler supports a given flag.
  7. .. command:: check_c_compiler_flag
  8. .. code-block:: cmake
  9. check_c_compiler_flag(<flag> <resultVar>)
  10. Check that the ``<flag>`` is accepted by the compiler without
  11. a diagnostic. Stores the result in an internal cache entry
  12. named ``<resultVar>``.
  13. A positive result from this check indicates only that the compiler did not
  14. issue a diagnostic message when given the flag. Whether the flag has any
  15. effect or even a specific one is beyond the scope of this module.
  16. The check is only performed once, with the result cached in the variable named
  17. by ``<resultVar>``. Every subsequent CMake run will re-use this cached value
  18. rather than performing the check again, even if the ``<code>`` changes. In
  19. order to force the check to be re-evaluated, the variable named by
  20. ``<resultVar>`` must be manually removed from the cache.
  21. The compile and link commands can be influenced by setting any of the
  22. following variables prior to calling ``check_c_compiler_flag()``
  23. .. include:: /module/CMAKE_REQUIRED_FLAGS.txt
  24. .. include:: /module/CMAKE_REQUIRED_DEFINITIONS.txt
  25. .. include:: /module/CMAKE_REQUIRED_INCLUDES.txt
  26. .. include:: /module/CMAKE_REQUIRED_LINK_OPTIONS.txt
  27. .. include:: /module/CMAKE_REQUIRED_LIBRARIES.txt
  28. .. include:: /module/CMAKE_REQUIRED_QUIET.txt
  29. #]=======================================================================]
  30. include_guard(GLOBAL)
  31. include(Internal/CheckCompilerFlag)
  32. macro (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
  33. cmake_check_compiler_flag(C "${_FLAG}" ${_RESULT})
  34. endmacro ()
  35. # FIXME(#24994): The following module is included only for compatibility
  36. # with projects that accidentally relied on it with CMake 3.26 and below.
  37. include(CheckCSourceCompiles)