1
0

CheckFunctionExists.cmake 1.1 KB

1234567891011121314151617181920212223242526272829
  1. #
  2. # Check if the function exists.
  3. #
  4. # CHECK_FUNCTION_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_FUNCTION_EXISTS FUNCTION VARIABLE)
  9. IF(NOT ${VARIABLE})
  10. SET(MACRO_CHECK_FUNCTION_DEFINITIONS -DCHECK_FUNCTION_EXISTS=${FUNCTION})
  11. MESSAGE(STATUS "Looking for ${FUNCTION}")
  12. TRY_COMPILE(${VARIABLE}
  13. ${PROJECT_BINARY_DIR}
  14. ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
  15. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
  16. OUTPUT_VARIABLE OUTPUT)
  17. IF(${VARIABLE})
  18. SET(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}")
  19. MESSAGE(STATUS "Looking for ${FUNCTION} - found")
  20. ELSE(${VARIABLE})
  21. MESSAGE(STATUS "Looking for ${FUNCTION} - not found")
  22. SET(${VARIABLE} "" CACHE INTERNAL "Have function ${FUNCTION}")
  23. WRITE_FILE(${PROJECT_BINARY_DIR}/CMakeError.log
  24. "Determining if the function ${FUNCTION} exists failed with the following output:\n"
  25. "${OUTPUT}\n" APPEND)
  26. ENDIF(${VARIABLE})
  27. ENDIF(NOT ${VARIABLE})
  28. ENDMACRO(CHECK_FUNCTION_EXISTS)