5757009a5675ef29d5d7d8dcbc6314e28cadaf16
[platform/upstream/cmake.git] / Utilities / cmcurl / CMake / FindNGTCP2.cmake
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.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:
24 FindNGTCP2
25 ----------
26
27 Find the ngtcp2 library
28
29 This module accepts optional COMPONENTS to control the crypto library (these are
30 mutually exclusive)::
31
32   OpenSSL:  Use libngtcp2_crypto_openssl
33   GnuTLS:   Use libngtcp2_crypto_gnutls
34
35 Result 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
48 if(UNIX)
49   find_package(PkgConfig QUIET)
50   pkg_search_module(PC_NGTCP2 libngtcp2)
51 endif()
52
53 find_path(NGTCP2_INCLUDE_DIR ngtcp2/ngtcp2.h
54   HINTS
55     ${PC_NGTCP2_INCLUDEDIR}
56     ${PC_NGTCP2_INCLUDE_DIRS}
57 )
58
59 find_library(NGTCP2_LIBRARY NAMES ngtcp2
60   HINTS
61     ${PC_NGTCP2_LIBDIR}
62     ${PC_NGTCP2_LIBRARY_DIRS}
63 )
64
65 if(PC_NGTCP2_VERSION)
66   set(NGTCP2_VERSION ${PC_NGTCP2_VERSION})
67 endif()
68
69 if(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()
97 endif()
98
99 include(FindPackageHandleStandardArgs)
100 find_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
108 if(NGTCP2_FOUND)
109   set(NGTCP2_LIBRARIES    ${NGTCP2_LIBRARY} ${NGTCP2_CRYPTO_LIBRARY})
110   set(NGTCP2_INCLUDE_DIRS ${NGTCP2_INCLUDE_DIR})
111 endif()
112
113 mark_as_advanced(NGTCP2_INCLUDE_DIRS NGTCP2_LIBRARIES)