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: 5CheckCXXSymbolExists 6-------------------- 7 8Check if a symbol exists as a function, variable, or macro in ``C++``. 9 10.. command:: check_cxx_symbol_exists 11 12 .. code-block:: cmake 13 14 check_cxx_symbol_exists(<symbol> <files> <variable>) 15 16 Check that the ``<symbol>`` is available after including given header 17 ``<files>`` and store the result in a ``<variable>``. Specify the list of 18 files in one argument as a semicolon-separated list. 19 ``check_cxx_symbol_exists()`` can be used to check for symbols as seen by 20 the C++ compiler, as opposed to :command:`check_symbol_exists`, which always 21 uses the ``C`` compiler. 22 23 If the header files define the symbol as a macro it is considered 24 available and assumed to work. If the header files declare the symbol 25 as a function or variable then the symbol must also be available for 26 linking. If the symbol is a type, enum value, or C++ template it will 27 not be recognized: consider using the :module:`CheckTypeSize` 28 or :module:`CheckSourceCompiles` module instead. 29 30.. note:: 31 32 This command is unreliable when ``<symbol>`` is (potentially) an overloaded 33 function. Since there is no reliable way to predict whether a given function 34 in the system environment may be defined as an overloaded function or may be 35 an overloaded function on other systems or will become so in the future, it 36 is generally advised to use the :module:`CheckCXXSourceCompiles` module for 37 checking any function symbol (unless somehow you surely know the checked 38 function is not overloaded on other systems or will not be so in the 39 future). 40 41The following variables may be set before calling this macro to modify 42the way the check is run: 43 44``CMAKE_REQUIRED_FLAGS`` 45 string of compile command line flags. 46``CMAKE_REQUIRED_DEFINITIONS`` 47 a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar). 48``CMAKE_REQUIRED_INCLUDES`` 49 a :ref:`;-list <CMake Language Lists>` of header search paths to pass to 50 the compiler. 51``CMAKE_REQUIRED_LINK_OPTIONS`` 52 .. versionadded:: 3.14 53 a :ref:`;-list <CMake Language Lists>` of options to add to the link command. 54``CMAKE_REQUIRED_LIBRARIES`` 55 a :ref:`;-list <CMake Language Lists>` of libraries to add to the link 56 command. See policy :policy:`CMP0075`. 57``CMAKE_REQUIRED_QUIET`` 58 .. versionadded:: 3.1 59 execute quietly without messages. 60 61For example: 62 63.. code-block:: cmake 64 65 include(CheckCXXSymbolExists) 66 67 # Check for macro SEEK_SET 68 check_cxx_symbol_exists(SEEK_SET "cstdio" HAVE_SEEK_SET) 69 # Check for function std::fopen 70 check_cxx_symbol_exists(std::fopen "cstdio" HAVE_STD_FOPEN) 71#]=======================================================================] 72 73include_guard(GLOBAL) 74include(CheckSymbolExists) 75 76macro(CHECK_CXX_SYMBOL_EXISTS SYMBOL FILES VARIABLE) 77 __CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" ) 78endmacro() 79