File: FindLibidn2.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 (77 lines) | stat: -rw-r--r-- 2,341 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
#[=======================================================================[.rst:
FindLibidn2
-----------

Find the Libidn2 library

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

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

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

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

This module will set the following variables in your project:

``Libidn2_FOUND``
  If false, do not try to use Libidn2.
``LIBIDN2_INCLUDE_DIR``
  where to find libidn2 headers.
``LIBIDN2_LIBRARIES``
  the libraries needed to use Libidn2.
``LIBIDN2_VERSION``
  the version of the Libidn2 library found

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

find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
    pkg_check_modules(PkgLibIdn2 IMPORTED_TARGET GLOBAL libidn2)
endif ()

if (PkgLibIdn2_FOUND)
  set(LIBIDN2_INCLUDE_DIR ${PkgLibIdn2_INCLUDE_DIRS} CACHE FILEPATH "libidn2 include path")
  set(LIBIDN2_LIBRARIES ${PkgLibIdn2_LIBRARIES} CACHE STRING "libidn2 libraries")
  set(LIBIDN2_VERSION ${PkgLibIdn2_VERSION})
  add_library(Libidn2::Libidn2 ALIAS PkgConfig::PkgLibIdn2)
  set(Libidn2_FOUND ON)
else ()
  find_path(LIBIDN2_INCLUDE_DIR idn2.h
    HINTS
      "${LIBIDN2_DIR}"
      "${LIBIDN2_DIR}/include"
  )

  find_library(LIBIDN2_LIBRARIES NAMES idn2 libidn2
    HINTS
      "${LIBIDN2_DIR}"
      "${LIBIDN2_DIR}/lib"
  )

  if (LIBIDN2_INCLUDE_DIR AND LIBIDN2_LIBRARIES)
    if (NOT TARGET Libidn2::Libidn2)
      add_library(Libidn2::Libidn2 UNKNOWN IMPORTED)
      set_target_properties(Libidn2::Libidn2 PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${LIBIDN2_INCLUDE_DIR}"
        IMPORTED_LINK_INTERFACE_LANGUAGES "C"
        IMPORTED_LOCATION "${LIBIDN2_LIBRARIES}"
      )
    endif ()

    if (NOT LIBIDN2_VERSION AND LIBIDN2_INCLUDE_DIR AND EXISTS "${LIBIDN2_INCLUDE_DIR}/idn2.h")
      file(STRINGS "${LIBIDN2_INCLUDE_DIR}/idn2.h" LIBIDN2_H REGEX "^[ \t]*#[ \t]*define[ \t]+IDN2_VERSION[ \t]")
      string(REGEX REPLACE "^.*IDN2_VERSION[ \t]+\"([0-9.]+)\".*$" "\\1" LIBIDN2_VERSION "${LIBIDN2_H}")
    endif ()
  endif ()
  include(FindPackageHandleStandardArgs)
  find_package_handle_standard_args(Libidn2
    REQUIRED_VARS LIBIDN2_LIBRARIES LIBIDN2_INCLUDE_DIR
    VERSION_VAR LIBIDN2_VERSION
  )
endif ()

mark_as_advanced(LIBIDN2_INCLUDE_DIR LIBIDN2_LIBRARIES)