ENH: fix bug where sharedforward would not work if there was a space in the path...
[cmake.git] / Modules / CheckIncludeFile.cmake
blobcfb69214984977bc64112e130deb073b49dad46d
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
6 #   
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}")
29     IF(${ARGC} EQUAL 3)
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}
35       ${CMAKE_BINARY_DIR}
36       ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c
37       COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
38       CMAKE_FLAGS 
39       -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
40       "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}"
41       OUTPUT_VARIABLE OUTPUT) 
43     IF(${ARGC} EQUAL 3)
44       SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_SAVE})
45     ENDIF(${ARGC} EQUAL 3)
47     IF(${VARIABLE})
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"
53         "${OUTPUT}\n\n")
54     ELSE(${VARIABLE})
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"
60         "${OUTPUT}\n\n")
61     ENDIF(${VARIABLE})
62   ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
63 ENDMACRO(CHECK_INCLUDE_FILE)