🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
4.5 KiB

  1. # - Check if a symbol exists as a function, variable, or macro
  2. # CHECK_SYMBOL_EXISTS(<symbol> <files> <variable>)
  3. #
  4. # Check that the <symbol> is available after including given header
  5. # <files> and store the result in a <variable>. Specify the list
  6. # of files in one argument as a semicolon-separated list.
  7. #
  8. # If the header files define the symbol as a macro it is considered
  9. # available and assumed to work. If the header files declare the
  10. # symbol as a function or variable then the symbol must also be
  11. # available for linking. If the symbol is a type or enum value
  12. # it will not be recognized (consider using CheckTypeSize or
  13. # CheckCSourceCompiles).
  14. #
  15. # The following variables may be set before calling this macro to
  16. # modify the way the check is run:
  17. #
  18. # CMAKE_REQUIRED_FLAGS = string of compile command line flags
  19. # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
  20. # CMAKE_REQUIRED_INCLUDES = list of include directories
  21. # CMAKE_REQUIRED_LIBRARIES = list of libraries to link
  22. #=============================================================================
  23. # Copyright 2003-2011 Kitware, Inc.
  24. #
  25. # Distributed under the OSI-approved BSD License (the "License");
  26. # see accompanying file Copyright.txt for details.
  27. #
  28. # This software is distributed WITHOUT ANY WARRANTY; without even the
  29. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  30. # See the License for more information.
  31. #=============================================================================
  32. # (To distribute this file outside of CMake, substitute the full
  33. # License text for the above reference.)
  34. MACRO(CHECK_SHARED_FUNCTION_EXISTS SYMBOL FILES LIBRARY LOCATION VARIABLE)
  35. IF(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
  36. SET(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
  37. SET(MACRO_CHECK_SYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS})
  38. IF(CMAKE_REQUIRED_LIBRARIES)
  39. SET(CHECK_SYMBOL_EXISTS_LIBS
  40. "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES};${LIBRARY}")
  41. ELSE(CMAKE_REQUIRED_LIBRARIES)
  42. SET(CHECK_SYMBOL_EXISTS_LIBS
  43. "-DLINK_LIBRARIES:STRING=${LIBRARY}")
  44. ENDIF(CMAKE_REQUIRED_LIBRARIES)
  45. IF(CMAKE_REQUIRED_INCLUDES)
  46. SET(CMAKE_SYMBOL_EXISTS_INCLUDES
  47. "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
  48. ELSE(CMAKE_REQUIRED_INCLUDES)
  49. SET(CMAKE_SYMBOL_EXISTS_INCLUDES)
  50. ENDIF(CMAKE_REQUIRED_INCLUDES)
  51. FOREACH(FILE ${FILES})
  52. SET(CMAKE_CONFIGURABLE_FILE_CONTENT
  53. "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
  54. ENDFOREACH(FILE)
  55. SET(CMAKE_CONFIGURABLE_FILE_CONTENT
  56. "${CMAKE_CONFIGURABLE_FILE_CONTENT}\nvoid cmakeRequireSymbol(int dummy,...){(void)dummy;}\nint main()\n{\n cmakeRequireSymbol(0,&${SYMBOL});\n return 0;\n}\n")
  57. CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
  58. "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" @ONLY)
  59. MESSAGE(STATUS "Looking for ${SYMBOL} in ${LIBRARY}")
  60. TRY_COMPILE(${VARIABLE}
  61. ${CMAKE_CURRENT_BINARY_DIR}
  62. ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c
  63. COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
  64. CMAKE_FLAGS
  65. -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_SYMBOL_EXISTS_FLAGS}
  66. -DLINK_DIRECTORIES:STRING=${LOCATION}
  67. "${CHECK_SYMBOL_EXISTS_LIBS}"
  68. "${CMAKE_SYMBOL_EXISTS_INCLUDES}"
  69. OUTPUT_VARIABLE OUTPUT)
  70. IF(${VARIABLE})
  71. MESSAGE(STATUS "Looking for ${SYMBOL} in ${LIBRARY} - found")
  72. SET(${VARIABLE} 1 CACHE INTERNAL "Have symbol ${SYMBOL} in ${LIBRARY}")
  73. FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  74. "Determining if the ${SYMBOL} "
  75. "exist in ${LIBRARY} passed with the following output:\n"
  76. "${OUTPUT}\nFile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c:\n"
  77. "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
  78. ELSE(${VARIABLE})
  79. MESSAGE(STATUS "Looking for ${SYMBOL} in ${LIBRARY} - not found.")
  80. SET(${VARIABLE} "" CACHE INTERNAL "Have symbol ${SYMBOL} in ${LIBRARY}")
  81. FILE(APPEND ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  82. "Determining if the ${SYMBOL} "
  83. "exist in ${LIBRARY} failed with the following output:\n"
  84. "${OUTPUT}\nFile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c:\n"
  85. "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
  86. ENDIF(${VARIABLE})
  87. ENDIF(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
  88. ENDMACRO(CHECK_SHARED_FUNCTION_EXISTS)