File: FindBIND.cmake

package info (click to toggle)
broccoli-python 0.62-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 460 kB
  • ctags: 105
  • sloc: python: 407; sh: 202; makefile: 21
file content (102 lines) | stat: -rw-r--r-- 2,905 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# - Try to find BIND include dirs and libraries
#
# Usage of this module as follows:
#
#     find_package(BIND)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
#  BIND_ROOT_DIR             Set this variable to the root installation of BIND
#                            if the module has problems finding the proper
#                            installation path.
#
# Variables defined by this module:
#
#  BIND_FOUND                System has BIND, include and library dirs found
#  BIND_INCLUDE_DIR          The BIND include directories. 
#  BIND_LIBRARY              The BIND library (if any) required for
#                            ns_inittab and res_mkquery symbols

find_path(BIND_ROOT_DIR
    NAMES include/bind/resolv.h include/resolv.h
)

find_path(BIND_INCLUDE_DIR
    NAMES resolv.h
    HINTS ${BIND_ROOT_DIR}/include/bind ${BIND_ROOT_DIR}/include
)

if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    # the static resolv library is preferred because
    # on some systems, the ns_initparse symbol is not
    # exported in the shared library (strangely)
    # see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=291609
    set(bind_libs none libresolv.a resolv bind)
else ()
    set(bind_libs none resolv bind)
endif ()

include(CheckCSourceCompiles)

# Find which library has the res_mkquery and ns_initparse symbols
set(CMAKE_REQUIRED_INCLUDES ${BIND_INCLUDE_DIR})
foreach (bindlib ${bind_libs})
    if (NOT ${bindlib} MATCHES "none")
        find_library(BIND_LIBRARY
            NAMES ${bindlib}
            HINTS ${BIND_ROOT_DIR}/lib ${BIND_ROOT_DIR}/lib/libbind
        )
    endif ()

    set(CMAKE_REQUIRED_LIBRARIES ${BIND_LIBRARY})

    check_c_source_compiles("
        #include <arpa/nameser.h>
        int main() {
            ns_initparse(0, 0, 0);
            return 0;
        }
" ns_initparse_works_${bindlib})

    check_c_source_compiles("
        #include <sys/types.h>
        #include <sys/socket.h>
        #include <netinet/in.h>
        #include <arpa/nameser.h>
        #include <resolv.h>
        int main() {
            int (*p)() = res_mkquery;
            return 0;
        }
" res_mkquery_works_${bindlib})

    set(CMAKE_REQUIRED_LIBRARIES)

    if (ns_initparse_works_${bindlib} AND res_mkquery_works_${bindlib})
        break ()
    else ()
        set(BIND_LIBRARY BIND_LIBRARY-NOTFOUND)
    endif ()
endforeach ()
set(CMAKE_REQUIRED_INCLUDES)

include(FindPackageHandleStandardArgs)

if (ns_initparse_works_none AND res_mkquery_works_none)
    # system does not require linking to a BIND library
    find_package_handle_standard_args(BIND DEFAULT_MSG
        BIND_INCLUDE_DIR
    )
else ()
    find_package_handle_standard_args(BIND DEFAULT_MSG
        BIND_LIBRARY
        BIND_INCLUDE_DIR
    )
endif ()

mark_as_advanced(
    BIND_ROOT_DIR
    BIND_LIBRARY
    BIND_INCLUDE_DIR
)