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