CheckCompilerFlag.cmake 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. CheckCompilerFlag
  5. ---------------------
  6. .. versionadded:: 3.19
  7. Check once whether the ``<lang>`` compiler supports a given flag.
  8. .. command:: check_compiler_flag
  9. .. code-block:: cmake
  10. check_compiler_flag(<lang> <flag> <resultVar>)
  11. Check once that the ``<flag>`` is accepted by the ``<lang>`` compiler without
  12. a diagnostic. The result is stored in the internal cache variable specified by
  13. ``<resultVar>``, with boolean ``true`` for success and boolean ``false`` for
  14. failure.
  15. ``true`` indicates only that the compiler did not issue a diagnostic message
  16. when given the flag. Whether the flag has any effect is beyond the scope of
  17. this module.
  18. Internally, :command:`try_compile` is used to perform the check. If
  19. :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to ``EXECUTABLE`` (default),
  20. the check compiles and links an executable program. If set to
  21. ``STATIC_LIBRARY``, the check is compiled but not linked.
  22. The compile and link commands can be influenced by setting any of the
  23. following variables prior to calling ``check_compiler_flag()``. Unknown flags
  24. in these variables can case a false negative result.
  25. .. include:: /module/include/CMAKE_REQUIRED_FLAGS.rst
  26. .. include:: /module/include/CMAKE_REQUIRED_DEFINITIONS.rst
  27. .. include:: /module/include/CMAKE_REQUIRED_INCLUDES.rst
  28. .. include:: /module/include/CMAKE_REQUIRED_LINK_OPTIONS.rst
  29. .. include:: /module/include/CMAKE_REQUIRED_LIBRARIES.rst
  30. .. include:: /module/include/CMAKE_REQUIRED_LINK_DIRECTORIES.rst
  31. .. include:: /module/include/CMAKE_REQUIRED_QUIET.rst
  32. #]=======================================================================]
  33. include_guard(GLOBAL)
  34. include(Internal/CheckCompilerFlag)
  35. function(CHECK_COMPILER_FLAG _lang _flag _var)
  36. cmake_check_compiler_flag(${_lang} "${_flag}" ${_var})
  37. endfunction()