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_SHARED_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
17 IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
18 SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
19 "-DCHECK_SHARED_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
21 SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
22 "-D_WIN32 ${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}")
24 MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
25 SET(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY})
26 IF(CMAKE_REQUIRED_LIBRARIES)
27 SET(CHECK_LIBRARY_EXISTS_LIBRARIES
28 ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
29 ENDIF(CMAKE_REQUIRED_LIBRARIES)
30 TRY_COMPILE(${VARIABLE}
32 ${CMAKE_SOURCE_DIR}/cmake/CheckSharedFunctionExists.c
33 COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
35 -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
36 -DLINK_DIRECTORIES:STRING=${LOCATION}
37 "-DLINK_LIBRARIES:STRING=${CHECK_LIBRARY_EXISTS_LIBRARIES}"
38 OUTPUT_VARIABLE OUTPUT)
41 MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found")
42 SET(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}")
43 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
44 "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
45 "passed with the following output:\n"
48 MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found")
49 SET(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}")
50 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
51 "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
52 "failed with the following output:\n"
55 ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
56 ENDMACRO(CHECK_SHARED_LIBRARY_EXISTS)