Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. #.rst:
  2. # CheckIncludeFiles
  3. # -----------------
  4. #
  5. # Provides a macro to check if a list of one or more header files can
  6. # be included together in ``C``.
  7. #
  8. # .. command:: CHECK_INCLUDE_FILES
  9. #
  10. # ::
  11. #
  12. # CHECK_INCLUDE_FILES("<includes>" <variable>)
  13. #
  14. # Check if the given ``<includes>`` list may be included together
  15. # in a ``C`` source file and store the result in an internal cache
  16. # entry named ``<variable>``. Specify the ``<includes>`` argument
  17. # as a :ref:`;-list <CMake Language Lists>` of header file names.
  18. #
  19. # The following variables may be set before calling this macro to modify
  20. # the way the check is run:
  21. #
  22. # ``CMAKE_REQUIRED_FLAGS``
  23. # string of compile command line flags
  24. # ``CMAKE_REQUIRED_DEFINITIONS``
  25. # list of macros to define (-DFOO=bar)
  26. # ``CMAKE_REQUIRED_INCLUDES``
  27. # list of include directories
  28. # ``CMAKE_REQUIRED_QUIET``
  29. # execute quietly without messages
  30. #
  31. # See modules :module:`CheckIncludeFile` and :module:`CheckIncludeFileCXX`
  32. # to check for a single header file in ``C`` or ``CXX`` languages.
  33.  
  34. #=============================================================================
  35. # Copyright 2003-2012 Kitware, Inc.
  36. #
  37. # Distributed under the OSI-approved BSD License (the "License");
  38. # see accompanying file Copyright.txt for details.
  39. #
  40. # This software is distributed WITHOUT ANY WARRANTY; without even the
  41. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  42. # See the License for more information.
  43. #=============================================================================
  44. # (To distribute this file outside of CMake, substitute the full
  45. # License text for the above reference.)
  46.  
  47. macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
  48. if(NOT DEFINED "${VARIABLE}")
  49. set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
  50. if(CMAKE_REQUIRED_INCLUDES)
  51. set(CHECK_INCLUDE_FILES_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
  52. else()
  53. set(CHECK_INCLUDE_FILES_INCLUDE_DIRS)
  54. endif()
  55. set(CHECK_INCLUDE_FILES_CONTENT "/* */\n")
  56. set(MACRO_CHECK_INCLUDE_FILES_FLAGS ${CMAKE_REQUIRED_FLAGS})
  57. foreach(FILE ${INCLUDE})
  58. set(CMAKE_CONFIGURABLE_FILE_CONTENT
  59. "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
  60. endforeach()
  61. set(CMAKE_CONFIGURABLE_FILE_CONTENT
  62. "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n\nint main(void){return 0;}\n")
  63. configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
  64. "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c" @ONLY)
  65.  
  66. set(_INCLUDE ${INCLUDE}) # remove empty elements
  67. if("${_INCLUDE}" MATCHES "^([^;]+);.+;([^;]+)$")
  68. list(LENGTH _INCLUDE _INCLUDE_LEN)
  69. set(_description "${_INCLUDE_LEN} include files ${CMAKE_MATCH_1}, ..., ${CMAKE_MATCH_2}")
  70. elseif("${_INCLUDE}" MATCHES "^([^;]+);([^;]+)$")
  71. set(_description "include files ${CMAKE_MATCH_1}, ${CMAKE_MATCH_2}")
  72. else()
  73. set(_description "include file ${_INCLUDE}")
  74. endif()
  75.  
  76. if(NOT CMAKE_REQUIRED_QUIET)
  77. message(STATUS "Looking for ${_description}")
  78. endif()
  79. try_compile(${VARIABLE}
  80. ${CMAKE_BINARY_DIR}
  81. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c
  82. COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
  83. CMAKE_FLAGS
  84. -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_FLAGS}
  85. "${CHECK_INCLUDE_FILES_INCLUDE_DIRS}"
  86. OUTPUT_VARIABLE OUTPUT)
  87. if(${VARIABLE})
  88. if(NOT CMAKE_REQUIRED_QUIET)
  89. message(STATUS "Looking for ${_description} - found")
  90. endif()
  91. set(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}")
  92. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  93. "Determining if files ${INCLUDE} "
  94. "exist passed with the following output:\n"
  95. "${OUTPUT}\n\n")
  96. else()
  97. if(NOT CMAKE_REQUIRED_QUIET)
  98. message(STATUS "Looking for ${_description} - not found")
  99. endif()
  100. set(${VARIABLE} "" CACHE INTERNAL "Have includes ${INCLUDE}")
  101. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  102. "Determining if files ${INCLUDE} "
  103. "exist failed with the following output:\n"
  104. "${OUTPUT}\nSource:\n${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
  105. endif()
  106. endif()
  107. endmacro()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement