Home | History | Annotate | Download | only in CMakeModules
      1 ## Checks for large file support ##
      2 include(CheckIncludeFile)
      3 include(CheckSymbolExists)
      4 include(CheckTypeSize)
      5 
      6 macro(check_lfs _isenable)
      7   set(LFS_OFF_T "")
      8   set(LFS_FOPEN "")
      9   set(LFS_FSEEK "")
     10   set(LFS_FTELL "")
     11   set(LFS_PRID "")
     12 
     13   if(${_isenable})
     14     set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
     15     set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
     16         -D_LARGEFILE_SOURCE -D_LARGE_FILES -D_FILE_OFFSET_BITS=64
     17         -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS)
     18 
     19     check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
     20     check_include_file("inttypes.h" HAVE_INTTYPES_H)
     21     check_include_file("stddef.h" HAVE_STDDEF_H)
     22     check_include_file("stdint.h" HAVE_STDINT_H)
     23 
     24     # LFS type1: 8 <= sizeof(off_t), fseeko, ftello
     25     check_type_size("off_t" SIZEOF_OFF_T)
     26     if(SIZEOF_OFF_T GREATER 7)
     27       check_symbol_exists("fseeko" "stdio.h" HAVE_FSEEKO)
     28       check_symbol_exists("ftello" "stdio.h" HAVE_FTELLO)
     29       if(HAVE_FSEEKO AND HAVE_FTELLO)
     30         set(LFS_OFF_T "off_t")
     31         set(LFS_FOPEN "fopen")
     32         set(LFS_FSEEK "fseeko")
     33         set(LFS_FTELL "ftello")
     34         check_symbol_exists("PRIdMAX" "inttypes.h" HAVE_PRIDMAX)
     35         if(HAVE_PRIDMAX)
     36           set(LFS_PRID "PRIdMAX")
     37         else(HAVE_PRIDMAX)
     38           check_type_size("long" SIZEOF_LONG)
     39           check_type_size("int" SIZEOF_INT)
     40           if(SIZEOF_OFF_T GREATER SIZEOF_LONG)
     41             set(LFS_PRID "\"lld\"")
     42           elseif(SIZEOF_LONG GREATER SIZEOF_INT)
     43             set(LFS_PRID "\"ld\"")
     44           else(SIZEOF_OFF_T GREATER SIZEOF_LONG)
     45             set(LFS_PRID "\"d\"")
     46           endif(SIZEOF_OFF_T GREATER SIZEOF_LONG)
     47         endif(HAVE_PRIDMAX)
     48       endif(HAVE_FSEEKO AND HAVE_FTELLO)
     49     endif(SIZEOF_OFF_T GREATER 7)
     50 
     51     # LFS type2: 8 <= sizeof(off64_t), fopen64, fseeko64, ftello64
     52     if(NOT LFS_OFF_T)
     53       check_type_size("off64_t" SIZEOF_OFF64_T)
     54       if(SIZEOF_OFF64_T GREATER 7)
     55         check_symbol_exists("fopen64" "stdio.h" HAVE_FOPEN64)
     56         check_symbol_exists("fseeko64" "stdio.h" HAVE_FSEEKO64)
     57         check_symbol_exists("ftello64" "stdio.h" HAVE_FTELLO64)
     58         if(HAVE_FOPEN64 AND HAVE_FSEEKO64 AND HAVE_FTELLO64)
     59           set(LFS_OFF_T "off64_t")
     60           set(LFS_FOPEN "fopen64")
     61           set(LFS_FSEEK "fseeko64")
     62           set(LFS_FTELL "ftello64")
     63           check_symbol_exists("PRIdMAX" "inttypes.h" HAVE_PRIDMAX)
     64           if(HAVE_PRIDMAX)
     65             set(LFS_PRID "PRIdMAX")
     66           else(HAVE_PRIDMAX)
     67             check_type_size("long" SIZEOF_LONG)
     68             check_type_size("int" SIZEOF_INT)
     69             if(SIZEOF_OFF64_T GREATER SIZEOF_LONG)
     70               set(LFS_PRID "\"lld\"")
     71             elseif(SIZEOF_LONG GREATER SIZEOF_INT)
     72               set(LFS_PRID "\"ld\"")
     73             else(SIZEOF_OFF64_T GREATER SIZEOF_LONG)
     74               set(LFS_PRID "\"d\"")
     75             endif(SIZEOF_OFF64_T GREATER SIZEOF_LONG)
     76           endif(HAVE_PRIDMAX)
     77         endif(HAVE_FOPEN64 AND HAVE_FSEEKO64 AND HAVE_FTELLO64)
     78       endif(SIZEOF_OFF64_T GREATER 7)
     79     endif(NOT LFS_OFF_T)
     80 
     81     # LFS type3: 8 <= sizeof(__int64), _fseeki64, _ftelli64
     82     if(NOT LFS_OFF_T)
     83       check_type_size("__int64" SIZEOF___INT64)
     84       if(SIZEOF___INT64 GREATER 7)
     85         check_symbol_exists("_fseeki64" "stdio.h" HAVE__FSEEKI64)
     86         check_symbol_exists("_ftelli64" "stdio.h" HAVE__FTELLI64)
     87         if(HAVE__FSEEKI64 AND HAVE__FTELLI64)
     88           set(LFS_OFF_T "__int64")
     89           set(LFS_FOPEN "fopen")
     90           set(LFS_FSEEK "_fseeki64")
     91           set(LFS_FTELL "_ftelli64")
     92           set(LFS_PRID  "\"I64d\"")
     93         endif(HAVE__FSEEKI64 AND HAVE__FTELLI64)
     94       endif(SIZEOF___INT64 GREATER 7)
     95     endif(NOT LFS_OFF_T)
     96 
     97     set(CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
     98   endif(${_isenable})
     99 
    100   if(NOT LFS_OFF_T)
    101     ## not found
    102     set(LFS_OFF_T "long")
    103     set(LFS_FOPEN "fopen")
    104     set(LFS_FSEEK "fseek")
    105     set(LFS_FTELL "ftell")
    106     set(LFS_PRID  "\"ld\"")
    107   endif(NOT LFS_OFF_T)
    108 
    109 endmacro(check_lfs)
    110