xref: /freebsd/contrib/libpcap/cmake/Modules/FindFseeko.cmake (revision 7877fdebeeb35fad1cbbafce22598b1bdf97c786)
1# CMake support for fseeko
2#
3# Based on FindLFS.cmake by
4# Copyright (C) 2016 Julian Andres Klode <jak@debian.org>.
5#
6# Permission is hereby granted, free of charge, to any person
7# obtaining a copy of this software and associated documentation files
8# (the "Software"), to deal in the Software without restriction,
9# including without limitation the rights to use, copy, modify, merge,
10# publish, distribute, sublicense, and/or sell copies of the Software,
11# and to permit persons to whom the Software is furnished to do so,
12# subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be
15# included in all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24# SOFTWARE.
25#
26# This defines the following variables
27#
28# FSEEKO_DEFINITIONS - List of definitions to pass to add_definitions()
29# FSEEKO_COMPILE_OPTIONS - List of definitions to pass to add_compile_options()
30# FSEEKO_LIBRARIES - List of libraries and linker flags
31# FSEEKO_FOUND - If there is Large files support
32#
33
34include(CheckCSourceCompiles)
35include(FindPackageHandleStandardArgs)
36include(CMakePushCheckState)
37
38# Check for the availability of fseeko()
39# The cases handled are:
40#
41#  * Native fseeko()
42#  * Preprocessor flag -D_LARGEFILE_SOURCE
43#
44function(_fseeko_check)
45    set(_fseeko_cppflags)
46    cmake_push_check_state()
47    set(CMAKE_REQUIRED_QUIET 1)
48    set(CMAKE_REQUIRED_DEFINITIONS ${LFS_DEFINITIONS})
49    message(STATUS "Looking for native fseeko support")
50    check_symbol_exists(fseeko stdio.h fseeko_native)
51    cmake_pop_check_state()
52    if (fseeko_native)
53        message(STATUS "Looking for native fseeko support - found")
54        set(FSEEKO_FOUND TRUE)
55    else()
56        message(STATUS "Looking for native fseeko support - not found")
57    endif()
58
59    if (NOT FSEEKO_FOUND)
60        # See if it's available with _LARGEFILE_SOURCE.
61        cmake_push_check_state()
62        set(CMAKE_REQUIRED_QUIET 1)
63        set(CMAKE_REQUIRED_DEFINITIONS ${LFS_DEFINITIONS} "-D_LARGEFILE_SOURCE")
64        check_symbol_exists(fseeko stdio.h fseeko_need_largefile_source)
65        cmake_pop_check_state()
66        if (fseeko_need_largefile_source)
67            message(STATUS "Looking for fseeko support with _LARGEFILE_SOURCE - found")
68            set(FSEEKO_FOUND TRUE)
69            set(_fseeko_cppflags "-D_LARGEFILE_SOURCE")
70        else()
71            message(STATUS "Looking for fseeko support with _LARGEFILE_SOURCE - not found")
72        endif()
73    endif()
74
75    set(FSEEKO_DEFINITIONS ${_fseeko_cppflags} CACHE STRING "Extra definitions for fseeko support")
76    set(FSEEKO_COMPILE_OPTIONS "" CACHE STRING "Extra compiler options for fseeko support")
77    set(FSEEKO_LIBRARIES "" CACHE STRING "Extra definitions for fseeko support")
78    set(FSEEKO_FOUND ${FSEEKO_FOUND} CACHE INTERNAL "Found fseeko")
79endfunction()
80
81if (NOT FSEEKO_FOUND)
82    _fseeko_check()
83endif()
84
85find_package_handle_standard_args(FSEEKO "Could not find fseeko. Set FSEEKO_DEFINITIONS, FSEEKO_COMPILE_OPTIONS, FSEEKO_LIBRARIES." FSEEKO_FOUND)
86