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 # ARGCOUNT - number of arguments for stdcall functions
7 # LOCATION - location where the library should be found
8 # VARIABLE - variable to store the result
10 # The following variables may be set before calling this macro to
11 # modify the way the check is run:
13 # CMAKE_REQUIRED_FLAGS = string of compile command line flags
14 # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
15 # CMAKE_REQUIRED_LIBRARIES = list of libraries to link
17 MACRO(CHECK_SHARED_LIBRARY_EXISTS LIBRARY FUNCTION ARGCOUNT LOCATION VARIABLE)
18 IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
19 SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
20 "-DCHECK_SHARED_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
22 IF(${ARGCOUNT} GREATER 0)
26 WHILE(${ARGCOUNT} GREATER ${CURARG})
27 SET(ARGSTACK "${ARGSTACK},void*")
28 SET(CALLSTACK "${CALLSTACK},NULL")
29 MATH(EXPR CURARG "${CURARG} + 1")
30 ENDWHILE(${ARGCOUNT} GREATER ${CURARG})
31 ENDIF(${ARGCOUNT} GREATER 0)
32 SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
33 "-D_WIN32 -DARGSTACK=\"${ARGSTACK}\" -DCALLSTACK=\"${CALLSTACK}\" ${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}")
35 MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
36 SET(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY})
37 IF(CMAKE_REQUIRED_LIBRARIES)
38 SET(CHECK_LIBRARY_EXISTS_LIBRARIES
39 ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
40 ENDIF(CMAKE_REQUIRED_LIBRARIES)
41 TRY_COMPILE(${VARIABLE}
43 ${CMAKE_SOURCE_DIR}/cmake/CheckSharedFunctionExists.c
44 COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
46 -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
47 -DLINK_DIRECTORIES:STRING=${LOCATION}
48 "-DLINK_LIBRARIES:STRING=${CHECK_LIBRARY_EXISTS_LIBRARIES}"
49 OUTPUT_VARIABLE OUTPUT)
52 MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found")
53 SET(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}")
54 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
55 "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
56 "passed with the following output:\n"
59 MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found")
60 SET(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}")
61 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
62 "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
63 "failed with the following output:\n"
66 ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
67 ENDMACRO(CHECK_SHARED_LIBRARY_EXISTS)