CheckIncludeFileCXX.cmake 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #.rst:
  2. # CheckIncludeFileCXX
  3. # -------------------
  4. #
  5. # Check if the include file exists.
  6. #
  7. # ::
  8. #
  9. # CHECK_INCLUDE_FILE_CXX(INCLUDE VARIABLE)
  10. #
  11. #
  12. #
  13. # ::
  14. #
  15. # INCLUDE - name of include file
  16. # VARIABLE - variable to return result
  17. #
  18. #
  19. #
  20. # An optional third argument is the CFlags to add to the compile line or
  21. # you can use CMAKE_REQUIRED_FLAGS.
  22. #
  23. # The following variables may be set before calling this macro to modify
  24. # the way the check is run:
  25. #
  26. # ::
  27. #
  28. # CMAKE_REQUIRED_FLAGS = string of compile command line flags
  29. # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
  30. # CMAKE_REQUIRED_INCLUDES = list of include directories
  31. #=============================================================================
  32. # Copyright 2002-2009 Kitware, Inc.
  33. #
  34. # Distributed under the OSI-approved BSD License (the "License");
  35. # see accompanying file Copyright.txt for details.
  36. #
  37. # This software is distributed WITHOUT ANY WARRANTY; without even the
  38. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  39. # See the License for more information.
  40. #=============================================================================
  41. # (To distribute this file outside of CMake, substitute the full
  42. # License text for the above reference.)
  43. macro(CHECK_INCLUDE_FILE_CXX INCLUDE VARIABLE)
  44. if("${VARIABLE}" MATCHES "^${VARIABLE}$")
  45. if(CMAKE_REQUIRED_INCLUDES)
  46. set(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
  47. else()
  48. set(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS)
  49. endif()
  50. set(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
  51. set(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
  52. configure_file(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in
  53. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx)
  54. message(STATUS "Looking for C++ include ${INCLUDE}")
  55. if(${ARGC} EQUAL 3)
  56. set(CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
  57. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGV2}")
  58. endif()
  59. try_compile(${VARIABLE}
  60. ${CMAKE_BINARY_DIR}
  61. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx
  62. COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
  63. CMAKE_FLAGS
  64. -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
  65. "${CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS}"
  66. OUTPUT_VARIABLE OUTPUT)
  67. if(${ARGC} EQUAL 3)
  68. set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE})
  69. endif()
  70. if(${VARIABLE})
  71. message(STATUS "Looking for C++ include ${INCLUDE} - found")
  72. set(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
  73. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  74. "Determining if the include file ${INCLUDE} "
  75. "exists passed with the following output:\n"
  76. "${OUTPUT}\n\n")
  77. else()
  78. message(STATUS "Looking for C++ include ${INCLUDE} - not found")
  79. set(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
  80. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  81. "Determining if the include file ${INCLUDE} "
  82. "exists failed with the following output:\n"
  83. "${OUTPUT}\n\n")
  84. endif()
  85. endif()
  86. endmacro()