1 # - Check if the function exists.
2 # CHECK_LIBRARY_EXISTS (LIBRARY FUNCTION LOCATION VARIABLE)
4 # LIBRARY - the name of the library you are looking for
5 # FUNCTION - the name of the function
6 # LOCATION - location where the library should be found
7 # VARIABLE - variable to store the result
9 # The following variables may be set before calling this macro to
10 # modify the way the check is run:
12 # CMAKE_REQUIRED_FLAGS = string of compile command line flags
13 # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
14 # CMAKE_REQUIRED_LIBRARIES = list of libraries to link
16 MACRO(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
17 IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
18 SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
19 "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
20 MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
21 SET(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY})
22 IF(CMAKE_REQUIRED_LIBRARIES)
23 SET(CHECK_LIBRARY_EXISTS_LIBRARIES
24 ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
25 ENDIF(CMAKE_REQUIRED_LIBRARIES)
26 TRY_COMPILE(${VARIABLE}
28 ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
29 COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
31 -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
32 -DLINK_DIRECTORIES:STRING=${LOCATION}
33 "-DLINK_LIBRARIES:STRING=${CHECK_LIBRARY_EXISTS_LIBRARIES}"
34 OUTPUT_VARIABLE OUTPUT)
37 MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found")
38 SET(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}")
39 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
40 "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
41 "passed with the following output:\n"
44 MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found")
45 SET(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}")
46 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
47 "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
48 "failed with the following output:\n"
51 ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
52 ENDMACRO(CHECK_LIBRARY_EXISTS)