STYLE: Nightly Version update
[cmake.git] / Modules / CheckIncludeFile.cmake
blobc5e34753ddffab08a8f9837b6b6f3c5a18356291
2 # Check if the include file exists.
4 # CHECK_INCLUDE_FILE - macro which checks the include file exists.
5 # INCLUDE - name of include file
6 # VARIABLE - variable to return result
9 MACRO(CHECK_INCLUDE_FILE INCLUDE VARIABLE)
10   IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
11     SET(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
12     SET(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
13     CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CheckIncludeFile.c.in
14       ${CMAKE_BINARY_DIR}/CMakeTmp/CheckIncludeFile.c IMMEDIATE)
15     MESSAGE(STATUS "Looking for ${INCLUDE}")
16     IF(${ARGC} EQUAL 3)
17       SET(CMAKE_C_FLAGS_SAVE ${CMAKE_C_FLAGS})
18       SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARGV2}")
19     ENDIF(${ARGC} EQUAL 3)
21     TRY_COMPILE(${VARIABLE}
22       ${CMAKE_BINARY_DIR}
23       ${CMAKE_BINARY_DIR}/CMakeTmp/CheckIncludeFile.c
24       CMAKE_FLAGS 
25       -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
26       OUTPUT_VARIABLE OUTPUT) 
28     IF(${ARGC} EQUAL 3)
29       SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_SAVE})
30     ENDIF(${ARGC} EQUAL 3)
32     IF(${VARIABLE})
33       MESSAGE(STATUS "Looking for ${INCLUDE} - found")
34       SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
35       FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log 
36         "Determining if the include file ${INCLUDE} "
37         "exists passed with the following output:\n"
38         "${OUTPUT}\n\n")
39     ELSE(${VARIABLE})
40       MESSAGE(STATUS "Looking for ${INCLUDE} - not found.")
41       SET(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
42       FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeError.log 
43         "Determining if the include file ${INCLUDE} "
44         "exists failed with the following output:\n"
45         "${OUTPUT}\n\n")
46     ENDIF(${VARIABLE})
47   ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
48 ENDMACRO(CHECK_INCLUDE_FILE)