1 # - Check if the function exists.
2 # CHECK_FUNCTION_EXISTS(FUNCTION VARIABLE)
3 # - macro which checks if the function exists
4 # FUNCTION - the name of the function
5 # VARIABLE - variable to store the result
7 # The following variables may be set before calling this macro to
8 # modify the way the check is run:
10 # CMAKE_REQUIRED_FLAGS = string of compile command line flags
11 # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
12 # CMAKE_REQUIRED_INCLUDES = list of include directories
13 # CMAKE_REQUIRED_LIBRARIES = list of libraries to link
15 MACRO(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE)
16 IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
17 SET(MACRO_CHECK_FUNCTION_DEFINITIONS
18 "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
19 MESSAGE(STATUS "Looking for ${FUNCTION}")
20 IF(CMAKE_REQUIRED_LIBRARIES)
21 SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
22 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
23 ELSE(CMAKE_REQUIRED_LIBRARIES)
24 SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES)
25 ENDIF(CMAKE_REQUIRED_LIBRARIES)
26 IF(CMAKE_REQUIRED_INCLUDES)
27 SET(CHECK_FUNCTION_EXISTS_ADD_INCLUDES
28 "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
29 ELSE(CMAKE_REQUIRED_INCLUDES)
30 SET(CHECK_FUNCTION_EXISTS_ADD_INCLUDES)
31 ENDIF(CMAKE_REQUIRED_INCLUDES)
32 TRY_COMPILE(${VARIABLE}
34 ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
35 COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
36 CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
37 "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}"
38 "${CHECK_FUNCTION_EXISTS_ADD_INCLUDES}"
39 OUTPUT_VARIABLE OUTPUT)
41 SET(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}")
42 MESSAGE(STATUS "Looking for ${FUNCTION} - found")
43 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
44 "Determining if the function ${FUNCTION} exists passed with the following output:\n"
47 MESSAGE(STATUS "Looking for ${FUNCTION} - not found")
48 SET(${VARIABLE} "" CACHE INTERNAL "Have function ${FUNCTION}")
49 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
50 "Determining if the function ${FUNCTION} exists failed with the following output:\n"
53 ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
54 ENDMACRO(CHECK_FUNCTION_EXISTS)