1*4ebd34fbSCy Schubert# - Check if _FILE_OFFSET_BITS macro needed for large files
2*4ebd34fbSCy Schubert# CHECK_FILE_OFFSET_BITS ()
3*4ebd34fbSCy Schubert#
4*4ebd34fbSCy Schubert# The following variables may be set before calling this macro to
5*4ebd34fbSCy Schubert# modify the way the check is run:
6*4ebd34fbSCy Schubert#
7*4ebd34fbSCy Schubert#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
8*4ebd34fbSCy Schubert#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
9*4ebd34fbSCy Schubert#  CMAKE_REQUIRED_INCLUDES = list of include directories
10*4ebd34fbSCy Schubert# Copyright (c) 2009, Michihiro NAKAJIMA
11*4ebd34fbSCy Schubert#
12*4ebd34fbSCy Schubert# Redistribution and use is allowed according to the terms of the BSD license.
13*4ebd34fbSCy Schubert# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
14*4ebd34fbSCy Schubert
15*4ebd34fbSCy Schubert#INCLUDE(CheckCSourceCompiles)
16*4ebd34fbSCy Schubert
17*4ebd34fbSCy SchubertGET_FILENAME_COMPONENT(_selfdir_CheckFileOffsetBits
18*4ebd34fbSCy Schubert	 "${CMAKE_CURRENT_LIST_FILE}" PATH)
19*4ebd34fbSCy Schubert
20*4ebd34fbSCy SchubertMACRO (CHECK_FILE_OFFSET_BITS)
21*4ebd34fbSCy Schubert  IF(NOT DEFINED _FILE_OFFSET_BITS)
22*4ebd34fbSCy Schubert    MESSAGE(STATUS "Cheking _FILE_OFFSET_BITS for large files")
23*4ebd34fbSCy Schubert    TRY_COMPILE(__WITHOUT_FILE_OFFSET_BITS_64
24*4ebd34fbSCy Schubert      ${CMAKE_CURRENT_BINARY_DIR}
25*4ebd34fbSCy Schubert      ${_selfdir_CheckFileOffsetBits}/CheckFileOffsetBits.c
26*4ebd34fbSCy Schubert      COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
27*4ebd34fbSCy Schubert    IF(NOT __WITHOUT_FILE_OFFSET_BITS_64)
28*4ebd34fbSCy Schubert      TRY_COMPILE(__WITH_FILE_OFFSET_BITS_64
29*4ebd34fbSCy Schubert        ${CMAKE_CURRENT_BINARY_DIR}
30*4ebd34fbSCy Schubert        ${_selfdir_CheckFileOffsetBits}/CheckFileOffsetBits.c
31*4ebd34fbSCy Schubert        COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_FILE_OFFSET_BITS=64)
32*4ebd34fbSCy Schubert    ENDIF(NOT __WITHOUT_FILE_OFFSET_BITS_64)
33*4ebd34fbSCy Schubert
34*4ebd34fbSCy Schubert    IF(NOT __WITHOUT_FILE_OFFSET_BITS_64 AND __WITH_FILE_OFFSET_BITS_64)
35*4ebd34fbSCy Schubert      SET(_FILE_OFFSET_BITS 64 CACHE INTERNAL "_FILE_OFFSET_BITS macro needed for large files")
36*4ebd34fbSCy Schubert      MESSAGE(STATUS "Cheking _FILE_OFFSET_BITS for large files - needed")
37*4ebd34fbSCy Schubert    ELSE(NOT __WITHOUT_FILE_OFFSET_BITS_64 AND __WITH_FILE_OFFSET_BITS_64)
38*4ebd34fbSCy Schubert      SET(_FILE_OFFSET_BITS "" CACHE INTERNAL "_FILE_OFFSET_BITS macro needed for large files")
39*4ebd34fbSCy Schubert      MESSAGE(STATUS "Cheking _FILE_OFFSET_BITS for large files - not needed")
40*4ebd34fbSCy Schubert    ENDIF(NOT __WITHOUT_FILE_OFFSET_BITS_64 AND __WITH_FILE_OFFSET_BITS_64)
41*4ebd34fbSCy Schubert  ENDIF(NOT DEFINED _FILE_OFFSET_BITS)
42*4ebd34fbSCy Schubert
43*4ebd34fbSCy SchubertENDMACRO (CHECK_FILE_OFFSET_BITS)
44