CheckIncludeFileCXX.cmake 3.4 KB

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