CheckIncludeFileCXX.cmake 2.62 KB
Newer Older
1
# - Check if the include file exists.
2 3 4
#  CHECK_INCLUDE_FILE_CXX(INCLUDE VARIABLE)
#
#  INCLUDE  - name of include file
5 6 7 8
#  VARIABLE - variable to return result
#  
# An optional third argument is the CFlags to add to the compile line 
# or you can use CMAKE_REQUIRED_FLAGS.
9
#
10 11 12 13 14 15 16
# The following variables may be set before calling this macro to
# modify the way the check is run:
#
#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
#  CMAKE_REQUIRED_INCLUDES = list of include directories
#
17
MACRO(CHECK_INCLUDE_FILE_CXX INCLUDE VARIABLE)
18
  IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
19 20 21 22 23
    IF(CMAKE_REQUIRED_INCLUDES)
      SET(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
    ELSE(CMAKE_REQUIRED_INCLUDES)
      SET(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS)
    ENDIF(CMAKE_REQUIRED_INCLUDES)
Andy Cedilnik's avatar
Andy Cedilnik committed
24
    SET(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
25 26
    SET(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
    CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in
27
      ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx IMMEDIATE)
Andy Cedilnik's avatar
Andy Cedilnik committed
28
    MESSAGE(STATUS "Looking for C++ include ${INCLUDE}")
29
    IF(${ARGC} EQUAL 3)
30 31
      SET(CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGV2}")
32
    ENDIF(${ARGC} EQUAL 3)
33

34
    TRY_COMPILE(${VARIABLE}
35
      ${CMAKE_BINARY_DIR}
36
      ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx
37
      COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
Andy Cedilnik's avatar
Andy Cedilnik committed
38 39
      CMAKE_FLAGS 
      -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
40
      "${CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS}"
Andy Cedilnik's avatar
Andy Cedilnik committed
41
      OUTPUT_VARIABLE OUTPUT) 
42

43
    IF(${ARGC} EQUAL 3)
44
      SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE})
45
    ENDIF(${ARGC} EQUAL 3)
46

47
    IF(${VARIABLE})
Andy Cedilnik's avatar
Andy Cedilnik committed
48
      MESSAGE(STATUS "Looking for C++ include ${INCLUDE} - found")
49
      SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
50
      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 
51 52 53
        "Determining if the include file ${INCLUDE} "
        "exists passed with the following output:\n"
        "${OUTPUT}\n\n")
54
    ELSE(${VARIABLE})
Andy Cedilnik's avatar
Andy Cedilnik committed
55
      MESSAGE(STATUS "Looking for C++ include ${INCLUDE} - not found")
56
      SET(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
57
      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 
58 59
        "Determining if the include file ${INCLUDE} "
        "exists failed with the following output:\n"
60
        "${OUTPUT}\n\n")
61 62
    ENDIF(${VARIABLE})
  ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
63
ENDMACRO(CHECK_INCLUDE_FILE_CXX)