1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.haxx.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21###########################################################################
22
23#[=======================================================================[.rst:
24FindNGTCP2
25----------
26
27Find the ngtcp2 library
28
29This module accepts optional COMPONENTS to control the crypto library (these are
30mutually exclusive)::
31
32  OpenSSL:  Use libngtcp2_crypto_openssl
33  GnuTLS:   Use libngtcp2_crypto_gnutls
34
35Result Variables
36^^^^^^^^^^^^^^^^
37
38``NGTCP2_FOUND``
39  System has ngtcp2
40``NGTCP2_INCLUDE_DIRS``
41  The ngtcp2 include directories.
42``NGTCP2_LIBRARIES``
43  The libraries needed to use ngtcp2
44``NGTCP2_VERSION``
45  version of ngtcp2.
46#]=======================================================================]
47
48if(UNIX)
49  find_package(PkgConfig QUIET)
50  pkg_search_module(PC_NGTCP2 libngtcp2)
51endif()
52
53find_path(NGTCP2_INCLUDE_DIR ngtcp2/ngtcp2.h
54  HINTS
55    ${PC_NGTCP2_INCLUDEDIR}
56    ${PC_NGTCP2_INCLUDE_DIRS}
57)
58
59find_library(NGTCP2_LIBRARY NAMES ngtcp2
60  HINTS
61    ${PC_NGTCP2_LIBDIR}
62    ${PC_NGTCP2_LIBRARY_DIRS}
63)
64
65if(PC_NGTCP2_VERSION)
66  set(NGTCP2_VERSION ${PC_NGTCP2_VERSION})
67endif()
68
69if(NGTCP2_FIND_COMPONENTS)
70  set(NGTCP2_CRYPTO_BACKEND "")
71  foreach(component IN LISTS NGTCP2_FIND_COMPONENTS)
72    if(component MATCHES "^(OpenSSL|GnuTLS)")
73      if(NGTCP2_CRYPTO_BACKEND)
74        message(FATAL_ERROR "NGTCP2: Only one crypto library can be selected")
75      endif()
76      set(NGTCP2_CRYPTO_BACKEND ${component})
77    endif()
78  endforeach()
79
80  if(NGTCP2_CRYPTO_BACKEND)
81    string(TOLOWER "ngtcp2_crypto_${NGTCP2_CRYPTO_BACKEND}" _crypto_library)
82    if(UNIX)
83      pkg_search_module(PC_${_crypto_library} lib${_crypto_library})
84    endif()
85    find_library(${_crypto_library}_LIBRARY
86      NAMES
87        ${_crypto_library}
88      HINTS
89        ${PC_${_crypto_library}_LIBDIR}
90        ${PC_${_crypto_library}_LIBRARY_DIRS}
91    )
92    if(${_crypto_library}_LIBRARY)
93      set(NGTCP2_${NGTCP2_CRYPTO_BACKEND}_FOUND TRUE)
94      set(NGTCP2_CRYPTO_LIBRARY ${${_crypto_library}_LIBRARY})
95    endif()
96  endif()
97endif()
98
99include(FindPackageHandleStandardArgs)
100find_package_handle_standard_args(NGTCP2
101  REQUIRED_VARS
102    NGTCP2_LIBRARY
103    NGTCP2_INCLUDE_DIR
104  VERSION_VAR NGTCP2_VERSION
105  HANDLE_COMPONENTS
106)
107
108if(NGTCP2_FOUND)
109  set(NGTCP2_LIBRARIES    ${NGTCP2_LIBRARY} ${NGTCP2_CRYPTO_LIBRARY})
110  set(NGTCP2_INCLUDE_DIRS ${NGTCP2_INCLUDE_DIR})
111endif()
112
113mark_as_advanced(NGTCP2_INCLUDE_DIRS NGTCP2_LIBRARIES)
114