TZIVI-254: IVI needs a newer version of cmake
[profile/ivi/cmake.git] / Modules / CheckIncludeFile.cmake
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
9 #
10 # The following variables may be set before calling this macro to
11 # modify the way the check is run:
12 #
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
16 #
17
18 #=============================================================================
19 # Copyright 2002-2009 Kitware, Inc.
20 #
21 # Distributed under the OSI-approved BSD License (the "License");
22 # see accompanying file Copyright.txt for details.
23 #
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.)
30
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}")
43     IF(${ARGC} EQUAL 3)
44       SET(CMAKE_C_FLAGS_SAVE ${CMAKE_C_FLAGS})
45       SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARGV2}")
46     ENDIF(${ARGC} EQUAL 3)
47
48     TRY_COMPILE(${VARIABLE}
49       ${CMAKE_BINARY_DIR}
50       ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c
51       COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
52       CMAKE_FLAGS 
53       -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
54       "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}"
55       OUTPUT_VARIABLE OUTPUT) 
56
57     IF(${ARGC} EQUAL 3)
58       SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_SAVE})
59     ENDIF(${ARGC} EQUAL 3)
60
61     IF(${VARIABLE})
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"
67         "${OUTPUT}\n\n")
68     ELSE(${VARIABLE})
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"
74         "${OUTPUT}\n\n")
75     ENDIF(${VARIABLE})
76   ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
77 ENDMACRO(CHECK_INCLUDE_FILE)