CheckCompilerFlag.cmake 1.8 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. CheckCompilerFlag
  5. ---------------------
  6. .. versionadded:: 3.19
  7. Check whether the compiler supports a given flag.
  8. .. command:: check_compiler_flag
  9. .. code-block:: cmake
  10. check_compiler_flag(<lang> <flag> <resultVar>)
  11. Check that the ``<flag>`` is accepted by the compiler without a diagnostic.
  12. Stores the result in an internal cache entry 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 reuse 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_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. function(CHECK_COMPILER_FLAG _lang _flag _var)
  33. cmake_check_compiler_flag(${_lang} "${_flag}" ${_var})
  34. endfunction()