Debian Codegraph @

cmake/TestLargeFiles.cmake

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