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