Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / CheckIncludeFileCXX.cmake
1 # - Check if the include file exists.
2 #  CHECK_INCLUDE_FILE_CXX(INCLUDE VARIABLE)
3 #
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_CXX INCLUDE VARIABLE)
32   if("${VARIABLE}" MATCHES "^${VARIABLE}$")
33     if(CMAKE_REQUIRED_INCLUDES)
34       set(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
35     else()
36       set(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS)
37     endif()
38     set(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
39     set(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
40     configure_file(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in
41       ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx IMMEDIATE)
42     message(STATUS "Looking for C++ include ${INCLUDE}")
43     if(${ARGC} EQUAL 3)
44       set(CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
45       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGV2}")
46     endif()
47
48     try_compile(${VARIABLE}
49       ${CMAKE_BINARY_DIR}
50       ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx
51       COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
52       CMAKE_FLAGS
53       -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
54       "${CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS}"
55       OUTPUT_VARIABLE OUTPUT)
56
57     if(${ARGC} EQUAL 3)
58       set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE})
59     endif()
60
61     if(${VARIABLE})
62       message(STATUS "Looking for C++ include ${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()
69       message(STATUS "Looking for C++ include ${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()
76   endif()
77 endmacro()