FindNGTCP2.cmake (5100B)
1 #*************************************************************************** 2 # _ _ ____ _ 3 # Project ___| | | | _ \| | 4 # / __| | | | |_) | | 5 # | (__| |_| | _ <| |___ 6 # \___|\___/|_| \_\_____| 7 # 8 # Copyright (C) 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 # 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 # - `NGTCP2_CRYPTO_BORINGSSL_LIBRARY`: Path to `ngtcp2_crypto_boringssl` library. 40 # - `NGTCP2_CRYPTO_GNUTLS_LIBRARY`: Path to `ngtcp2_crypto_gnutls` library. 41 # - `NGTCP2_CRYPTO_OSSL_LIBRARY`: Path to `ngtcp2_crypto_ossl` library. 42 # - `NGTCP2_CRYPTO_QUICTLS_LIBRARY`: Path to `ngtcp2_crypto_quictls` library. 43 # - `NGTCP2_CRYPTO_WOLFSSL_LIBRARY`: Path to `ngtcp2_crypto_wolfssl` library. 44 # 45 # Result variables: 46 # 47 # - `NGTCP2_FOUND`: System has ngtcp2. 48 # - `NGTCP2_INCLUDE_DIRS`: The ngtcp2 include directories. 49 # - `NGTCP2_LIBRARIES`: The ngtcp2 library names. 50 # - `NGTCP2_LIBRARY_DIRS`: The ngtcp2 library directories. 51 # - `NGTCP2_PC_REQUIRES`: The ngtcp2 pkg-config packages. 52 # - `NGTCP2_CFLAGS`: Required compiler flags. 53 # - `NGTCP2_VERSION`: Version of ngtcp2. 54 55 if(NGTCP2_FIND_COMPONENTS) 56 set(_ngtcp2_crypto_backend "") 57 foreach(_component IN LISTS NGTCP2_FIND_COMPONENTS) 58 if(_component MATCHES "^(BoringSSL|GnuTLS|ossl|quictls|wolfSSL)") 59 if(_ngtcp2_crypto_backend) 60 message(FATAL_ERROR "NGTCP2: Only one crypto library can be selected") 61 endif() 62 set(_ngtcp2_crypto_backend ${_component}) 63 endif() 64 endforeach() 65 66 if(_ngtcp2_crypto_backend) 67 string(TOLOWER "ngtcp2_crypto_${_ngtcp2_crypto_backend}" _crypto_library_lower) 68 string(TOUPPER "ngtcp2_crypto_${_ngtcp2_crypto_backend}" _crypto_library_upper) 69 endif() 70 endif() 71 72 set(NGTCP2_PC_REQUIRES "libngtcp2") 73 if(_ngtcp2_crypto_backend) 74 list(APPEND NGTCP2_PC_REQUIRES "lib${_crypto_library_lower}") 75 endif() 76 77 if(CURL_USE_PKGCONFIG AND 78 NOT DEFINED NGTCP2_INCLUDE_DIR AND 79 NOT DEFINED NGTCP2_LIBRARY) 80 find_package(PkgConfig QUIET) 81 pkg_check_modules(NGTCP2 ${NGTCP2_PC_REQUIRES}) 82 endif() 83 84 if(NGTCP2_FOUND) 85 set(NGTCP2_VERSION "${NGTCP2_libngtcp2_VERSION}") 86 string(REPLACE ";" " " NGTCP2_CFLAGS "${NGTCP2_CFLAGS}") 87 message(STATUS "Found NGTCP2 (via pkg-config): ${NGTCP2_INCLUDE_DIRS} (found version \"${NGTCP2_VERSION}\")") 88 else() 89 find_path(NGTCP2_INCLUDE_DIR NAMES "ngtcp2/ngtcp2.h") 90 find_library(NGTCP2_LIBRARY NAMES "ngtcp2") 91 92 unset(NGTCP2_VERSION CACHE) 93 if(NGTCP2_INCLUDE_DIR AND EXISTS "${NGTCP2_INCLUDE_DIR}/ngtcp2/version.h") 94 set(_version_regex "#[\t ]*define[\t ]+NGTCP2_VERSION[\t ]+\"([^\"]*)\"") 95 file(STRINGS "${NGTCP2_INCLUDE_DIR}/ngtcp2/version.h" _version_str REGEX "${_version_regex}") 96 string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}") 97 set(NGTCP2_VERSION "${_version_str}") 98 unset(_version_regex) 99 unset(_version_str) 100 endif() 101 102 if(_ngtcp2_crypto_backend) 103 get_filename_component(_ngtcp2_library_dir "${NGTCP2_LIBRARY}" DIRECTORY) 104 find_library(${_crypto_library_upper}_LIBRARY NAMES ${_crypto_library_lower} HINTS ${_ngtcp2_library_dir}) 105 106 if(${_crypto_library_upper}_LIBRARY) 107 set(NGTCP2_${_ngtcp2_crypto_backend}_FOUND TRUE) 108 set(NGTCP2_CRYPTO_LIBRARY ${${_crypto_library_upper}_LIBRARY}) 109 endif() 110 endif() 111 112 include(FindPackageHandleStandardArgs) 113 find_package_handle_standard_args(NGTCP2 114 REQUIRED_VARS 115 NGTCP2_INCLUDE_DIR 116 NGTCP2_LIBRARY 117 VERSION_VAR 118 NGTCP2_VERSION 119 HANDLE_COMPONENTS 120 ) 121 122 if(NGTCP2_FOUND) 123 set(NGTCP2_INCLUDE_DIRS ${NGTCP2_INCLUDE_DIR}) 124 set(NGTCP2_LIBRARIES ${NGTCP2_LIBRARY} ${NGTCP2_CRYPTO_LIBRARY}) 125 endif() 126 127 mark_as_advanced(NGTCP2_INCLUDE_DIR NGTCP2_LIBRARY NGTCP2_CRYPTO_LIBRARY) 128 endif()