From c3be4bc18d4c8ef27d09b452bf8b792914b865ab Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 29 Jun 2023 02:58:17 +0200 Subject: [PATCH] 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 --- CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c912e7bf..3cf957d38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,11 +67,12 @@ include(${SDL3_SOURCE_DIR}/cmake/CheckCPUArchitecture.cmake) include(${SDL3_SOURCE_DIR}/cmake/GetGitRevisionDescription.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) -if (LIBC_IS_GLIBC AND CMAKE_SIZEOF_VOID_P EQUAL 4) - target_compile_definitions(sdl-build-options INTERFACE "_FILE_OFFSET_BITS=64") +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") + # 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() if(CMAKE_VERSION VERSION_LESS "3.26")