2 # Check if the function exists.
4 # CHECK_FUNCTION_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_FUNCTION_EXISTS FUNCTION VARIABLE)
10 IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
11 SET(MACRO_CHECK_FUNCTION_DEFINITIONS
12 "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
13 MESSAGE(STATUS "Looking for ${FUNCTION}")
14 IF(CMAKE_REQUIRED_LIBRARIES)
15 SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
16 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
17 ENDIF(CMAKE_REQUIRED_LIBRARIES)
18 TRY_COMPILE(${VARIABLE}
20 ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
21 CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
22 "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}"
23 OUTPUT_VARIABLE OUTPUT)
25 SET(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}")
26 MESSAGE(STATUS "Looking for ${FUNCTION} - found")
27 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
28 "Determining if the function ${FUNCTION} exists passed with the following output:\n"
31 MESSAGE(STATUS "Looking for ${FUNCTION} - not found")
32 SET(${VARIABLE} "" CACHE INTERNAL "Have function ${FUNCTION}")
33 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeError.log
34 "Determining if the function ${FUNCTION} exists failed with the following output:\n"
37 ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
38 ENDMACRO(CHECK_FUNCTION_EXISTS)