CheckIncludeFileCXX.cmake 1.94 KB
Newer Older
1 2 3 4 5 6
#
# Check if the include file exists.
#
# CHECK_INCLUDE_FILE - macro which checks the include file exists.
# INCLUDE - name of include file
# VARIABLE - variable to return result
Ken Martin's avatar
Ken Martin committed
7
#
Andy Cedilnik's avatar
Andy Cedilnik committed
8 9
# an optional third argument is the CFlags to add to the compile line 
# or you can use CMAKE_REQUIRED_FLAGS
10 11
#
MACRO(CHECK_INCLUDE_FILE_CXX INCLUDE VARIABLE)
12
  IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
Andy Cedilnik's avatar
Andy Cedilnik committed
13
    SET(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
14 15
    SET(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
    CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in
16
      ${CMAKE_BINARY_DIR}/CMakeTmp/CheckIncludeFile.cxx IMMEDIATE)
Andy Cedilnik's avatar
Andy Cedilnik committed
17
    MESSAGE(STATUS "Looking for C++ include ${INCLUDE}")
18
    IF(${ARGC} EQUAL 3)
19 20
      SET(CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
      SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGV2}")
21
    ENDIF(${ARGC} EQUAL 3)
22

23
    TRY_COMPILE(${VARIABLE}
24 25
      ${CMAKE_BINARY_DIR}
      ${CMAKE_BINARY_DIR}/CMakeTmp/CheckIncludeFile.cxx
Andy Cedilnik's avatar
Andy Cedilnik committed
26 27 28
      CMAKE_FLAGS 
      -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
      OUTPUT_VARIABLE OUTPUT) 
29

30
    IF(${ARGC} EQUAL 3)
31
      SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE})
32
    ENDIF(${ARGC} EQUAL 3)
33

34
    IF(${VARIABLE})
Andy Cedilnik's avatar
Andy Cedilnik committed
35
      MESSAGE(STATUS "Looking for C++ include ${INCLUDE} - found")
36
      SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
37
      FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeOutput.log 
38 39 40
        "Determining if the include file ${INCLUDE} "
        "exists passed with the following output:\n"
        "${OUTPUT}\n\n")
41
    ELSE(${VARIABLE})
Andy Cedilnik's avatar
Andy Cedilnik committed
42
      MESSAGE(STATUS "Looking for C++ include ${INCLUDE} - not found")
43
      SET(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
44
      FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeError.log 
45 46
        "Determining if the include file ${INCLUDE} "
        "exists failed with the following output:\n"
47
        "${OUTPUT}\n\n")
48 49
    ENDIF(${VARIABLE})
  ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
50
ENDMACRO(CHECK_INCLUDE_FILE_CXX)