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
12 # However, it is YOUR job to make sure these defines are set in a cmakedefine so they
13 # end up in a config.h file that is included in your source if necessary!
15 MACRO(GMX_TEST_LARGE_FILES VARIABLE)
16 IF(NOT DEFINED ${VARIABLE})
18 # On most platforms it is probably overkill to first test the flags for 64-bit off_t,
19 # and then separately fseeko. However, in the future we might have 128-bit filesystems
20 # (ZFS), so it might be dangerous to indiscriminately set e.g. _FILE_OFFSET_BITS=64.
22 MESSAGE(STATUS "Checking for 64-bit off_t")
24 # First check without any special flags
25 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
26 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c")
28 MESSAGE(STATUS "Checking for 64-bit off_t - present")
32 # Test with _FILE_OFFSET_BITS=64
33 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
34 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
35 COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64" )
37 MESSAGE(STATUS "Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64")
38 set(_FILE_OFFSET_BITS 64)
43 # Test with _LARGE_FILES
44 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
45 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
46 COMPILE_DEFINITIONS "-D_LARGE_FILES" )
48 MESSAGE(STATUS "Checking for 64-bit off_t - present with _LARGE_FILES")
54 # Test with _LARGEFILE_SOURCE
55 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
56 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
57 COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
59 MESSAGE(STATUS "Checking for 64-bit off_t - present with _LARGEFILE_SOURCE")
60 set(_LARGEFILE_SOURCE 1)
65 # now check for Windows stuff
66 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
67 "${CMAKE_SOURCE_DIR}/cmake/TestWindowsFSeek.c")
69 MESSAGE(STATUS "Checking for 64-bit off_t - present with _fseeki64")
75 MESSAGE(STATUS "Checking for 64-bit off_t - not present")
78 # Set the flags we might have determined to be required above
79 configure_file("${CMAKE_SOURCE_DIR}/cmake/TestLargeFiles.c.cmakein"
80 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
82 MESSAGE(STATUS "Checking for fseeko/ftello")
83 # Test if ftello/fseeko are available
84 TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
85 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
87 MESSAGE(STATUS "Checking for fseeko/ftello - present")
88 endif(FSEEKO_COMPILE_OK)
90 if(NOT FSEEKO_COMPILE_OK)
91 # glibc 2.2 neds _LARGEFILE_SOURCE for fseeko (but not 64-bit off_t...)
92 TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
93 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c"
94 COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
96 MESSAGE(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE")
97 set(_LARGEFILE_SOURCE 1)
98 endif(FSEEKO_COMPILE_OK)
99 endif(NOT FSEEKO_COMPILE_OK)
103 if(FSEEKO_COMPILE_OK)
104 SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
106 else(FSEEKO_COMPILE_OK)
108 SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
109 SET(HAVE__FSEEKI64 1 CACHE INTERNAL "Windows 64-bit fseek" FORCE)
110 else (HAVE__FSEEKI64)
111 MESSAGE(STATUS "Checking for fseeko/ftello - not found")
112 SET(${VARIABLE} 0 CACHE INTERNAL "Result of test for large file support" FORCE)
113 endif (HAVE__FSEEKI64)
114 endif(FSEEKO_COMPILE_OK)
116 ENDIF(NOT DEFINED ${VARIABLE})
117 ENDMACRO(GMX_TEST_LARGE_FILES VARIABLE)