1
0

CheckCXXSymbolExists.cmake 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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:`CheckSourceCompiles` module instead.
  22. .. note::
  23. This command is unreliable when ``<symbol>`` is (potentially) an overloaded
  24. function. Since there is no reliable way to predict whether a given function
  25. in the system environment may be defined as an overloaded function or may be
  26. an overloaded function on other systems or will become so in the future, it
  27. is generally advised to use the :module:`CheckSourceCompiles` module for
  28. checking any function symbol (unless somehow you surely know the checked
  29. function is not overloaded on other systems or will not be so in the
  30. future).
  31. The following variables may be set before calling this macro to modify
  32. the way the check is run:
  33. .. include:: /module/CMAKE_REQUIRED_FLAGS.txt
  34. .. include:: /module/CMAKE_REQUIRED_DEFINITIONS.txt
  35. .. include:: /module/CMAKE_REQUIRED_INCLUDES.txt
  36. .. include:: /module/CMAKE_REQUIRED_LINK_OPTIONS.txt
  37. .. include:: /module/CMAKE_REQUIRED_LIBRARIES.txt
  38. .. include:: /module/CMAKE_REQUIRED_QUIET.txt
  39. For example:
  40. .. code-block:: cmake
  41. include(CheckCXXSymbolExists)
  42. # Check for macro SEEK_SET
  43. check_cxx_symbol_exists(SEEK_SET "cstdio" HAVE_SEEK_SET)
  44. # Check for function std::fopen
  45. check_cxx_symbol_exists(std::fopen "cstdio" HAVE_STD_FOPEN)
  46. #]=======================================================================]
  47. include_guard(GLOBAL)
  48. include(CheckSymbolExists)
  49. macro(CHECK_CXX_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
  50. __CHECK_SYMBOL_EXISTS_IMPL(CheckSymbolExists.cxx "${SYMBOL}" "${FILES}" "${VARIABLE}" )
  51. endmacro()