CheckIncludeFile.cmake 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. MACRO(CHECK_INCLUDE_FILE INCLUDE VARIABLE)
  18. IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
  19. IF(CMAKE_REQUIRED_INCLUDES)
  20. SET(CHECK_INCLUDE_FILE_C_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
  21. ELSE(CMAKE_REQUIRED_INCLUDES)
  22. SET(CHECK_INCLUDE_FILE_C_INCLUDE_DIRS)
  23. ENDIF(CMAKE_REQUIRED_INCLUDES)
  24. SET(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
  25. SET(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
  26. CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CheckIncludeFile.c.in
  27. ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckIncludeFile.c IMMEDIATE)
  28. MESSAGE(STATUS "Looking for ${INCLUDE}")
  29. IF(${ARGC} EQUAL 3)
  30. SET(CMAKE_C_FLAGS_SAVE ${CMAKE_C_FLAGS})
  31. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARGV2}")
  32. ENDIF(${ARGC} EQUAL 3)
  33. TRY_COMPILE(${VARIABLE}
  34. ${CMAKE_BINARY_DIR}
  35. ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckIncludeFile.c
  36. COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
  37. CMAKE_FLAGS
  38. -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
  39. "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}"
  40. OUTPUT_VARIABLE OUTPUT)
  41. IF(${ARGC} EQUAL 3)
  42. SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_SAVE})
  43. ENDIF(${ARGC} EQUAL 3)
  44. IF(${VARIABLE})
  45. MESSAGE(STATUS "Looking for ${INCLUDE} - found")
  46. SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
  47. FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeOutput.log
  48. "Determining if the include file ${INCLUDE} "
  49. "exists passed with the following output:\n"
  50. "${OUTPUT}\n\n")
  51. ELSE(${VARIABLE})
  52. MESSAGE(STATUS "Looking for ${INCLUDE} - not found")
  53. SET(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
  54. FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeError.log
  55. "Determining if the include file ${INCLUDE} "
  56. "exists failed with the following output:\n"
  57. "${OUTPUT}\n\n")
  58. ENDIF(${VARIABLE})
  59. ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
  60. ENDMACRO(CHECK_INCLUDE_FILE)