1 # - Check if the include file exists.
2 # CHECK_INCLUDE_FILE(INCLUDE VARIABLE)
3 # - macro which checks the include file exists.
4 # INCLUDE - name of include file
5 # VARIABLE - variable to return result
7 # an optional third argument is the CFlags to add to the compile line
8 # or you can use CMAKE_REQUIRED_FLAGS
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_INCLUDES = list of include directories
17 MACRO(CHECK_INCLUDE_FILE INCLUDE VARIABLE)
18 IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
19 IF(CMAKE_REQUIRED_INCLUDES)
20 SET(CHECK_INCLUDE_FILE_C_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
21 ELSE(CMAKE_REQUIRED_INCLUDES)
22 SET(CHECK_INCLUDE_FILE_C_INCLUDE_DIRS)
23 ENDIF(CMAKE_REQUIRED_INCLUDES)
24 SET(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
25 SET(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
26 CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CheckIncludeFile.c.in
27 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c IMMEDIATE)
28 MESSAGE(STATUS "Looking for ${INCLUDE}")
30 SET(CMAKE_C_FLAGS_SAVE ${CMAKE_C_FLAGS})
31 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARGV2}")
32 ENDIF(${ARGC} EQUAL 3)
34 TRY_COMPILE(${VARIABLE}
36 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c
37 COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
39 -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
40 "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}"
41 OUTPUT_VARIABLE OUTPUT)
44 SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_SAVE})
45 ENDIF(${ARGC} EQUAL 3)
48 MESSAGE(STATUS "Looking for ${INCLUDE} - found")
49 SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
50 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
51 "Determining if the include file ${INCLUDE} "
52 "exists passed with the following output:\n"
55 MESSAGE(STATUS "Looking for ${INCLUDE} - not found")
56 SET(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
57 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
58 "Determining if the include file ${INCLUDE} "
59 "exists failed with the following output:\n"
62 ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
63 ENDMACRO(CHECK_INCLUDE_FILE)