File: FindLibunbound.cmake

package info (click to toggle)
getdns 1.7.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,752 kB
  • sloc: ansic: 57,351; sh: 407; xml: 38; makefile: 22
file content (104 lines) | stat: -rw-r--r-- 3,493 bytes parent folder | download
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
103
104
#[=======================================================================[.rst:
FindLibunbound
--------------

Find the Libunbound library

Imported targets
^^^^^^^^^^^^^^^^

This module defines the following :prop_tgt:`IMPORTED` targets:

``Libunbound::Libunbound``
  The Libunbound library, if found.

Result variables
^^^^^^^^^^^^^^^^

This module will set the following variables in your project:

``Libunbound_FOUND``
  If false, do not try to use Libunbound.
``LIBUNBOUND_INCLUDE_DIR``
  where to find libunbound headers.
``LIBUNBOUND_LIBRARIES``
  the libraries needed to use Libunbound.
``LIBUNBOUND_VERSION``
  the version of the Libunbound library found

#]=======================================================================]

find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
  pkg_check_modules(PkgLibunbound IMPORTED_TARGET GLOBAL QUIET libunbound)
endif ()

if (PkgLibunbound_FOUND)
  set(LIBUNBOUND_INCLUDE_DIR ${PkgLibunbound_INCLUDE_DIRS} CACHE FILEPATH "libunbound include path")
  set(LIBUNBOUND_LIBRARIES ${PkgLibunbound_LIBRARIES} CACHE STRING "libunbound libraries")
  set(LIBUNBOUND_VERSION ${PkgLibunbound_VERSION})
  add_library(Libunbound::Libunbound ALIAS PkgConfig::PkgLibunbound)
  set(Libunbound_FOUND ON)
else ()
  find_path(LIBUNBOUND_INCLUDE_DIR unbound.h
    HINTS
    "${LIBUNBOUND_DIR}"
    "${LIBUNBOUND_DIR}/include"
  )
  
  find_library(LIBUNBOUND_LIBRARY NAMES unbound
    HINTS
    "${LIBUNBOUND_DIR}"
    "${LIBUNBOUND_DIR}/lib"
  )
  
  set(_LIBUNBOUND_LIBRARIES "")
  
  if (UNIX)
    find_package(Threads REQUIRED)
    find_package(OpenSSL REQUIRED)
  
    list(APPEND _LIBUNBOUND_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
    list(APPEND _LIBUNBOUND_LIBRARIES "${OPENSSL_LIBRARIES}")
  endif()
  
  if (LIBUNBOUND_INCLUDE_DIR AND LIBUNBOUND_LIBRARY)
    if (NOT TARGET Libunbound::Libunbound)
      add_library(Libunbound::Libunbound UNKNOWN IMPORTED)
      set_target_properties(Libunbound::Libunbound PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${LIBUNBOUND_INCLUDE_DIR}"
        IMPORTED_LINK_INTERFACE_LANGUAGES "C"
        IMPORTED_LOCATION "${LIBUNBOUND_LIBRARY}"
        )
  
      if(UNIX AND TARGET Threads::Threads)
        set_property(TARGET Libunbound::Libunbound APPEND PROPERTY
          INTERFACE_LINK_LIBRARIES Threads::Threads)
      endif ()
      if(UNIX AND TARGET OpenSSL::SSL)
        set_property(TARGET Libunbound::Libunbound APPEND PROPERTY
          INTERFACE_LINK_LIBRARIES OpenSSL::SSL)
      endif ()
      if(UNIX AND TARGET OpenSSL::Crypto)
        set_property(TARGET Libunbound::Libunbound APPEND PROPERTY
          INTERFACE_LINK_LIBRARIES OpenSSL::Crypto)
      endif ()
    endif ()
  
    if (NOT LIBUNBOUND_VERSION AND LIBUNBOUND_INCLUDE_DIR AND EXISTS "${LIBUNBOUND_INCLUDE_DIR}/unbound.h")
      file(STRINGS "${LIBUNBOUND_INCLUDE_DIR}/unbound.h" LIBUNBOUND_H REGEX "^#define UNBOUND_VERSION_M[A-Z]+")
      string(REGEX REPLACE "^.*MAJOR ([0-9]+).*MINOR ([0-9]+).*MICRO ([0-9]+).*$" "\\1.\\2.\\3" LIBUNBOUND_VERSION "${LIBUNBOUND_H}")
    endif ()
  endif ()
  
  list(APPEND _LIBUNBOUND_LIBRARIES "${LIBUNBOUND_LIBRARY}")
  set(LIBUNBOUND_LIBRARIES ${_LIBUNBOUND_LIBRARIES} CACHE STRING "libunbound libraries")

  include(FindPackageHandleStandardArgs)
  find_package_handle_standard_args(Libunbound
    REQUIRED_VARS LIBUNBOUND_LIBRARIES LIBUNBOUND_INCLUDE_DIR
    VERSION_VAR LIBUNBOUND_VERSION
    )
endif ()

mark_as_advanced(LIBUNBOUND_INCLUDE_DIR LIBUNBOUND_LIBRARIES LIBUNBOUND_LIBRARY)