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