Debian Codegraph @

extra/curl/curl-8.14.1/CMake/FindNGTCP2.cmake

raw
1 #***************************************************************************
2 # _ _ ____ _
3 # Project ___| | | | _ \| |
4 # / __| | | | |_) | |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) Daniel Stenberg, <[email protected]>, 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 # SPDX-License-Identifier: curl
22 #
23 ###########################################################################
24 # Find the ngtcp2 library
25 #
26 # This module accepts optional COMPONENTS to control the crypto library (these are
27 # mutually exclusive):
28 #
29 # - quictls: Use `libngtcp2_crypto_quictls`. (choose this for LibreSSL)
30 # - BoringSSL: Use `libngtcp2_crypto_boringssl`. (choose this for AWS-LC)
31 # - wolfSSL: Use `libngtcp2_crypto_wolfssl`.
32 # - GnuTLS: Use `libngtcp2_crypto_gnutls`.
33 # - ossl: Use `libngtcp2_crypto_ossl`.
34 #
35 # Input variables:
36 #
37 # - `NGTCP2_INCLUDE_DIR`: The ngtcp2 include directory.
38 # - `NGTCP2_LIBRARY`: Path to `ngtcp2` library.
39 #
40 # Result variables:
41 #
42 # - `NGTCP2_FOUND`: System has ngtcp2.
43 # - `NGTCP2_INCLUDE_DIRS`: The ngtcp2 include directories.
44 # - `NGTCP2_LIBRARIES`: The ngtcp2 library names.
45 # - `NGTCP2_LIBRARY_DIRS`: The ngtcp2 library directories.
46 # - `NGTCP2_PC_REQUIRES`: The ngtcp2 pkg-config packages.
47 # - `NGTCP2_CFLAGS`: Required compiler flags.
48 # - `NGTCP2_VERSION`: Version of ngtcp2.
49
50 if(NGTCP2_FIND_COMPONENTS)
51 set(_ngtcp2_crypto_backend "")
52 foreach(_component IN LISTS NGTCP2_FIND_COMPONENTS)
53 if(_component MATCHES "^(BoringSSL|quictls|wolfSSL|GnuTLS|ossl)")
54 if(_ngtcp2_crypto_backend)
55 message(FATAL_ERROR "NGTCP2: Only one crypto library can be selected")
56 endif()
57 set(_ngtcp2_crypto_backend ${_component})
58 endif()
59 endforeach()
60
61 if(_ngtcp2_crypto_backend)
62 string(TOLOWER "ngtcp2_crypto_${_ngtcp2_crypto_backend}" _crypto_library_lower)
63 string(TOUPPER "ngtcp2_crypto_${_ngtcp2_crypto_backend}" _crypto_library_upper)
64 endif()
65 endif()
66
67 set(NGTCP2_PC_REQUIRES "libngtcp2")
68 if(_ngtcp2_crypto_backend)
69 list(APPEND NGTCP2_PC_REQUIRES "lib${_crypto_library_lower}")
70 endif()
71
72 if(CURL_USE_PKGCONFIG AND
73 NOT DEFINED NGTCP2_INCLUDE_DIR AND
74 NOT DEFINED NGTCP2_LIBRARY)
75 find_package(PkgConfig QUIET)
76 pkg_check_modules(NGTCP2 ${NGTCP2_PC_REQUIRES})
77 endif()
78
79 if(NGTCP2_FOUND)
80 set(NGTCP2_VERSION "${NGTCP2_libngtcp2_VERSION}")
81 string(REPLACE ";" " " NGTCP2_CFLAGS "${NGTCP2_CFLAGS}")
82 message(STATUS "Found NGTCP2 (via pkg-config): ${NGTCP2_INCLUDE_DIRS} (found version \"${NGTCP2_VERSION}\")")
83 else()
84 find_path(NGTCP2_INCLUDE_DIR NAMES "ngtcp2/ngtcp2.h")
85 find_library(NGTCP2_LIBRARY NAMES "ngtcp2")
86
87 unset(NGTCP2_VERSION CACHE)
88 if(NGTCP2_INCLUDE_DIR AND EXISTS "${NGTCP2_INCLUDE_DIR}/ngtcp2/version.h")
89 set(_version_regex "#[\t ]*define[\t ]+NGTCP2_VERSION[\t ]+\"([^\"]*)\"")
90 file(STRINGS "${NGTCP2_INCLUDE_DIR}/ngtcp2/version.h" _version_str REGEX "${_version_regex}")
91 string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
92 set(NGTCP2_VERSION "${_version_str}")
93 unset(_version_regex)
94 unset(_version_str)
95 endif()
96
97 if(_ngtcp2_crypto_backend)
98 get_filename_component(_ngtcp2_library_dir "${NGTCP2_LIBRARY}" DIRECTORY)
99 find_library(${_crypto_library_upper}_LIBRARY NAMES ${_crypto_library_lower} HINTS ${_ngtcp2_library_dir})
100
101 if(${_crypto_library_upper}_LIBRARY)
102 set(NGTCP2_${_ngtcp2_crypto_backend}_FOUND TRUE)
103 set(NGTCP2_CRYPTO_LIBRARY ${${_crypto_library_upper}_LIBRARY})
104 endif()
105 endif()
106
107 include(FindPackageHandleStandardArgs)
108 find_package_handle_standard_args(NGTCP2
109 REQUIRED_VARS
110 NGTCP2_INCLUDE_DIR
111 NGTCP2_LIBRARY
112 VERSION_VAR
113 NGTCP2_VERSION
114 HANDLE_COMPONENTS
115 )
116
117 if(NGTCP2_FOUND)
118 set(NGTCP2_INCLUDE_DIRS ${NGTCP2_INCLUDE_DIR})
119 set(NGTCP2_LIBRARIES ${NGTCP2_LIBRARY} ${NGTCP2_CRYPTO_LIBRARY})
120 endif()
121
122 mark_as_advanced(NGTCP2_INCLUDE_DIR NGTCP2_LIBRARY NGTCP2_CRYPTO_LIBRARY)
123 endif()