CheckLibraryExists.cmake 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #
  2. # Check if the function exists.
  3. #
  4. # CHECK_LIBRARY_EXISTS - macro which checks if the function exists
  5. # FUNCTION - the name of the function
  6. # VARIABLE - variable to store the result
  7. #
  8. MACRO(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
  9. IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
  10. SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION -DCHECK_FUNCTION_EXISTS=${FUNCTION})
  11. MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
  12. SET(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY})
  13. IF(CMAKE_REQUIRED_LIBRARIES)
  14. SET(CHECK_LIBRARY_EXISTS_LIBRARIES
  15. ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
  16. ENDIF(CMAKE_REQUIRED_LIBRARIES)
  17. TRY_COMPILE(${VARIABLE}
  18. ${CMAKE_BINARY_DIR}
  19. ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
  20. CMAKE_FLAGS
  21. -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
  22. -DLINK_DIRECTORIES:STRING=${LOCATION}
  23. "-DLINK_LIBRARIES:STRING=${CHECK_LIBRARY_EXISTS_LIBRARIES}"
  24. OUTPUT_VARIABLE OUTPUT)
  25. IF(${VARIABLE})
  26. MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found")
  27. SET(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}")
  28. ELSE(${VARIABLE})
  29. MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found")
  30. SET(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}")
  31. WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeError.log
  32. "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
  33. "failed with the following output:\n"
  34. "${OUTPUT}\n" APPEND)
  35. ENDIF(${VARIABLE})
  36. ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
  37. ENDMACRO(CHECK_LIBRARY_EXISTS)