Updated formatting of documentation plus a little reorganization.
[cmake.git] / Modules / CheckIncludeFiles.cmake
blobbf791e7ed28b2f65ff55a178fb1f235308a4aee4
1 # - Check if the files can be included
3 # CHECK_INCLUDE_FILES(INCLUDE VARIABLE)
5 #  INCLUDE  - list of files to include
6 #  VARIABLE - variable to return result
8 # The following variables may be set before calling this macro to
9 # modify the way the check is run:
11 #  CMAKE_REQUIRED_FLAGS = string of compile command line flags
12 #  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
13 #  CMAKE_REQUIRED_INCLUDES = list of include directories
15 MACRO(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
16   IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
17     SET(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
18     IF(CMAKE_REQUIRED_INCLUDES)
19       SET(CHECK_INCLUDE_FILES_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
20     ELSE(CMAKE_REQUIRED_INCLUDES)
21       SET(CHECK_INCLUDE_FILES_INCLUDE_DIRS)
22     ENDIF(CMAKE_REQUIRED_INCLUDES)
23     SET(CHECK_INCLUDE_FILES_CONTENT "/* */\n")
24     SET(MACRO_CHECK_INCLUDE_FILES_FLAGS ${CMAKE_REQUIRED_FLAGS})
25     FOREACH(FILE ${INCLUDE})
26       SET(CMAKE_CONFIGURABLE_FILE_CONTENT
27         "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
28     ENDFOREACH(FILE)
29     SET(CMAKE_CONFIGURABLE_FILE_CONTENT
30       "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n\nint main(){return 0;}\n")
31     CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
32       "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c" @ONLY IMMEDIATE)
34     MESSAGE(STATUS "Looking for include files ${VARIABLE}")
35     TRY_COMPILE(${VARIABLE}
36       ${CMAKE_BINARY_DIR}
37       ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c
38       COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
39       CMAKE_FLAGS 
40       -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_FLAGS}
41       "${CHECK_INCLUDE_FILES_INCLUDE_DIRS}"
42       OUTPUT_VARIABLE OUTPUT)
43     IF(${VARIABLE})
44       MESSAGE(STATUS "Looking for include files ${VARIABLE} - found")
45       SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${VARIABLE}")
46       FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 
47         "Determining if files ${INCLUDE} "
48         "exist passed with the following output:\n"
49         "${OUTPUT}\n\n")
50     ELSE(${VARIABLE})
51       MESSAGE(STATUS "Looking for include files ${VARIABLE} - not found.")
52       SET(${VARIABLE} "" CACHE INTERNAL "Have includes ${VARIABLE}")
53       FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 
54         "Determining if files ${INCLUDE} "
55         "exist failed with the following output:\n"
56         "${OUTPUT}\nSource:\n${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
57     ENDIF(${VARIABLE})
58   ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
59 ENDMACRO(CHECK_INCLUDE_FILES)