1# Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2# file Copyright.txt or https://cmake.org/licensing for details. 3 4#[=======================================================================[.rst: 5CheckCompilerFlag 6--------------------- 7 8.. versionadded:: 3.19 9 10Check whether the compiler supports a given flag. 11 12.. command:: check_compiler_flag 13 14 .. code-block:: cmake 15 16 check_compiler_flag(<lang> <flag> <var>) 17 18Check that the ``<flag>`` is accepted by the compiler without a diagnostic. 19Stores the result in an internal cache entry named ``<var>``. 20 21This command temporarily sets the ``CMAKE_REQUIRED_DEFINITIONS`` variable 22and calls the ``check_source_compiles(<LANG>)`` function from the 23:module:`CheckSourceCompiles` module. See documentation of that 24module for a listing of variables that can otherwise modify the build. 25 26A positive result from this check indicates only that the compiler did not 27issue a diagnostic message when given the flag. Whether the flag has any 28effect or even a specific one is beyond the scope of this module. 29 30.. note:: 31 Since the :command:`try_compile` command forwards flags from variables 32 like :variable:`CMAKE_<LANG>_FLAGS <CMAKE_<LANG>_FLAGS>`, unknown flags 33 in such variables may cause a false negative for this check. 34#]=======================================================================] 35 36include_guard(GLOBAL) 37include(Internal/CheckCompilerFlag) 38 39function(CHECK_COMPILER_FLAG _lang _flag _var) 40 cmake_check_compiler_flag(${_lang} "${_flag}" ${_var}) 41endfunction() 42