1
0

CheckLibraryExists.cmake 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  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(NOT ${VARIABLE})
  10. SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION -DCHECK_FUNCTION_EXISTS=${FUNCTION})
  11. MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
  12. TRY_COMPILE(${VARIABLE}
  13. ${PROJECT_BINARY_DIR}
  14. ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
  15. CMAKE_FLAGS
  16. -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
  17. -DLINK_DIRECTORIES:STRING=${LOCATION}
  18. -DLINK_LIBRARIES:STRING=${LIBRARY}
  19. OUTPUT_VARIABLE OUTPUT)
  20. IF(${VARIABLE})
  21. MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found")
  22. SET(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}")
  23. ELSE(${VARIABLE})
  24. MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found")
  25. SET(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}")
  26. WRITE_FILE(${PROJECT_BINARY_DIR}/CMakeError.log
  27. "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
  28. "failed with the following output:\n"
  29. "${OUTPUT}\n" APPEND)
  30. ENDIF(${VARIABLE})
  31. ENDIF(NOT ${VARIABLE})
  32. ENDMACRO(CHECK_LIBRARY_EXISTS)