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 MESSAGE(STATUS "Checking for 64-bit off_t - not present")
68 # Set the flags we might have determined to be required above
69 configure_file("${CMAKE_SOURCE_DIR}/cmake/TestLargeFiles.c.cmakein"
70 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
72 MESSAGE(STATUS "Checking for fseeko/ftello")
73 # Test if ftello/fseeko are available
74 TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
75 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
77 MESSAGE(STATUS "Checking for fseeko/ftello - present")
78 endif(FSEEKO_COMPILE_OK)
80 if(NOT FSEEKO_COMPILE_OK)
81 # glibc 2.2 neds _LARGEFILE_SOURCE for fseeko (but not 64-bit off_t...)
82 TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
83 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c"
84 COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
86 MESSAGE(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE")
87 set(_LARGEFILE_SOURCE 1)
88 endif(FSEEKO_COMPILE_OK)
89 endif(NOT FSEEKO_COMPILE_OK)
94 SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
96 else(FSEEKO_COMPILE_OK)
97 MESSAGE(STATUS "Checking for fseeko/ftello - not found")
98 SET(${VARIABLE} 0 CACHE INTERNAL "Result of test for large file support" FORCE)
99 endif(FSEEKO_COMPILE_OK)
101 ENDIF(NOT DEFINED ${VARIABLE})
102 ENDMACRO(GMX_TEST_LARGE_FILES VARIABLE)