Remove some usage of SIZEOF*
[gromacs.git] / cmake / gmxTestLargeFiles.cmake
blobe6cc07132ca4a47b2c84c4506af5cf2746d5b3ef
2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2009,2010,2012, 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
41 #  _LARGE_FILES
42 #  _LARGEFILE_SOURCE
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")
60         if(FILE64_OK)
61             MESSAGE(STATUS "Checking for 64-bit off_t - present")
62         endif(FILE64_OK)
64         if(NOT FILE64_OK)
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" )
69             if(FILE64_OK)
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")
72             endif(FILE64_OK)
73         endif(NOT FILE64_OK)
75         if(NOT FILE64_OK)
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" )
80             if(FILE64_OK)
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")
83             endif(FILE64_OK)
84         endif(NOT FILE64_OK)
86         if(NOT FILE64_OK)
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" )
91             if(FILE64_OK)
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")
94             endif(FILE64_OK)
95         endif(NOT FILE64_OK)
97         if(NOT FILE64_OK)
98             MESSAGE(STATUS "Checking for 64-bit off_t - not present")
99         else(NOT FILE64_OK)
100             # 64-bit off_t found. Now check that ftello/fseeko is available.
102             # Set the flags we might have determined to be required above
103             configure_file("${CMAKE_SOURCE_DIR}/cmake/TestLargeFiles.c.cmakein"
104                            "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
106             MESSAGE(STATUS "Checking for fseeko/ftello")
107             # Test if ftello/fseeko are available
108             TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
109                         "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
110             if(FSEEKO_COMPILE_OK)
111                 MESSAGE(STATUS "Checking for fseeko/ftello - present")
112             endif(FSEEKO_COMPILE_OK)
114             if(NOT FSEEKO_COMPILE_OK)
115                 # glibc 2.2 neds _LARGEFILE_SOURCE for fseeko (but not 64-bit off_t...)
116                 TRY_COMPILE(FSEEKO_COMPILE_OK "${CMAKE_BINARY_DIR}"
117                             "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c"
118                             COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
119                 if(FSEEKO_COMPILE_OK)
120                     MESSAGE(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE")
121                     set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit fseeko requires _LARGEFILE_SOURCE")
122                 else(FSEEKO_COMPILE_OK)
123                     set(FILE64_OK 0)
124                     message(STATUS "64-bit off_t present but fseeko/ftello not found!")
125                 endif(FSEEKO_COMPILE_OK)
126             endif(NOT FSEEKO_COMPILE_OK)
127         endif(NOT FILE64_OK)
129         if(NOT FILE64_OK)
130             # now check for Windows stuff
131             TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
132                         "${CMAKE_SOURCE_DIR}/cmake/TestWindowsFSeek.c")
133             if(FILE64_OK)
134                 MESSAGE(STATUS "Checking for 64-bit off_t - present with _fseeki64")
135                 set(HAVE__FSEEKI64 1 CACHE INTERNAL "64-bit off_t requires _fseeki64")
136             endif(FILE64_OK)
137         endif(NOT FILE64_OK)
139         if(FSEEKO_COMPILE_OK)
140             SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
141             set(HAVE_FSEEKO 1 CACHE INTERNAL "64bit fseeko is available" FORCE)
142         elseif(HAVE__FSEEKI64)
143             SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
144             SET(HAVE__FSEEKI64 1 CACHE INTERNAL "Windows 64-bit fseek" FORCE)
145         elseif(SIZEOF_LONG_INT EQUAL 8) #standard fseek is OK for 64bit
146             SET(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
147         else()
148             SET(${VARIABLE} 0 CACHE INTERNAL "Result of test for large file support" FORCE)
149             MESSAGE(FATAL_ERROR "Checking for 64bit file support failed.")
150         endif()
152     ENDIF(NOT DEFINED ${VARIABLE})
153 ENDMACRO(GMX_TEST_LARGE_FILES VARIABLE)