cmake: Compile with 64-bit time stamps where possible

On platforms where time_t is a signed 32-bit integer, most notably i386 Linux,
various functions stop working when dealing with a timestamp
beyond January 2038.

glibc has an opt-in mechanism that redefines time_t to be 64-bit,
and correspondingly increases the size of all system data
structures that contain a time_t, such as struct timeval and struct stat.
This is necessary to allow timestamps beyond January 2038 to be represented;
as well as things that obviously deal with timestamps, this affects functions
like stat(), which will fail with EOVERFLOW if asked to inspect a file whose
correct timestamp does not fit in time_t. This in turn can cause unexpected
problems for "filesystem APIs" of the form "if /run/foo exists, then ..."
when accessed by 32-bit code, if the check for existence is done with stat()
rather than access().

Using 64-bit timestamps in glibc is an opt-in and not the default, because
if done carelessly it can change libraries' ABIs. However, SDL mostly doesn't
use system headers or types in its own headers. I

Co-authored-by: Simon McVittie <smcv@collabora.com>
main
Anonymous Maarten 2023-06-29 02:58:17 +02:00 committed by Sam Lantinga
parent baa9c57581
commit c3be4bc18d
1 changed files with 5 additions and 4 deletions

View File

@ -67,11 +67,12 @@ include(${SDL3_SOURCE_DIR}/cmake/CheckCPUArchitecture.cmake)
include(${SDL3_SOURCE_DIR}/cmake/GetGitRevisionDescription.cmake) include(${SDL3_SOURCE_DIR}/cmake/GetGitRevisionDescription.cmake)
include(${SDL3_SOURCE_DIR}/cmake/3rdparty.cmake) include(${SDL3_SOURCE_DIR}/cmake/3rdparty.cmake)
# Enable large file support on 32-bit glibc, so that we can access files
# with large inode numbers
check_symbol_exists("__GLIBC__" "stdlib.h" LIBC_IS_GLIBC) check_symbol_exists("__GLIBC__" "stdlib.h" LIBC_IS_GLIBC)
if (LIBC_IS_GLIBC AND CMAKE_SIZEOF_VOID_P EQUAL 4) if(CMAKE_SIZEOF_VOID_P EQUAL 4)
# Enable large file support on 32-bit glibc, so that we can access files with large inode numbers
target_compile_definitions(sdl-build-options INTERFACE "_FILE_OFFSET_BITS=64") target_compile_definitions(sdl-build-options INTERFACE "_FILE_OFFSET_BITS=64")
# Enable 64-bit time_t on 32-bit glibc, so that time stamps remain correct beyond January 2038
target_compile_definitions(sdl-build-options INTERFACE "_TIME_BITS=64")
endif() endif()
if(CMAKE_VERSION VERSION_LESS "3.26") if(CMAKE_VERSION VERSION_LESS "3.26")