Build: Fix a typo in autogen.sh
[xz/debian.git] / cmake / tuklib_large_file_support.cmake
blob4ed1d09107b2ea133d9990f8ad77652f1876aa3c
1 # SPDX-License-Identifier: 0BSD
3 #############################################################################
5 # tuklib_large_file_support.cmake
7 # If off_t is less than 64 bits by default and -D_FILE_OFFSET_BITS=64
8 # makes off_t become 64-bit, the CMake option LARGE_FILE_SUPPORT is
9 # provided (ON by default) and -D_FILE_OFFSET_BITS=64 is added to
10 # the compile definitions if LARGE_FILE_SUPPORT is ON.
12 # Author: Lasse Collin
14 #############################################################################
16 include("${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake")
17 include(CheckCSourceCompiles)
19 function(tuklib_large_file_support TARGET_OR_ALL)
20     # MSVC must be handled specially in the C code.
21     if(MSVC)
22         return()
23     endif()
25     set(TUKLIB_LARGE_FILE_SUPPORT_TEST
26             "#include <sys/types.h>
27             int foo[sizeof(off_t) >= 8 ? 1 : -1];
28             int main(void) { return 0; }")
30     check_c_source_compiles("${TUKLIB_LARGE_FILE_SUPPORT_TEST}"
31                             TUKLIB_LARGE_FILE_SUPPORT_BY_DEFAULT)
33     if(NOT TUKLIB_LARGE_FILE_SUPPORT_BY_DEFAULT)
34         cmake_push_check_state()
35         # This needs -D.
36         list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64")
37         check_c_source_compiles("${TUKLIB_LARGE_FILE_SUPPORT_TEST}"
38                                 TUKLIB_LARGE_FILE_SUPPORT_WITH_FOB64)
39         cmake_pop_check_state()
40     endif()
42     if(TUKLIB_LARGE_FILE_SUPPORT_WITH_FOB64)
43         # Show the option only when _FILE_OFFSET_BITS=64 affects sizeof(off_t).
44         option(LARGE_FILE_SUPPORT
45                "Use -D_FILE_OFFSET_BITS=64 to support files larger than 2 GiB."
46                ON)
48         if(LARGE_FILE_SUPPORT)
49             # This must not use -D.
50             tuklib_add_definitions("${TARGET_OR_ALL}" "_FILE_OFFSET_BITS=64")
51         endif()
52     endif()
53 endfunction()