Velocities and forces for selections.
[gromacs/qmmm-gamess-us.git] / cmake / gmxTestLargeFiles.cmake
blobda1c0f54fdaace2ae9d9bbd7f59044e5d25c771e
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             MESSAGE(STATUS "Checking for 64-bit off_t - not present")
66         else(NOT FILE64_OK)
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")
76             if(FSEEKO_COMPILE_OK)
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" )
85                 if(FSEEKO_COMPILE_OK)
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)
91         endif(NOT FILE64_OK)
93             if(FSEEKO_COMPILE_OK)
94                 SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
95                 set(HAVE_FSEEKO 1)
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)