2 # Check if the function exists.
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
9 MACRO(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
10 IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
11 SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
12 "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
13 MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
14 SET(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY})
15 IF(CMAKE_REQUIRED_LIBRARIES)
16 SET(CHECK_LIBRARY_EXISTS_LIBRARIES
17 ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
18 ENDIF(CMAKE_REQUIRED_LIBRARIES)
19 TRY_COMPILE(${VARIABLE}
21 ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
23 -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
24 -DLINK_DIRECTORIES:STRING=${LOCATION}
25 "-DLINK_LIBRARIES:STRING=${CHECK_LIBRARY_EXISTS_LIBRARIES}"
26 OUTPUT_VARIABLE OUTPUT)
29 MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found")
30 SET(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}")
31 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
32 "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
33 "passed with the following output:\n"
36 MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found")
37 SET(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}")
38 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeError.log
39 "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
40 "failed with the following output:\n"
43 ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
44 ENDMACRO(CHECK_LIBRARY_EXISTS)