CheckCCompilerFlag.cmake 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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> <var>)
  10. Check that the ``<flag>`` is accepted by the compiler without
  11. a diagnostic. Stores the result in an internal cache entry
  12. named ``<var>``.
  13. This command temporarily sets the ``CMAKE_REQUIRED_DEFINITIONS`` variable
  14. and calls the ``check_c_source_compiles`` macro from the
  15. :module:`CheckCSourceCompiles` module. See documentation of that
  16. module for a listing of variables that can otherwise modify the build.
  17. A positive result from this check indicates only that the compiler did not
  18. issue a diagnostic message when given the flag. Whether the flag has any
  19. effect or even a specific one is beyond the scope of this module.
  20. .. note::
  21. Since the :command:`try_compile` command forwards flags from variables
  22. like :variable:`CMAKE_C_FLAGS <CMAKE_<LANG>_FLAGS>`, unknown flags
  23. in such variables may cause a false negative for this check.
  24. #]=======================================================================]
  25. include_guard(GLOBAL)
  26. include(CheckCSourceCompiles)
  27. include(CheckCompilerFlag)
  28. macro (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
  29. check_compiler_flag(C "${_FLAG}" ${_RESULT})
  30. endmacro ()