CheckCXXSymbolExists.cmake 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 for symbols as seen by
  14. the C++ compiler, as opposed to :command:`check_symbol_exists`, which always
  15. uses the ``C`` compiler.
  16. If the header files define the symbol as a macro it is considered
  17. available and assumed to work. If the header files declare the symbol
  18. as a function or variable then the symbol must also be available for
  19. linking. If the symbol is a type, enum value, or C++ template it will
  20. not be recognized: consider using the :module:`CheckTypeSize`
  21. or :module:`CheckCXXSourceCompiles` module instead.
  22. The following variables may be set before calling this macro to modify
  23. the way the check is run:
  24. ``CMAKE_REQUIRED_FLAGS``
  25. string of compile command line flags.
  26. ``CMAKE_REQUIRED_DEFINITIONS``
  27. a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar).
  28. ``CMAKE_REQUIRED_INCLUDES``
  29. a :ref:`;-list <CMake Language Lists>` of header search paths to pass to
  30. the compiler.
  31. ``CMAKE_REQUIRED_LINK_OPTIONS``
  32. a :ref:`;-list <CMake Language Lists>` of options to add to the link command.
  33. ``CMAKE_REQUIRED_LIBRARIES``
  34. a :ref:`;-list <CMake Language Lists>` of libraries to add to the link
  35. command. See policy :policy:`CMP0075`.
  36. ``CMAKE_REQUIRED_QUIET``
  37. execute quietly without messages.
  38. For example:
  39. .. code-block:: cmake
  40. include(CheckCXXSymbolExists)
  41. # Check for macro SEEK_SET
  42. check_cxx_symbol_exists(SEEK_SET "cstdio" HAVE_SEEK_SET)
  43. # Check for function std::fopen
  44. check_cxx_symbol_exists(std::fopen "cstdio" HAVE_STD_FOPEN)
  45. #]=======================================================================]
  46. include_guard(GLOBAL)
  47. include(CheckSymbolExists)
  48. macro(CHECK_CXX_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
  49. __CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
  50. endmacro()