2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2009,2010,2012,2014, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source 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 include(CheckTypeSize)
50 MACRO(GMX_TEST_LARGE_FILES VARIABLE)
51 IF(NOT DEFINED ${VARIABLE})
53 # On most platforms it is probably overkill to first test the flags for 64-bit off_t,
54 # and then separately fseeko. However, in the future we might have 128-bit filesystems
55 # (ZFS), so it might be dangerous to indiscriminately set e.g. _FILE_OFFSET_BITS=64.
57 MESSAGE(STATUS "Checking for 64-bit off_t")
59 # First check without any special flags
60 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
61 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c")
63 MESSAGE(STATUS "Checking for 64-bit off_t - present")
67 # Test with _FILE_OFFSET_BITS=64
68 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
69 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
70 COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64" )
72 MESSAGE(STATUS "Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64")
73 set(_FILE_OFFSET_BITS 64 CACHE INTERNAL "64-bit off_t requires _FILE_OFFSET_BITS=64")
78 # Test with _LARGE_FILES
79 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
80 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
81 COMPILE_DEFINITIONS "-D_LARGE_FILES" )
83 MESSAGE(STATUS "Checking for 64-bit off_t - present with _LARGE_FILES")
84 set(_LARGE_FILES 1 CACHE INTERNAL "64-bit off_t requires _LARGE_FILES")
89 # Test with _LARGEFILE_SOURCE
90 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
91 "${CMAKE_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
92 COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
94 MESSAGE(STATUS "Checking for 64-bit off_t - present with _LARGEFILE_SOURCE")
95 set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit off_t requires _LARGEFILE_SOURCE")
100 MESSAGE(STATUS "Checking for 64-bit off_t - not present")
102 # 64-bit off_t found. Now check that ftello/fseeko is available.
104 # Set the flags we might have determined to be required above
105 configure_file("${CMAKE_SOURCE_DIR}/cmake/TestLargeFiles.c.cmakein"
106 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
108 MESSAGE(STATUS "Checking for fseeko/ftello")
109 # Test if ftello/fseeko are available
110 TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
111 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
112 if(FSEEKO_COMPILE_OK)
113 MESSAGE(STATUS "Checking for fseeko/ftello - present")
116 if(NOT FSEEKO_COMPILE_OK)
117 # glibc 2.2 neds _LARGEFILE_SOURCE for fseeko (but not 64-bit off_t...)
118 TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
119 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c"
120 COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
121 if(FSEEKO_COMPILE_OK)
122 MESSAGE(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE")
123 set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit fseeko requires _LARGEFILE_SOURCE")
126 message(STATUS "64-bit off_t present but fseeko/ftello not found!")
132 # now check for Windows stuff
133 TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
134 "${CMAKE_SOURCE_DIR}/cmake/TestWindowsFSeek.c")
136 MESSAGE(STATUS "Checking for 64-bit off_t - present with _fseeki64")
137 set(HAVE__FSEEKI64 1 CACHE INTERNAL "64-bit off_t requires _fseeki64")
141 if(FSEEKO_COMPILE_OK)
142 SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
143 set(HAVE_FSEEKO 1 CACHE INTERNAL "64bit fseeko is available" FORCE)
144 elseif(HAVE__FSEEKI64)
145 SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
146 SET(HAVE__FSEEKI64 1 CACHE INTERNAL "Windows 64-bit fseek" FORCE)
148 check_type_size("long int" SIZEOF_LONG_INT)
149 if(SIZEOF_LONG_INT EQUAL 8) #standard fseek is OK for 64bit
150 SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
152 MESSAGE(FATAL_ERROR "Checking for 64bit file support failed.")
157 ENDMACRO(GMX_TEST_LARGE_FILES VARIABLE)