CheckIncludeFiles.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # - Check if the files can be included
  2. #
  3. # CHECK_INCLUDE_FILES(INCLUDE VARIABLE)
  4. #
  5. # INCLUDE - list of files to include
  6. # VARIABLE - variable to return result
  7. #
  8. # The following variables may be set before calling this macro to
  9. # modify the way the check is run:
  10. #
  11. # CMAKE_REQUIRED_FLAGS = string of compile command line flags
  12. # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
  13. # CMAKE_REQUIRED_INCLUDES = list of include directories
  14. #=============================================================================
  15. # Copyright 2003-2009 Kitware, Inc.
  16. #
  17. # Distributed under the OSI-approved BSD License (the "License");
  18. # see accompanying file Copyright.txt for details.
  19. #
  20. # This software is distributed WITHOUT ANY WARRANTY; without even the
  21. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. # See the License for more information.
  23. #=============================================================================
  24. # (To distribute this file outside of CMake, substitute the full
  25. # License text for the above reference.)
  26. MACRO(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
  27. IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
  28. SET(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
  29. IF(CMAKE_REQUIRED_INCLUDES)
  30. SET(CHECK_INCLUDE_FILES_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
  31. ELSE(CMAKE_REQUIRED_INCLUDES)
  32. SET(CHECK_INCLUDE_FILES_INCLUDE_DIRS)
  33. ENDIF(CMAKE_REQUIRED_INCLUDES)
  34. SET(CHECK_INCLUDE_FILES_CONTENT "/* */\n")
  35. SET(MACRO_CHECK_INCLUDE_FILES_FLAGS ${CMAKE_REQUIRED_FLAGS})
  36. FOREACH(FILE ${INCLUDE})
  37. SET(CMAKE_CONFIGURABLE_FILE_CONTENT
  38. "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
  39. ENDFOREACH(FILE)
  40. SET(CMAKE_CONFIGURABLE_FILE_CONTENT
  41. "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n\nint main(){return 0;}\n")
  42. CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
  43. "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c" @ONLY IMMEDIATE)
  44. MESSAGE(STATUS "Looking for include files ${INCLUDE}")
  45. TRY_COMPILE(${VARIABLE}
  46. ${CMAKE_BINARY_DIR}
  47. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c
  48. COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
  49. CMAKE_FLAGS
  50. -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_FLAGS}
  51. "${CHECK_INCLUDE_FILES_INCLUDE_DIRS}"
  52. OUTPUT_VARIABLE OUTPUT)
  53. IF(${VARIABLE})
  54. MESSAGE(STATUS "Looking for include files ${INCLUDE} - found")
  55. SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
  56. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  57. "Determining if files ${INCLUDE} "
  58. "exist passed with the following output:\n"
  59. "${OUTPUT}\n\n")
  60. ELSE(${VARIABLE})
  61. MESSAGE(STATUS "Looking for include files ${INCLUDE} - not found.")
  62. SET(${VARIABLE} "" CACHE INTERNAL "Have includes ${INCLUDE}")
  63. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  64. "Determining if files ${INCLUDE} "
  65. "exist failed with the following output:\n"
  66. "${OUTPUT}\nSource:\n${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
  67. ENDIF(${VARIABLE})
  68. ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
  69. ENDMACRO(CHECK_INCLUDE_FILES)