TestLargeFiles.cmake 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. include (CheckIncludeFile)
  2. include (CheckTypeSize)
  3. include (CMakePushCheckState)
  4. macro (TEST_LARGE_FILES VARIABLE)
  5. if (NOT DEFINED ${VARIABLE})
  6. cmake_push_check_state()
  7. message (STATUS "")
  8. message (STATUS "")
  9. message (STATUS "Checking large files support...")
  10. if (WIN32)
  11. set (${VARIABLE} 1 CACHE INTERNAL "Result of tests for large file support" FORCE)
  12. message (STATUS "")
  13. message (STATUS "Result of checking large files support: supported with WinAPI")
  14. else ()
  15. message (STATUS "")
  16. check_include_file(sys/types.h HAVE_SYS_TYPES_H)
  17. check_include_file(stdint.h HAVE_STDINT_H)
  18. check_include_file(stddef.h HAVE_STDDEF_H)
  19. message (STATUS "")
  20. message (STATUS "Checking size of off_t without any definitions:")
  21. check_type_size (off_t SIZEOF_OFF_T)
  22. message (STATUS "Checking of off_t without any definitions: ${SIZEOF_OFF_T}")
  23. if (SIZEOF_OFF_T EQUAL 8)
  24. set (LARGE_FILES_DEFINITIONS "" CACHE INTERNAL "64-bit off_t required definitions")
  25. set (FILE64 TRUE)
  26. else ()
  27. unset (HAVE_SIZEOF_OFF_T CACHE)
  28. unset (SIZEOF_OFF_T CACHE)
  29. unset (SIZEOF_OFF_T_CODE CACHE)
  30. cmake_pop_check_state()
  31. set (FILE64 FALSE)
  32. endif ()
  33. if (NOT FILE64)
  34. set (CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} /D_FILE_OFFSET_BITS=64)
  35. message (STATUS "")
  36. message (STATUS "Checking size of off_t with _FILE_OFFSET_BITS=64:")
  37. check_type_size (off_t SIZEOF_OFF_T)
  38. message (STATUS "Checking size of off_t with _FILE_OFFSET_BITS=64: ${SIZEOF_OFF_T}")
  39. if (SIZEOF_OFF_T EQUAL 8)
  40. set (_FILE_OFFSET_BITS 64 CACHE INTERNAL "")
  41. set (_FILE_OFFSET_BITS_CODE "#define _FILE_OFFSET_BITS 64" CACHE INTERNAL "")
  42. set (LARGE_FILES_DEFINITIONS ${LARGE_FILES_DEFINITIONS} "/D_FILE_OFFSET_BITS=64" CACHE INTERNAL "64-bit off_t required definitions")
  43. set (FILE64 TRUE)
  44. else ()
  45. set (_FILE_OFFSET_BITS_CODE "" CACHE INTERNAL "")
  46. unset (HAVE_SIZEOF_OFF_T CACHE)
  47. unset (SIZEOF_OFF_T CACHE)
  48. unset (SIZEOF_OFF_T_CODE CACHE)
  49. cmake_pop_check_state()
  50. set (FILE64 FALSE)
  51. endif ()
  52. endif ()
  53. if (NOT FILE64)
  54. set (CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} /D_LARGE_FILES)
  55. message (STATUS "")
  56. message (STATUS "Checking size of off_t with _LARGE_FILES:")
  57. check_type_size (off_t SIZEOF_OFF_T)
  58. message (STATUS "Checking size of off_t with _LARGE_FILES: ${SIZEOF_OFF_T}")
  59. if (SIZEOF_OFF_T EQUAL 8)
  60. set (_LARGE_FILES 1 CACHE INTERNAL "")
  61. set (LARGE_FILES_DEFINITIONS ${LARGE_FILES_DEFINITIONS} "/D_LARGE_FILES" CACHE INTERNAL "64-bit off_t required definitions")
  62. set (FILE64 TRUE)
  63. else ()
  64. unset (HAVE_SIZEOF_OFF_T CACHE)
  65. unset (SIZEOF_OFF_T CACHE)
  66. unset (SIZEOF_OFF_T_CODE CACHE)
  67. cmake_pop_check_state()
  68. set (FILE64 FALSE)
  69. endif ()
  70. endif ()
  71. if (NOT FILE64)
  72. set (CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} /D_LARGEFILE_SOURCE)
  73. unset (HAVE_SIZEOF_OFF_T CACHE)
  74. unset (SIZEOF_OFF_T CACHE)
  75. unset (SIZEOF_OFF_T_CODE CACHE)
  76. message (STATUS "")
  77. message (STATUS "Checking size of off_t with _LARGEFILE_SOURCE:")
  78. check_type_size (off_t SIZEOF_OFF_T)
  79. message (STATUS "Checking size of off_t with _LARGEFILE_SOURCE: ${SIZEOF_OFF_T}")
  80. if (SIZEOF_OFF_T EQUAL 8)
  81. set (_LARGEFILE_SOURCE 1 CACHE INTERNAL "")
  82. set (LARGE_FILES_DEFINITIONS ${LARGE_FILES_DEFINITIONS} "/D_LARGEFILE_SOURCE" CACHE INTERNAL "64-bit off_t required definitions")
  83. set (FILE64 TRUE)
  84. else ()
  85. cmake_pop_check_state()
  86. set (FILE64 FALSE)
  87. endif ()
  88. endif ()
  89. message (STATUS "")
  90. if (FILE64)
  91. set (${VARIABLE} 1 CACHE INTERNAL "Result of tests for large file support" FORCE)
  92. if (NOT SIZEOF_OFF_T_REQURED_DEFINITIONS)
  93. message (STATUS "Result of checking large files support: supported")
  94. else ()
  95. message (STATUS "Result of checking large files support: supported with ${LARGE_FILES_DEFINITIONS}")
  96. message (STATUS "Add LARGE_FILES_DEFINITIONS to your compiler definitions or configure with _FILE_OFFSET_BITS,")
  97. message (STATUS "_FILE_OFFSET_BITS_CODE, _LARGE_FILES and _LARGEFILE_SOURCE variables.")
  98. endif ()
  99. else ()
  100. message ("Result of checking large files support: not supported")
  101. set (${VARIABLE} 0 CACHE INTERNAL "Result of test for large file support" FORCE)
  102. endif ()
  103. message ("")
  104. message ("")
  105. endif ()
  106. endif (NOT DEFINED ${VARIABLE})
  107. endmacro (TEST_LARGE_FILES VARIABLE)