2 # Check if the symbol exists in include files
4 # CHECK_SYMBOL_EXISTS - macro which checks the symbol exists in include files.
6 # FILES - include files to check
7 # VARIABLE - variable to return result
10 MACRO(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
11 IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
12 SET(CHECK_SYMBOL_EXISTS_CONTENT "/* */\n")
13 SET(MACRO_CHECK_SYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS})
14 IF(CMAKE_REQUIRED_LIBRARIES)
15 SET(CHECK_SYMBOL_EXISTS_LIBS
16 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
17 ENDIF(CMAKE_REQUIRED_LIBRARIES)
18 FOREACH(FILE ${FILES})
19 SET(CHECK_SYMBOL_EXISTS_CONTENT
20 "${CHECK_SYMBOL_EXISTS_CONTENT}#include <${FILE}>\n")
22 SET(CHECK_SYMBOL_EXISTS_CONTENT
23 "${CHECK_SYMBOL_EXISTS_CONTENT}\nvoid cmakeRequireSymbol(int dummy,...){(void)dummy;}\nint main()\n{\n#ifndef ${SYMBOL}\n cmakeRequireSymbol(0,&${SYMBOL});\n#endif\n return 0;\n}\n")
25 FILE(WRITE ${CMAKE_BINARY_DIR}/CMakeTmp/CheckSymbolExists.c
26 "${CHECK_SYMBOL_EXISTS_CONTENT}")
28 MESSAGE(STATUS "Looking for ${SYMBOL}")
29 TRY_COMPILE(${VARIABLE}
31 ${CMAKE_BINARY_DIR}/CMakeTmp/CheckSymbolExists.c
33 -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_SYMBOL_EXISTS_FLAGS}
34 "${CHECK_SYMBOL_EXISTS_LIBS}"
35 OUTPUT_VARIABLE OUTPUT)
37 MESSAGE(STATUS "Looking for ${SYMBOL} - found")
38 SET(${VARIABLE} 1 CACHE INTERNAL "Have symbol ${SYMBOL}")
39 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
40 "Determining if the ${SYMBOL} "
41 "exist passed with the following output:\n"
42 "${OUTPUT}\nFile ${CMAKE_BINARY_DIR}/CMakeTmp/CheckSymbolExists.c:\n"
43 "${CHECK_SYMBOL_EXISTS_CONTENT}\n")
45 MESSAGE(STATUS "Looking for ${SYMBOL} - not found.")
46 SET(${VARIABLE} "" CACHE INTERNAL "Have symbol ${SYMBOL}")
47 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeError.log
48 "Determining if the ${SYMBOL} "
49 "exist failed with the following output:\n"
50 "${OUTPUT}\nFile ${CMAKE_BINARY_DIR}/CMakeTmp/CheckSymbolExists.c:\n"
51 "${CHECK_SYMBOL_EXISTS_CONTENT}\n")
53 ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
54 ENDMACRO(CHECK_SYMBOL_EXISTS)