From 8d8c763683c5a975152b9259a1b7b89fddf34686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Thu, 17 Jan 2019 00:40:08 +0100 Subject: [PATCH] Add tde_setup_largefiles macro. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The macro sets the necessary definitions so that the default libc filesystem interface will be for large files on all architectures. Signed-off-by: Slávek Banko --- modules/TDEMacros.cmake | 86 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/modules/TDEMacros.cmake b/modules/TDEMacros.cmake index 15008b8..8f86c62 100644 --- a/modules/TDEMacros.cmake +++ b/modules/TDEMacros.cmake @@ -1927,6 +1927,92 @@ macro( tde_setup_msgfmt ) endmacro( ) +################################################ +##### +##### tde_setup_largefiles + +macro( tde_setup_largefiles ) + if( NOT DEFINED HAVE_LARGEFILES ) + message( STATUS "Check support for large files" ) + unset( LARGEFILES_DEFINITIONS ) + + # check without special definitions + unset( HAVE_SIZEOF_T CACHE ) + check_type_size( off_t SIZEOF_OFF_T ) + if( SIZEOF_OFF_T GREATER 7 ) + set( HAVE_LARGEFILES 1 ) + endif( ) + + # check with definition _FILE_OFFSET_BITS=64 + if( NOT HAVE_LARGEFILES ) + unset( HAVE_SIZEOF_OFF_T CACHE ) + tde_save_and_set( CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_FILE_OFFSET_BITS=64" ) + check_type_size( off_t SIZEOF_OFF_T ) + tde_restore( CMAKE_REQUIRED_DEFINITIONS ) + if( SIZEOF_OFF_T GREATER 7 ) + set( LARGEFILES_DEFINITIONS "-D_FILE_OFFSET_BITS=64" ) + set( HAVE_LARGEFILES 1 ) + endif( ) + endif( ) + + # check with definition _LARGE_FILES + if( NOT HAVE_LARGEFILES ) + unset( HAVE_SIZEOF_OFF_T CACHE ) + tde_save_and_set( CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_LARGE_FILES" ) + check_type_size( off_t SIZEOF_OFF_T ) + tde_restore( CMAKE_REQUIRED_DEFINITIONS ) + if( SIZEOF_OFF_T GREATER 7 ) + set( LARGEFILES_DEFINITIONS "-D_LARGE_FILES" ) + set( HAVE_LARGEFILES 1 ) + endif( ) + endif( ) + + # check with definition _LARGEFILE_SOURCE + if( NOT HAVE_LARGEFILES ) + unset( HAVE_SIZEOF_OFF_T CACHE ) + tde_save_and_set( CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_LARGEFILE_SOURCE" ) + check_type_size( off_t SIZEOF_OFF_T ) + tde_restore( CMAKE_REQUIRED_DEFINITIONS ) + if( SIZEOF_OFF_T GREATER 7 ) + set( LARGEFILES_DEFINITIONS "-D_LARGEFILE_SOURCE" ) + set( HAVE_LARGEFILES 1 ) + endif( ) + endif( ) + + # check for fseeko/ftello + if( HAVE_LARGEFILES ) + tde_save_and_set( CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} ${LARGEFILES_DEFINITIONS}" ) + check_symbol_exists( "fseeko" "stdio.h" HAVE_FSEEKO ) + tde_restore( CMAKE_REQUIRED_DEFINITIONS ) + if( NOT HAVE_FSEEKO ) + tde_save_and_set( CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} ${LARGEFILES_DEFINITIONS} -D_LARGEFILE_SOURCE" ) + check_symbol_exists( "fseeko" "stdio.h" HAVE_FSEEKO ) + tde_restore( CMAKE_REQUIRED_DEFINITIONS ) + if( HAVE_FSEEKO ) + set( LARGEFILES_DEFINITIONS "${LARGEFILES_DEFINITIONS} -D_LARGEFILE_SOURCE" ) + else( ) + unset( HAVE_LARGEFILES ) + endif( ) + endif( ) + endif( ) + + # check results + if( HAVE_LARGEFILES ) + if( "${LARGEFILES_DEFINITIONS}" STREQUAL "" ) + message( STATUS "Check support for large files - Success" ) + else( ) + add_definitions( ${LARGEFILES_DEFINITIONS} ) + message( STATUS "Check support for large files - Success with ${LARGEFILES_DEFINITIONS}" ) + endif( ) + set( HAVE_LARGEFILES 1 CACHE INTERNAL "Support for large files enabled" ) + else( ) + message( STATUS "Check support for large files - Failed" ) + tde_message_fatal( "Cannot find a way to enable support for large files." ) + endif( ) + endif( ) +endmacro( ) + + ################################################ ##### ##### Restore CMP0026 policy