2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2012,2013, by the GROMACS development team, led by
5 # David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 # others, as listed in the AUTHORS file in the top-level source
7 # directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 # - Define macro to check large file support
37 # GMX_TEST_LARGE_FILES(VARIABLE)
39 # VARIABLE will be set to true if off_t is 64 bits, and fseeko/ftello present.
40 # This macro will also set defines necessary enable large file support, for instance
43 # _FILE_OFFSET_BITS 64
45 # However, it is YOUR job to make sure these defines are set in a cmakedefine so they
46 # end up in a config.h file that is included in your source if necessary!
48 MACRO(GMX_TEST_LARGE_FILES VARIABLE)
49 IF(NOT DEFINED ${VARIABLE})
51 # On most platforms it is probably overkill to first test the flags for 64-bit off_t,
52 # and then separately fseeko. However, in the future we might have 128-bit filesystems
53 # (ZFS), so it might be dangerous to indiscriminately set e.g. _FILE_OFFSET_BITS=64.
55 MESSAGE(STATUS "Checking for 64-bit off_t")
57 # First check without any special flags
58 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
59 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c")
61 MESSAGE(STATUS "Checking for 64-bit off_t - present")
65 # Test with _FILE_OFFSET_BITS=64
66 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
67 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
68 COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64" )
70 MESSAGE(STATUS "Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64")
71 set(_FILE_OFFSET_BITS 64 CACHE INTERNAL "64-bit off_t requires _FILE_OFFSET_BITS=64")
76 # Test with _LARGE_FILES
77 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
78 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
79 COMPILE_DEFINITIONS "-D_LARGE_FILES" )
81 MESSAGE(STATUS "Checking for 64-bit off_t - present with _LARGE_FILES")
82 set(_LARGE_FILES 1 CACHE INTERNAL "64-bit off_t requires _LARGE_FILES")
87 # Test with _LARGEFILE_SOURCE
88 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
89 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
90 COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
92 MESSAGE(STATUS "Checking for 64-bit off_t - present with _LARGEFILE_SOURCE")
93 set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit off_t requires _LARGEFILE_SOURCE")
98 # now check for Windows stuff
99 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
100 "${CMAKE_SOURCE_DIR}/cmake/TestWindowsFSeek.c")
102 MESSAGE(STATUS "Checking for 64-bit off_t - present with _fseeki64")
103 set(HAVE__FSEEKI64 1 CACHE INTERNAL "64-bit off_t requires _fseeki64")
108 MESSAGE(STATUS "Checking for 64-bit off_t - not present")
111 # Set the flags we might have determined to be required above
112 configure_file("${CMAKE_SOURCE_DIR}/cmake/TestLargeFiles.c.cmakein"
113 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
115 MESSAGE(STATUS "Checking for fseeko/ftello")
116 # Test if ftello/fseeko are available
117 TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
118 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
119 if(FSEEKO_COMPILE_OK)
120 MESSAGE(STATUS "Checking for fseeko/ftello - present")
121 endif(FSEEKO_COMPILE_OK)
123 if(NOT FSEEKO_COMPILE_OK)
124 # glibc 2.2 neds _LARGEFILE_SOURCE for fseeko (but not 64-bit off_t...)
125 TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
126 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c"
127 COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
128 if(FSEEKO_COMPILE_OK)
129 MESSAGE(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE")
130 set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit fseeko requires _LARGEFILE_SOURCE")
131 endif(FSEEKO_COMPILE_OK)
132 endif(NOT FSEEKO_COMPILE_OK)
136 if(FSEEKO_COMPILE_OK)
137 SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
138 set(HAVE_FSEEKO 1 CACHE INTERNAL "64bit fseeko is available" FORCE)
139 else(FSEEKO_COMPILE_OK)
141 SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
142 SET(HAVE__FSEEKI64 1 CACHE INTERNAL "Windows 64-bit fseek" FORCE)
143 else (HAVE__FSEEKI64)
144 MESSAGE(STATUS "Checking for fseeko/ftello - not found")
145 SET(${VARIABLE} 0 CACHE INTERNAL "Result of test for large file support" FORCE)
146 endif (HAVE__FSEEKI64)
147 endif(FSEEKO_COMPILE_OK)
149 ENDIF(NOT DEFINED ${VARIABLE})
150 ENDMACRO(GMX_TEST_LARGE_FILES VARIABLE)