STYLE: Nightly Version update
[cmake.git] / Modules / CheckIncludeFiles.cmake
blobcf0361c8f5ee3fcc818bdfbb2a60215b9dc2a649
2 # Check if the files can be included
4 # CHECK_INCLUDE_FILES - macro which checks the include file exists.
5 # INCLUDE - list of files to include
6 # VARIABLE - variable to return result
9 MACRO(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
10   IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
11     SET(CHECK_INCLUDE_FILES_CONTENT "/* */\n")
12     SET(MACRO_CHECK_INCLUDE_FILES_FLAGS ${CMAKE_REQUIRED_FLAGS})
13     FOREACH(FILE ${INCLUDE})
14       SET(CHECK_INCLUDE_FILES_CONTENT
15         "${CHECK_INCLUDE_FILES_CONTENT}#include <${FILE}>\n")
16     ENDFOREACH(FILE)
17     SET(CHECK_INCLUDE_FILES_CONTENT
18       "${CHECK_INCLUDE_FILES_CONTENT}\n\nint main(){return 0;}\n")
19     FILE(WRITE ${CMAKE_BINARY_DIR}/CMakeTmp/CheckIncludeFiles.c 
20       "${CHECK_INCLUDE_FILES_CONTENT}")
22     MESSAGE(STATUS "Looking for include files ${VARIABLE}")
23     TRY_COMPILE(${VARIABLE}
24       ${CMAKE_BINARY_DIR}
25       ${CMAKE_BINARY_DIR}/CMakeTmp/CheckIncludeFiles.c
26       CMAKE_FLAGS 
27       -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_FLAGS}
28       OUTPUT_VARIABLE OUTPUT)
29     IF(${VARIABLE})
30       MESSAGE(STATUS "Looking for include files ${VARIABLE} - found")
31       SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${VARIABLE}")
32       FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log 
33         "Determining if files ${INCLUDE} "
34         "exist passed with the following output:\n"
35         "${OUTPUT}\n\n")
36     ELSE(${VARIABLE})
37       MESSAGE(STATUS "Looking for include files ${VARIABLE} - not found.")
38       SET(${VARIABLE} "" CACHE INTERNAL "Have includes ${VARIABLE}")
39       FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeError.log 
40         "Determining if files ${INCLUDE} "
41         "exist failed with the following output:\n"
42         "${OUTPUT}\nSource:\n${CHECK_INCLUDE_FILES_CONTENT}\n")
43     ENDIF(${VARIABLE})
44   ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
45 ENDMACRO(CHECK_INCLUDE_FILES)