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
This commit is contained in:
Viktor Szakats 2024-07-09 11:39:48 +02:00
parent f518c73a87
commit 87aa4ebd82
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
2 changed files with 36 additions and 12 deletions

View File

@ -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)

View File

@ -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)