CheckIncludeFile.cmake 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #=============================================================================
  18. # Copyright 2002-2009 Kitware, Inc.
  19. #
  20. # Distributed under the OSI-approved BSD License (the "License");
  21. # see accompanying file Copyright.txt for details.
  22. #
  23. # This software is distributed WITHOUT ANY WARRANTY; without even the
  24. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  25. # See the License for more information.
  26. #=============================================================================
  27. # (To distribute this file outside of CMake, substitute the full
  28. # License text for the above reference.)
  29. MACRO(CHECK_INCLUDE_FILE INCLUDE VARIABLE)
  30. IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
  31. IF(CMAKE_REQUIRED_INCLUDES)
  32. SET(CHECK_INCLUDE_FILE_C_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
  33. ELSE(CMAKE_REQUIRED_INCLUDES)
  34. SET(CHECK_INCLUDE_FILE_C_INCLUDE_DIRS)
  35. ENDIF(CMAKE_REQUIRED_INCLUDES)
  36. SET(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
  37. SET(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
  38. CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CheckIncludeFile.c.in
  39. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c IMMEDIATE)
  40. MESSAGE(STATUS "Looking for ${INCLUDE}")
  41. IF(${ARGC} EQUAL 3)
  42. SET(CMAKE_C_FLAGS_SAVE ${CMAKE_C_FLAGS})
  43. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARGV2}")
  44. ENDIF(${ARGC} EQUAL 3)
  45. TRY_COMPILE(${VARIABLE}
  46. ${CMAKE_BINARY_DIR}
  47. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c
  48. COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
  49. CMAKE_FLAGS
  50. -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
  51. "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}"
  52. OUTPUT_VARIABLE OUTPUT)
  53. IF(${ARGC} EQUAL 3)
  54. SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_SAVE})
  55. ENDIF(${ARGC} EQUAL 3)
  56. IF(${VARIABLE})
  57. MESSAGE(STATUS "Looking for ${INCLUDE} - found")
  58. SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
  59. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  60. "Determining if the include file ${INCLUDE} "
  61. "exists passed with the following output:\n"
  62. "${OUTPUT}\n\n")
  63. ELSE(${VARIABLE})
  64. MESSAGE(STATUS "Looking for ${INCLUDE} - not found")
  65. SET(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
  66. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  67. "Determining if the include file ${INCLUDE} "
  68. "exists failed with the following output:\n"
  69. "${OUTPUT}\n\n")
  70. ENDIF(${VARIABLE})
  71. ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
  72. ENDMACRO(CHECK_INCLUDE_FILE)