1 # - Check if the include file exists.
2 # CHECK_INCLUDE_FILE_CXX(INCLUDE VARIABLE)
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_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}")
36 set(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS)
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}")
44 set(CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
45 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGV2}")
48 try_compile(${VARIABLE}
50 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx
51 COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
53 -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
54 "${CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS}"
55 OUTPUT_VARIABLE OUTPUT)
58 set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE})
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"
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"