209 lines
8.0 KiB
CMake
209 lines
8.0 KiB
CMake
#
|
|
# This file is part of the GROMACS molecular simulation package.
|
|
#
|
|
# Copyright (c) 2009,2010,2012,2014,2019, by the GROMACS development team, led by
|
|
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
|
|
# and including many others, as listed in the AUTHORS file in the
|
|
# top-level source directory and at http://www.gromacs.org.
|
|
#
|
|
# GROMACS is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU Lesser General Public License
|
|
# as published by the Free Software Foundation; either version 2.1
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# GROMACS is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Lesser General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
# License along with GROMACS; if not, see
|
|
# http://www.gnu.org/licenses, or write to the Free Software Foundation,
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
#
|
|
# If you want to redistribute modifications to GROMACS, please
|
|
# consider that scientific software is very special. Version
|
|
# control is crucial - bugs must be traceable. We will be happy to
|
|
# consider code for inclusion in the official distribution, but
|
|
# derived work must not be called official GROMACS. Details are found
|
|
# in the README & COPYING files - if they are missing, get the
|
|
# official version at http://www.gromacs.org.
|
|
#
|
|
# To help us fund GROMACS development, we humbly ask that you cite
|
|
# the research papers on the package. Check out http://www.gromacs.org.
|
|
|
|
# Forked from Gromacs
|
|
|
|
# - Define macro to check large file support
|
|
#
|
|
# myx_cmake_test_large_files(VARIABLE)
|
|
#
|
|
# VARIABLE will be set to true if off_t is 64 bits, and fseeko/ftello present.
|
|
# This macro will also set defines necessary enable large file support, for instance
|
|
# _LARGE_FILES
|
|
# _LARGEFILE_SOURCE
|
|
# _FILE_OFFSET_BITS 64
|
|
# HAVE_FSEEKO
|
|
# HAVE__FSEEKI64
|
|
#
|
|
# However, it is YOUR job to make sure these defines are set in a cmakedefine so they
|
|
# end up in a config.h file that is included in your source if necessary!
|
|
|
|
include_guard(GLOBAL)
|
|
include(CheckTypeSize)
|
|
|
|
|
|
set(_test_file_offset_bits_c
|
|
"
|
|
#include <sys/types.h>
|
|
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
|
int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ];
|
|
int main(int argc, char **argv) { return 0; }
|
|
")
|
|
set(_test_file_offset_bits_c_path ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/test_file_offset_bits.c)
|
|
file(WRITE ${_test_file_offset_bits_c_path} ${_test_file_offset_bits_c})
|
|
|
|
|
|
set(_test_large_file_c_in
|
|
"
|
|
#cmakedefine _LARGEFILE_SOURCE
|
|
#cmakedefine _LARGEFILE64_SOURCE
|
|
#cmakedefine _LARGE_FILES
|
|
#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@
|
|
|
|
#include <sys/types.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ];
|
|
FILE *fp = fopen(argv[0],\"r\");
|
|
off_t offset = ftello( fp );
|
|
fseeko( fp, offset, SEEK_CUR );
|
|
fclose(fp);
|
|
return off_t_is_large[0] || argc;
|
|
}
|
|
")
|
|
set(_test_large_file_c_path ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/test_large_file.c)
|
|
set(_test_large_file_c_in_path ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/test_large_file.c.in)
|
|
file(WRITE ${_test_large_file_c_in_path} ${_test_large_file_c_in})
|
|
|
|
|
|
set(_test_windows_fseek_c
|
|
"
|
|
#include <stdio.h>
|
|
int main()
|
|
{
|
|
__int64 off=0;
|
|
_fseeki64(NULL, off, SEEK_SET);
|
|
return 0;
|
|
}
|
|
")
|
|
set(_test_windows_fseek_c_path ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/test_windows_fseek.c)
|
|
file(WRITE ${_test_windows_fseek_c_path} ${_test_windows_fseek_c})
|
|
|
|
|
|
macro(myx_cmake_test_large_files VARIABLE)
|
|
if(NOT DEFINED ${VARIABLE})
|
|
|
|
# On most platforms it is probably overkill to first test the flags for 64-bit off_t,
|
|
# and then separately fseeko. However, in the future we might have 128-bit filesystems
|
|
# (ZFS), so it might be dangerous to indiscriminately set e.g. _FILE_OFFSET_BITS=64.
|
|
|
|
message(STATUS "Checking for 64-bit off_t")
|
|
|
|
# First check without any special flags
|
|
try_compile(FILE64_OK ${CMAKE_CURRENT_BINARY_DIR} ${_test_file_offset_bits_c_path})
|
|
if(FILE64_OK)
|
|
message(STATUS "Checking for 64-bit off_t - present")
|
|
endif()
|
|
|
|
if(NOT FILE64_OK)
|
|
# Test with _FILE_OFFSET_BITS=64
|
|
try_compile(FILE64_OK ${CMAKE_CURRENT_BINARY_DIR} ${_test_file_offset_bits_c_path}
|
|
COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
|
|
if(FILE64_OK)
|
|
message(STATUS "Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64")
|
|
set(_FILE_OFFSET_BITS 64 CACHE INTERNAL "64-bit off_t requires _FILE_OFFSET_BITS=64")
|
|
endif()
|
|
endif()
|
|
|
|
if(NOT FILE64_OK)
|
|
# Test with _LARGE_FILES
|
|
try_compile(FILE64_OK ${CMAKE_CURRENT_BINARY_DIR} ${_test_file_offset_bits_c_path}
|
|
COMPILE_DEFINITIONS "-D_LARGE_FILES")
|
|
if(FILE64_OK)
|
|
message(STATUS "Checking for 64-bit off_t - present with _LARGE_FILES")
|
|
set(_LARGE_FILES 1 CACHE INTERNAL "64-bit off_t requires _LARGE_FILES")
|
|
endif()
|
|
endif()
|
|
|
|
if(NOT FILE64_OK)
|
|
# Test with _LARGEFILE_SOURCE
|
|
try_compile(FILE64_OK ${CMAKE_CURRENT_BINARY_DIR} ${_test_file_offset_bits_c_path}
|
|
COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE")
|
|
if(FILE64_OK)
|
|
message(STATUS "Checking for 64-bit off_t - present with _LARGEFILE_SOURCE")
|
|
set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit off_t requires _LARGEFILE_SOURCE")
|
|
endif()
|
|
endif()
|
|
|
|
if(NOT FILE64_OK)
|
|
message(STATUS "Checking for 64-bit off_t - not present")
|
|
else()
|
|
# 64-bit off_t found. Now check that ftello/fseeko is available.
|
|
|
|
# Set the flags we might have determined to be required above
|
|
configure_file(${_test_large_file_c_in_path} ${_test_large_file_c_path})
|
|
|
|
message(STATUS "Checking for fseeko/ftello")
|
|
# Test if ftello/fseeko are available
|
|
try_compile(FSEEKO_COMPILE_OK ${CMAKE_CURRENT_BINARY_DIR} ${_test_large_file_c_path})
|
|
if(FSEEKO_COMPILE_OK)
|
|
message(STATUS "Checking for fseeko/ftello - present")
|
|
endif()
|
|
|
|
if(NOT FSEEKO_COMPILE_OK)
|
|
# glibc 2.2 neds _LARGEFILE_SOURCE for fseeko (but not 64-bit off_t...)
|
|
try_compile(FSEEKO_COMPILE_OK ${CMAKE_CURRENT_BINARY_DIR} ${_test_large_file_c_path}
|
|
COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE")
|
|
if(FSEEKO_COMPILE_OK)
|
|
message(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE")
|
|
set(_LARGEFILE_SOURCE 1 CACHE INTERNAL "64-bit fseeko requires _LARGEFILE_SOURCE")
|
|
else()
|
|
set(FILE64_OK 0)
|
|
message(STATUS "64-bit off_t present but fseeko/ftello not found!")
|
|
endif()
|
|
endif()
|
|
endif()
|
|
|
|
# cmake-lint: disable=C0103
|
|
if(NOT FILE64_OK)
|
|
# now check for Windows stuff
|
|
try_compile(FILE64_OK ${CMAKE_CURRENT_BINARY_DIR} ${_test_windows_fseek_c_path})
|
|
if(FILE64_OK)
|
|
message(STATUS "Checking for 64-bit off_t - present with _fseeki64")
|
|
set(HAVE__FSEEKI64 1 CACHE INTERNAL "64-bit off_t requires _fseeki64")
|
|
endif()
|
|
endif()
|
|
|
|
if(FSEEKO_COMPILE_OK)
|
|
set(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
|
|
set(HAVE_FSEEKO 1 CACHE INTERNAL "64-bit fseeko is available" FORCE)
|
|
elseif(HAVE__FSEEKI64)
|
|
set(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
|
|
set(HAVE__FSEEKI64 1 CACHE INTERNAL "Windows 64-bit fseek" FORCE)
|
|
else()
|
|
check_type_size("long int" SIZEOF_LONG_INT)
|
|
if(SIZEOF_LONG_INT EQUAL 8) #standard fseek is OK for 64bit
|
|
set(${VARIABLE} 1 CACHE INTERNAL "Result of test for large file support" FORCE)
|
|
else()
|
|
message(FATAL_ERROR "Checking for 64-bit file support failed.")
|
|
endif()
|
|
endif()
|
|
endif()
|
|
endmacro(myx_cmake_test_large_files VARIABLE)
|