1*6236dae4SAndroid Build Coastguard Worker#*************************************************************************** 2*6236dae4SAndroid Build Coastguard Worker# _ _ ____ _ 3*6236dae4SAndroid Build Coastguard Worker# Project ___| | | | _ \| | 4*6236dae4SAndroid Build Coastguard Worker# / __| | | | |_) | | 5*6236dae4SAndroid Build Coastguard Worker# | (__| |_| | _ <| |___ 6*6236dae4SAndroid Build Coastguard Worker# \___|\___/|_| \_\_____| 7*6236dae4SAndroid Build Coastguard Worker# 8*6236dae4SAndroid Build Coastguard Worker# Copyright (C) Daniel Stenberg, <[email protected]>, et al. 9*6236dae4SAndroid Build Coastguard Worker# 10*6236dae4SAndroid Build Coastguard Worker# This software is licensed as described in the file COPYING, which 11*6236dae4SAndroid Build Coastguard Worker# you should have received as part of this distribution. The terms 12*6236dae4SAndroid Build Coastguard Worker# are also available at https://curl.se/docs/copyright.html. 13*6236dae4SAndroid Build Coastguard Worker# 14*6236dae4SAndroid Build Coastguard Worker# You may opt to use, copy, modify, merge, publish, distribute and/or sell 15*6236dae4SAndroid Build Coastguard Worker# copies of the Software, and permit persons to whom the Software is 16*6236dae4SAndroid Build Coastguard Worker# furnished to do so, under the terms of the COPYING file. 17*6236dae4SAndroid Build Coastguard Worker# 18*6236dae4SAndroid Build Coastguard Worker# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19*6236dae4SAndroid Build Coastguard Worker# KIND, either express or implied. 20*6236dae4SAndroid Build Coastguard Worker# 21*6236dae4SAndroid Build Coastguard Worker# SPDX-License-Identifier: curl 22*6236dae4SAndroid Build Coastguard Worker# 23*6236dae4SAndroid Build Coastguard Worker########################################################################### 24*6236dae4SAndroid Build Coastguard Worker# Find the ngtcp2 library 25*6236dae4SAndroid Build Coastguard Worker# 26*6236dae4SAndroid Build Coastguard Worker# This module accepts optional COMPONENTS to control the crypto library (these are 27*6236dae4SAndroid Build Coastguard Worker# mutually exclusive): 28*6236dae4SAndroid Build Coastguard Worker# 29*6236dae4SAndroid Build Coastguard Worker# - quictls: Use `libngtcp2_crypto_quictls`. (choose this for LibreSSL) 30*6236dae4SAndroid Build Coastguard Worker# - BoringSSL: Use `libngtcp2_crypto_boringssl`. (choose this for AWS-LC) 31*6236dae4SAndroid Build Coastguard Worker# - wolfSSL: Use `libngtcp2_crypto_wolfssl`. 32*6236dae4SAndroid Build Coastguard Worker# - GnuTLS: Use `libngtcp2_crypto_gnutls`. 33*6236dae4SAndroid Build Coastguard Worker# 34*6236dae4SAndroid Build Coastguard Worker# Input variables: 35*6236dae4SAndroid Build Coastguard Worker# 36*6236dae4SAndroid Build Coastguard Worker# - `NGTCP2_INCLUDE_DIR`: The ngtcp2 include directory. 37*6236dae4SAndroid Build Coastguard Worker# - `NGTCP2_LIBRARY`: Path to `ngtcp2` library. 38*6236dae4SAndroid Build Coastguard Worker# 39*6236dae4SAndroid Build Coastguard Worker# Result variables: 40*6236dae4SAndroid Build Coastguard Worker# 41*6236dae4SAndroid Build Coastguard Worker# - `NGTCP2_FOUND`: System has ngtcp2. 42*6236dae4SAndroid Build Coastguard Worker# - `NGTCP2_INCLUDE_DIRS`: The ngtcp2 include directories. 43*6236dae4SAndroid Build Coastguard Worker# - `NGTCP2_LIBRARIES`: The ngtcp2 library names. 44*6236dae4SAndroid Build Coastguard Worker# - `NGTCP2_VERSION`: Version of ngtcp2. 45*6236dae4SAndroid Build Coastguard Worker 46*6236dae4SAndroid Build Coastguard Workerif(CURL_USE_PKGCONFIG) 47*6236dae4SAndroid Build Coastguard Worker find_package(PkgConfig QUIET) 48*6236dae4SAndroid Build Coastguard Worker pkg_check_modules(PC_NGTCP2 "libngtcp2") 49*6236dae4SAndroid Build Coastguard Workerendif() 50*6236dae4SAndroid Build Coastguard Worker 51*6236dae4SAndroid Build Coastguard Workerfind_path(NGTCP2_INCLUDE_DIR NAMES "ngtcp2/ngtcp2.h" 52*6236dae4SAndroid Build Coastguard Worker HINTS 53*6236dae4SAndroid Build Coastguard Worker ${PC_NGTCP2_INCLUDEDIR} 54*6236dae4SAndroid Build Coastguard Worker ${PC_NGTCP2_INCLUDE_DIRS} 55*6236dae4SAndroid Build Coastguard Worker) 56*6236dae4SAndroid Build Coastguard Worker 57*6236dae4SAndroid Build Coastguard Workerfind_library(NGTCP2_LIBRARY NAMES "ngtcp2" 58*6236dae4SAndroid Build Coastguard Worker HINTS 59*6236dae4SAndroid Build Coastguard Worker ${PC_NGTCP2_LIBDIR} 60*6236dae4SAndroid Build Coastguard Worker ${PC_NGTCP2_LIBRARY_DIRS} 61*6236dae4SAndroid Build Coastguard Worker) 62*6236dae4SAndroid Build Coastguard Worker 63*6236dae4SAndroid Build Coastguard Workerif(PC_NGTCP2_VERSION) 64*6236dae4SAndroid Build Coastguard Worker set(NGTCP2_VERSION ${PC_NGTCP2_VERSION}) 65*6236dae4SAndroid Build Coastguard Workerelseif(NGTCP2_INCLUDE_DIR AND EXISTS "${NGTCP2_INCLUDE_DIR}/ngtcp2/version.h") 66*6236dae4SAndroid Build Coastguard Worker set(_version_regex "#[\t ]*define[\t ]+NGTCP2_VERSION[\t ]+\"([^\"]*)\"") 67*6236dae4SAndroid Build Coastguard Worker file(STRINGS "${NGTCP2_INCLUDE_DIR}/ngtcp2/version.h" _version_str REGEX "${_version_regex}") 68*6236dae4SAndroid Build Coastguard Worker string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}") 69*6236dae4SAndroid Build Coastguard Worker set(NGTCP2_VERSION "${_version_str}") 70*6236dae4SAndroid Build Coastguard Worker unset(_version_regex) 71*6236dae4SAndroid Build Coastguard Worker unset(_version_str) 72*6236dae4SAndroid Build Coastguard Workerendif() 73*6236dae4SAndroid Build Coastguard Worker 74*6236dae4SAndroid Build Coastguard Workerif(NGTCP2_FIND_COMPONENTS) 75*6236dae4SAndroid Build Coastguard Worker set(_ngtcp2_crypto_backend "") 76*6236dae4SAndroid Build Coastguard Worker foreach(_component IN LISTS NGTCP2_FIND_COMPONENTS) 77*6236dae4SAndroid Build Coastguard Worker if(_component MATCHES "^(BoringSSL|quictls|wolfSSL|GnuTLS)") 78*6236dae4SAndroid Build Coastguard Worker if(_ngtcp2_crypto_backend) 79*6236dae4SAndroid Build Coastguard Worker message(FATAL_ERROR "NGTCP2: Only one crypto library can be selected") 80*6236dae4SAndroid Build Coastguard Worker endif() 81*6236dae4SAndroid Build Coastguard Worker set(_ngtcp2_crypto_backend ${_component}) 82*6236dae4SAndroid Build Coastguard Worker endif() 83*6236dae4SAndroid Build Coastguard Worker endforeach() 84*6236dae4SAndroid Build Coastguard Worker 85*6236dae4SAndroid Build Coastguard Worker if(_ngtcp2_crypto_backend) 86*6236dae4SAndroid Build Coastguard Worker string(TOLOWER "ngtcp2_crypto_${_ngtcp2_crypto_backend}" _crypto_library) 87*6236dae4SAndroid Build Coastguard Worker 88*6236dae4SAndroid Build Coastguard Worker if(CURL_USE_PKGCONFIG) 89*6236dae4SAndroid Build Coastguard Worker pkg_check_modules(PC_${_crypto_library} "lib${_crypto_library}") 90*6236dae4SAndroid Build Coastguard Worker endif() 91*6236dae4SAndroid Build Coastguard Worker 92*6236dae4SAndroid Build Coastguard Worker get_filename_component(_ngtcp2_library_dir "${NGTCP2_LIBRARY}" DIRECTORY) 93*6236dae4SAndroid Build Coastguard Worker find_library(${_crypto_library}_LIBRARY NAMES ${_crypto_library} 94*6236dae4SAndroid Build Coastguard Worker HINTS 95*6236dae4SAndroid Build Coastguard Worker ${_ngtcp2_library_dir} 96*6236dae4SAndroid Build Coastguard Worker ${PC_${_crypto_library}_LIBDIR} 97*6236dae4SAndroid Build Coastguard Worker ${PC_${_crypto_library}_LIBRARY_DIRS} 98*6236dae4SAndroid Build Coastguard Worker ) 99*6236dae4SAndroid Build Coastguard Worker 100*6236dae4SAndroid Build Coastguard Worker if(${_crypto_library}_LIBRARY) 101*6236dae4SAndroid Build Coastguard Worker set(NGTCP2_${_ngtcp2_crypto_backend}_FOUND TRUE) 102*6236dae4SAndroid Build Coastguard Worker set(NGTCP2_CRYPTO_LIBRARY ${${_crypto_library}_LIBRARY}) 103*6236dae4SAndroid Build Coastguard Worker endif() 104*6236dae4SAndroid Build Coastguard Worker endif() 105*6236dae4SAndroid Build Coastguard Workerendif() 106*6236dae4SAndroid Build Coastguard Worker 107*6236dae4SAndroid Build Coastguard Workerinclude(FindPackageHandleStandardArgs) 108*6236dae4SAndroid Build Coastguard Workerfind_package_handle_standard_args(NGTCP2 109*6236dae4SAndroid Build Coastguard Worker REQUIRED_VARS 110*6236dae4SAndroid Build Coastguard Worker NGTCP2_INCLUDE_DIR 111*6236dae4SAndroid Build Coastguard Worker NGTCP2_LIBRARY 112*6236dae4SAndroid Build Coastguard Worker VERSION_VAR 113*6236dae4SAndroid Build Coastguard Worker NGTCP2_VERSION 114*6236dae4SAndroid Build Coastguard Worker HANDLE_COMPONENTS 115*6236dae4SAndroid Build Coastguard Worker) 116*6236dae4SAndroid Build Coastguard Worker 117*6236dae4SAndroid Build Coastguard Workerif(NGTCP2_FOUND) 118*6236dae4SAndroid Build Coastguard Worker set(NGTCP2_INCLUDE_DIRS ${NGTCP2_INCLUDE_DIR}) 119*6236dae4SAndroid Build Coastguard Worker set(NGTCP2_LIBRARIES ${NGTCP2_LIBRARY} ${NGTCP2_CRYPTO_LIBRARY}) 120*6236dae4SAndroid Build Coastguard Workerendif() 121*6236dae4SAndroid Build Coastguard Worker 122*6236dae4SAndroid Build Coastguard Workermark_as_advanced(NGTCP2_INCLUDE_DIR NGTCP2_LIBRARY NGTCP2_CRYPTO_LIBRARY) 123