fixed incorrect pdb2gmx output with multiple (altloc) atom entries in specbonds
[gromacs.git] / cmake / gmxTestLargeFiles.cmake
blob5a97bed65ec59ae8c0d69117816c2975da001f2e
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
7 #  _LARGE_FILES
8 #  _LARGEFILE_SOURCE
9 #  _FILE_OFFSET_BITS 64  
10 #  HAVE_FSEEKO
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")
27         if(FILE64_OK)
28             MESSAGE(STATUS "Checking for 64-bit off_t - present")                       
29         endif(FILE64_OK)
31         if(NOT FILE64_OK)       
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" )
36             if(FILE64_OK)
37                 MESSAGE(STATUS "Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64")
38                 set(_FILE_OFFSET_BITS 64)
39             endif(FILE64_OK)
40         endif(NOT FILE64_OK)    
42         if(NOT FILE64_OK)
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" )
47             if(FILE64_OK)
48                 MESSAGE(STATUS "Checking for 64-bit off_t - present with _LARGE_FILES")
49                 set(_LARGE_FILES 1)
50             endif(FILE64_OK)
51         endif(NOT FILE64_OK)
52         
53         if(NOT FILE64_OK)
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" )
58             if(FILE64_OK)
59                 MESSAGE(STATUS "Checking for 64-bit off_t - present with _LARGEFILE_SOURCE")
60                                set(_LARGEFILE_SOURCE 1)
61             endif(FILE64_OK)
62         endif(NOT FILE64_OK)
64         if(NOT FILE64_OK)
65             # now check for Windows stuff
66             TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
67                         "${CMAKE_SOURCE_DIR}/cmake/TestWindowsFSeek.c")
68             if(FILE64_OK)
69                 MESSAGE(STATUS "Checking for 64-bit off_t - present with _fseeki64")
70                 set(HAVE__FSEEKI64 1)
71             endif(FILE64_OK)
72         endif(NOT FILE64_OK)
74         if(NOT FILE64_OK)
75             MESSAGE(STATUS "Checking for 64-bit off_t - not present")
76         else(NOT FILE64_OK)
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")
86             if(FSEEKO_COMPILE_OK)
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" )
95                 if(FSEEKO_COMPILE_OK)
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)
101         endif(NOT FILE64_OK)
103             if(FSEEKO_COMPILE_OK)
104                 SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
105                 set(HAVE_FSEEKO 1)
106         else(FSEEKO_COMPILE_OK)
107                         if (HAVE__FSEEKI64)
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)