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
18 #=============================================================================
19 # Copyright 2002-2009 Kitware, Inc.
21 # Distributed under the OSI-approved BSD License (the "License");
22 # see accompanying file Copyright.txt for details.
24 # This software is distributed WITHOUT ANY WARRANTY; without even the
25 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 # See the License for more information.
27 #=============================================================================
28 # (To distribute this file outside of CMake, substitute the full
29 # License text for the above reference.)
31 MACRO(CHECK_INCLUDE_FILE INCLUDE VARIABLE)
32 IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
33 IF(CMAKE_REQUIRED_INCLUDES)
34 SET(CHECK_INCLUDE_FILE_C_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
35 ELSE(CMAKE_REQUIRED_INCLUDES)
36 SET(CHECK_INCLUDE_FILE_C_INCLUDE_DIRS)
37 ENDIF(CMAKE_REQUIRED_INCLUDES)
38 SET(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
39 SET(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
40 CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CheckIncludeFile.c.in
41 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c IMMEDIATE)
42 MESSAGE(STATUS "Looking for ${INCLUDE}")
44 SET(CMAKE_C_FLAGS_SAVE ${CMAKE_C_FLAGS})
45 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARGV2}")
46 ENDIF(${ARGC} EQUAL 3)
48 TRY_COMPILE(${VARIABLE}
50 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c
51 COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
53 -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
54 "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}"
55 OUTPUT_VARIABLE OUTPUT)
58 SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_SAVE})
59 ENDIF(${ARGC} EQUAL 3)
62 MESSAGE(STATUS "Looking for ${INCLUDE} - found")
63 SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
64 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
65 "Determining if the include file ${INCLUDE} "
66 "exists passed with the following output:\n"
69 MESSAGE(STATUS "Looking for ${INCLUDE} - not found")
70 SET(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
71 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
72 "Determining if the include file ${INCLUDE} "
73 "exists failed with the following output:\n"
76 ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
77 ENDMACRO(CHECK_INCLUDE_FILE)