Fix malformed CUDA version macro check
[alexxy/gromacs.git] / cmake / gmxTestLargeFiles.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
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.
8 #
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.
13 #
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.
18 #
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.
23 #
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.
31 #
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.
34 #
35 # - Define macro to check large file support
36 #
37 #  GMX_TEST_LARGE_FILES(VARIABLE)
38 #
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  
44 #
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!
47
48 MACRO(GMX_TEST_LARGE_FILES VARIABLE)
49     IF(NOT DEFINED ${VARIABLE})
50
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.
54
55         MESSAGE(STATUS "Checking for 64-bit off_t")
56
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)
63
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)    
74
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)
85         
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)
96
97         if(NOT FILE64_OK)
98             # now check for Windows stuff
99             TRY_COMPILE(FILE64_OK "${CMAKE_BINARY_DIR}"
100                         "${CMAKE_SOURCE_DIR}/cmake/TestWindowsFSeek.c")
101             if(FILE64_OK)
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")
104             endif(FILE64_OK)
105         endif(NOT FILE64_OK)
106
107         if(NOT FILE64_OK)
108             MESSAGE(STATUS "Checking for 64-bit off_t - not present")
109         else(NOT FILE64_OK)
110
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")
114
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)
122
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)
133
134         endif(NOT FILE64_OK)
135
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)
140             if (HAVE__FSEEKI64)
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)
148
149     ENDIF(NOT DEFINED ${VARIABLE})
150 ENDMACRO(GMX_TEST_LARGE_FILES VARIABLE)
151
152
153