xref: /curl/CMake/FindNGHTTP2.cmake (revision f66af623)
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 nghttp2 library
25#
26# Input variables:
27#
28# - `NGHTTP2_INCLUDE_DIR`:   The nghttp2 include directory.
29# - `NGHTTP2_LIBRARY`:       Path to `nghttp2` library.
30#
31# Result variables:
32#
33# - `NGHTTP2_FOUND`:         System has nghttp2.
34# - `NGHTTP2_INCLUDE_DIRS`:  The nghttp2 include directories.
35# - `NGHTTP2_LIBRARIES`:     The nghttp2 library names.
36# - `NGHTTP2_VERSION`:       Version of nghttp2.
37
38if(CURL_USE_PKGCONFIG)
39  find_package(PkgConfig QUIET)
40  pkg_check_modules(PC_NGHTTP2 "libnghttp2")
41endif()
42
43find_path(NGHTTP2_INCLUDE_DIR NAMES "nghttp2/nghttp2.h"
44  HINTS
45    ${PC_NGHTTP2_INCLUDEDIR}
46    ${PC_NGHTTP2_INCLUDE_DIRS}
47)
48
49find_library(NGHTTP2_LIBRARY NAMES "nghttp2" "nghttp2_static"
50  HINTS
51    ${PC_NGHTTP2_LIBDIR}
52    ${PC_NGHTTP2_LIBRARY_DIRS}
53)
54
55if(PC_NGHTTP2_VERSION)
56  set(NGHTTP2_VERSION ${PC_NGHTTP2_VERSION})
57elseif(NGHTTP2_INCLUDE_DIR AND EXISTS "${NGHTTP2_INCLUDE_DIR}/nghttp2/nghttp2ver.h")
58  set(_version_regex "#[\t ]*define[\t ]+NGHTTP2_VERSION[\t ]+\"([^\"]*)\"")
59  file(STRINGS "${NGHTTP2_INCLUDE_DIR}/nghttp2/nghttp2ver.h" _version_str REGEX "${_version_regex}")
60  string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
61  set(NGHTTP2_VERSION "${_version_str}")
62  unset(_version_regex)
63  unset(_version_str)
64endif()
65
66include(FindPackageHandleStandardArgs)
67find_package_handle_standard_args(NGHTTP2
68  REQUIRED_VARS
69    NGHTTP2_INCLUDE_DIR
70    NGHTTP2_LIBRARY
71  VERSION_VAR
72    NGHTTP2_VERSION
73)
74
75if(NGHTTP2_FOUND)
76  set(NGHTTP2_INCLUDE_DIRS ${NGHTTP2_INCLUDE_DIR})
77  set(NGHTTP2_LIBRARIES    ${NGHTTP2_LIBRARY})
78endif()
79
80mark_as_advanced(NGHTTP2_INCLUDE_DIR NGHTTP2_LIBRARY)
81