CheckIncludeFileCXX.cmake 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. # CMAKE_REQUIRED_QUIET = execute quietly without messages
  32. #=============================================================================
  33. # Copyright 2002-2009 Kitware, Inc.
  34. #
  35. # Distributed under the OSI-approved BSD License (the "License");
  36. # see accompanying file Copyright.txt for details.
  37. #
  38. # This software is distributed WITHOUT ANY WARRANTY; without even the
  39. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  40. # See the License for more information.
  41. #=============================================================================
  42. # (To distribute this file outside of CMake, substitute the full
  43. # License text for the above reference.)
  44. macro(CHECK_INCLUDE_FILE_CXX INCLUDE VARIABLE)
  45. if(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
  46. if(CMAKE_REQUIRED_INCLUDES)
  47. set(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
  48. else()
  49. set(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS)
  50. endif()
  51. set(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
  52. set(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
  53. configure_file(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in
  54. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx)
  55. if(NOT CMAKE_REQUIRED_QUIET)
  56. message(STATUS "Looking for C++ include ${INCLUDE}")
  57. endif()
  58. if(${ARGC} EQUAL 3)
  59. set(CMAKE_CXX_FLAGS_SAVE ${CMAKE_CXX_FLAGS})
  60. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARGV2}")
  61. endif()
  62. try_compile(${VARIABLE}
  63. ${CMAKE_BINARY_DIR}
  64. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx
  65. COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
  66. CMAKE_FLAGS
  67. -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
  68. "${CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS}"
  69. OUTPUT_VARIABLE OUTPUT)
  70. if(${ARGC} EQUAL 3)
  71. set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE})
  72. endif()
  73. if(${VARIABLE})
  74. if(NOT CMAKE_REQUIRED_QUIET)
  75. message(STATUS "Looking for C++ include ${INCLUDE} - found")
  76. endif()
  77. set(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
  78. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  79. "Determining if the include file ${INCLUDE} "
  80. "exists passed with the following output:\n"
  81. "${OUTPUT}\n\n")
  82. else()
  83. if(NOT CMAKE_REQUIRED_QUIET)
  84. message(STATUS "Looking for C++ include ${INCLUDE} - not found")
  85. endif()
  86. set(${VARIABLE} "" CACHE INTERNAL "Have include ${INCLUDE}")
  87. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  88. "Determining if the include file ${INCLUDE} "
  89. "exists failed with the following output:\n"
  90. "${OUTPUT}\n\n")
  91. endif()
  92. endif()
  93. endmacro()