]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: detect `nghttp2` via `pkg-config`, enable by default
authorViktor Szakats <commit@vsz.me>
Tue, 9 Jul 2024 09:39:48 +0000 (11:39 +0200)
committerViktor Szakats <commit@vsz.me>
Sat, 3 Aug 2024 07:22:26 +0000 (09:22 +0200)
- 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
CMakeLists.txt

index 88ac0374176c38a905411db33ea7a34c76c99f37..81c11f21473ba4a5fc2ed93fbf48a34fc34dff42 100644 (file)
 # SPDX-License-Identifier: curl
 #
 ###########################################################################
-include(FindPackageHandleStandardArgs)
 
-find_path(NGHTTP2_INCLUDE_DIR "nghttp2/nghttp2.h")
+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}
+)
 
-find_library(NGHTTP2_LIBRARY NAMES nghttp2 nghttp2_static)
+if(PC_NGHTTP2_VERSION)
+  set(NGHTTP2_VERSION ${PC_NGHTTP2_VERSION})
+endif()
 
+include(FindPackageHandleStandardArgs)
 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)
index 990c745b5fc0f865e6b5cca06b3a795a737b9c5a..2b3663e9b002526c4dd530620fbe74a3596bc82f 100644 (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)