CheckLibraryExists.cmake 983 B

1234567891011121314151617181920212223242526
  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. SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION -DCHECK_FUNCTION_EXISTS=${FUNCTION})
  10. TRY_COMPILE(${VARIABLE}
  11. ${PROJECT_BINARY_DIR}/CheckIfLibraryExists
  12. ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
  13. CMAKE_FLAGS
  14. -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
  15. -DLINK_DIRECTORIES:STRING=${LOCATION}
  16. -DLINK_LIBRARIES:STRING=${LIBRARY}
  17. OUTPUT_VARIABLE OUTPUT)
  18. IF(NOT ${VARIABLE})
  19. WRITE_FILE(${PROJECT_BINARY_DIR}/CMakeError.log
  20. "Determining if the function ${FUNCTION} exists in the ${LIBRARY} failed with the following output:\n"
  21. "${OUTPUT}\n")
  22. ENDIF(NOT ${VARIABLE})
  23. ENDMACRO(CHECK_LIBRARY_EXISTS)