From 87aa4ebd821ebae0023df8658360c724efcf5e00 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 9 Jul 2024 11:39:48 +0200 Subject: [PATCH] cmake: detect `nghttp2` via `pkg-config`, enable by default - also detect nghttp2 via `pkg-config` to match nghttp3 detection and autotools. - enable nghttp2 by default to match autotools. Cherry-picked from #14097 Closes #14136 --- CMake/FindNGHTTP2.cmake | 34 +++++++++++++++++++++++++++------- CMakeLists.txt | 14 +++++++++----- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/CMake/FindNGHTTP2.cmake b/CMake/FindNGHTTP2.cmake index 88ac037417..81c11f2147 100644 --- a/CMake/FindNGHTTP2.cmake +++ b/CMake/FindNGHTTP2.cmake @@ -21,21 +21,41 @@ # SPDX-License-Identifier: curl # ########################################################################### + +if(UNIX) + find_package(PkgConfig QUIET) + pkg_search_module(PC_NGHTTP2 "libnghttp2") +endif() + +find_path(NGHTTP2_INCLUDE_DIR "nghttp2/nghttp2.h" + HINTS + ${PC_NGHTTP2_INCLUDEDIR} + ${PC_NGHTTP2_INCLUDE_DIRS} +) + +find_library(NGHTTP2_LIBRARY NAMES "nghttp2" "nghttp2_static" + HINTS + ${PC_NGHTTP2_LIBDIR} + ${PC_NGHTTP2_LIBRARY_DIRS} +) + +if(PC_NGHTTP2_VERSION) + set(NGHTTP2_VERSION ${PC_NGHTTP2_VERSION}) +endif() + include(FindPackageHandleStandardArgs) - -find_path(NGHTTP2_INCLUDE_DIR "nghttp2/nghttp2.h") - -find_library(NGHTTP2_LIBRARY NAMES nghttp2 nghttp2_static) - find_package_handle_standard_args(NGHTTP2 FOUND_VAR NGHTTP2_FOUND REQUIRED_VARS NGHTTP2_LIBRARY NGHTTP2_INCLUDE_DIR + VERSION_VAR NGHTTP2_VERSION ) -set(NGHTTP2_INCLUDE_DIRS ${NGHTTP2_INCLUDE_DIR}) -set(NGHTTP2_LIBRARIES ${NGHTTP2_LIBRARY}) +if(NGHTTP2_FOUND) + set(NGHTTP2_INCLUDE_DIRS ${NGHTTP2_INCLUDE_DIR}) + set(NGHTTP2_LIBRARIES ${NGHTTP2_LIBRARY}) +endif() mark_as_advanced(NGHTTP2_INCLUDE_DIRS NGHTTP2_LIBRARIES) diff --git a/CMakeLists.txt b/CMakeLists.txt index 990c745b5f..2b3663e9b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -701,12 +701,16 @@ if(USE_ECH) endif() endif() -option(USE_NGHTTP2 "Use nghttp2 library" OFF) +option(USE_NGHTTP2 "Use nghttp2 library" ON) if(USE_NGHTTP2) - find_package(NGHTTP2 REQUIRED) - include_directories(${NGHTTP2_INCLUDE_DIRS}) - list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES}) - list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libnghttp2") + find_package(NGHTTP2) + if(NGHTTP2_FOUND) + include_directories(${NGHTTP2_INCLUDE_DIRS}) + list(APPEND CURL_LIBS ${NGHTTP2_LIBRARIES}) + list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libnghttp2") + else() + set(USE_NGHTTP2 OFF) + endif() endif() option(USE_NGTCP2 "Use ngtcp2 and nghttp3 libraries for HTTP/3 support" OFF)