1 # - Define macro to check large file support
3 # GMX_TEST_LARGE_FILES(VARIABLE)
5 # VARIABLE will be set to true if off_t is 64 bits, and fseeko/ftello present.
6 # This macro will also set defines necessary enable large file support, for instance
11 # However, it is YOUR job to make sure these defines are set in a cmakedefine so they
12 # end up in a config.h file that is included in your source if necessary!
14 MACRO(GMX_TEST_LARGE_FILES VARIABLE)
15 IF(NOT DEFINED ${VARIABLE})
17 # On most platforms it is probably overkill to first test the flags for 64-bit off_t,
18 # and then separately fseeko. However, in the future we might have 128-bit filesystems
19 # (ZFS), so it might be dangerous to indiscriminately set e.g. _FILE_OFFSET_BITS=64.
21 MESSAGE(STATUS "Checking for 64-bit off_t")
23 # First check without any special flags
24 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
25 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c")
27 MESSAGE(STATUS "Checking for 64-bit off_t - present")
31 # Test with _FILE_OFFSET_BITS=64
32 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
33 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
34 COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64" )
36 MESSAGE(STATUS "Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64")
37 set(_FILE_OFFSET_BITS 64 CACHE INTERNAL "64-bit off_t requires _FILE_OFFSET_BITS=64")
42 # Test with _LARGE_FILES
43 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
44 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
45 COMPILE_DEFINITIONS "-D_LARGE_FILES" )
47 MESSAGE(STATUS "Checking for 64-bit off_t - present with _LARGE_FILES")
48 set(_LARGE_FILES 1 CACHE INTERNAL "64-bit off_t requires _LARGE_FILES")
53 # Test with _LARGEFILE_SOURCE
54 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
55 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
56 COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
58 MESSAGE(STATUS "Checking for 64-bit off_t - present with _LARGEFILE_SOURCE")
59 set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit off_t requires _LARGEFILE_SOURCE")
64 # now check for Windows stuff
65 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
66 "${CMAKE_SOURCE_DIR}/cmake/TestWindowsFSeek.c")
68 MESSAGE(STATUS "Checking for 64-bit off_t - present with _fseeki64")
69 set(HAVE__FSEEKI64 1 CACHE INTERNAL "64-bit off_t requires _fseeki64")
74 MESSAGE(STATUS "Checking for 64-bit off_t - not present")
77 # Set the flags we might have determined to be required above
78 configure_file("${CMAKE_SOURCE_DIR}/cmake/TestLargeFiles.c.cmakein"
79 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
81 MESSAGE(STATUS "Checking for fseeko/ftello")
82 # Test if ftello/fseeko are available
83 TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
84 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
86 MESSAGE(STATUS "Checking for fseeko/ftello - present")
87 endif(FSEEKO_COMPILE_OK)
89 if(NOT FSEEKO_COMPILE_OK)
90 # glibc 2.2 neds _LARGEFILE_SOURCE for fseeko (but not 64-bit off_t...)
91 TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
92 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c"
93 COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
95 MESSAGE(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE")
96 set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit fseeko requires _LARGEFILE_SOURCE")
97 endif(FSEEKO_COMPILE_OK)
98 endif(NOT FSEEKO_COMPILE_OK)
102 if(FSEEKO_COMPILE_OK)
103 SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
104 set(HAVE_FSEEKO 1 CACHE INTERNAL "64bit fseeko is available" FORCE)
105 else(FSEEKO_COMPILE_OK)
107 SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
108 SET(HAVE__FSEEKI64 1 CACHE INTERNAL "Windows 64-bit fseek" FORCE)
109 else (HAVE__FSEEKI64)
110 MESSAGE(STATUS "Checking for fseeko/ftello - not found")
111 SET(${VARIABLE} 0 CACHE INTERNAL "Result of test for large file support" FORCE)
112 endif (HAVE__FSEEKI64)
113 endif(FSEEKO_COMPILE_OK)
115 ENDIF(NOT DEFINED ${VARIABLE})
116 ENDMACRO(GMX_TEST_LARGE_FILES VARIABLE)