CheckCXXSymbolExists.cmake 2.2 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. CheckCXXSymbolExists
  5. --------------------
  6. Check if a symbol exists as a function, variable, or macro in C++
  7. .. command:: CHECK_CXX_SYMBOL_EXISTS
  8. .. code-block:: cmake
  9. CHECK_CXX_SYMBOL_EXISTS(<symbol> <files> <variable>)
  10. Check that the ``<symbol>`` is available after including given header
  11. ``<files>`` and store the result in a ``<variable>``. Specify the list of
  12. files in one argument as a semicolon-separated list.
  13. ``CHECK_CXX_SYMBOL_EXISTS()`` can be used to check in C++ files, as
  14. opposed to ``CHECK_SYMBOL_EXISTS()``, which works only for ``C``.
  15. If the header files define the symbol as a macro it is considered
  16. available and assumed to work. If the header files declare the symbol
  17. as a function or variable then the symbol must also be available for
  18. linking. If the symbol is a type or enum value it will not be
  19. recognized (consider using :module:`CheckTypeSize`
  20. or :module:`CheckCXXSourceCompiles`).
  21. The following variables may be set before calling this macro to modify
  22. the way the check is run:
  23. ``CMAKE_REQUIRED_FLAGS``
  24. string of compile command line flags.
  25. ``CMAKE_REQUIRED_DEFINITIONS``
  26. a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar).
  27. ``CMAKE_REQUIRED_INCLUDES``
  28. a :ref:`;-list <CMake Language Lists>` of header search paths to pass to
  29. the compiler.
  30. ``CMAKE_REQUIRED_LINK_OPTIONS``
  31. a :ref:`;-list <CMake Language Lists>` of options to add to the link command.
  32. ``CMAKE_REQUIRED_LIBRARIES``
  33. a :ref:`;-list <CMake Language Lists>` of libraries to add to the link
  34. command. See policy :policy:`CMP0075`.
  35. ``CMAKE_REQUIRED_QUIET``
  36. execute quietly without messages.
  37. #]=======================================================================]
  38. include_guard(GLOBAL)
  39. include(CheckSymbolExists)
  40. macro(CHECK_CXX_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
  41. __CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
  42. endmacro()