]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: add `CURL_USE_PKGCONFIG` option
authorViktor Szakats <commit@vsz.me>
Mon, 12 Aug 2024 13:35:50 +0000 (15:35 +0200)
committerViktor Szakats <commit@vsz.me>
Tue, 13 Aug 2024 07:28:27 +0000 (09:28 +0200)
Add option to control whether to use `pkg-config` to detect
dependencies. Curl's CMake uses `pkg-config` by default for all targets
except for MSVC without vcpkg.

With the CMake option `-DCURL_USE_PKGCONFIG=ON` you can override it to
use `pkg-config` always.

If `pkg-config` is causing issues, e.g. in cross-builds or other cases,
`-DCURL_USE_PKGCONFIG=OFF` disables all use of `pkg-config`.

Also add it to `curl-config.cmake`. Not yet used, but will be once curl
starts referencing any curl-specific `Find*` module from this public
script.

Follow-up to 9dfdc6ff42ba045ec48056bb6d2072f2fcac2e9d #14483
Closes #14504

CMake/FindGSS.cmake
CMake/FindMSH3.cmake
CMake/FindNGHTTP2.cmake
CMake/FindNGHTTP3.cmake
CMake/FindNGTCP2.cmake
CMake/FindNettle.cmake
CMake/FindQUICHE.cmake
CMake/FindWolfSSL.cmake
CMake/FindZstd.cmake
CMake/curl-config.cmake.in
CMakeLists.txt

index 07e4fd0444f24ca54aac60463c7f75446d134762..83a9fc2d6f61a6e71450ee72a21fb8eaaa0fb8fb 100644 (file)
@@ -53,7 +53,7 @@ set(_gss_root_hints
 
 # Try to find library using system pkg-config if user did not specify root dir
 if(NOT GSS_ROOT_DIR AND NOT "$ENV{GSS_ROOT_DIR}")
-  if(NOT MSVC OR VCPKG_TOOLCHAIN)
+  if(CURL_USE_PKGCONFIG)
     find_package(PkgConfig QUIET)
     pkg_search_module(_GSS ${_mit_modname} ${_heimdal_modname})
     list(APPEND _gss_root_hints "${_GSS_PREFIX}")
index 59e8c31dbbdb9b270996ae0f88e71b94be7bb57a..56dc2a39effdad91dff4a8b4185e952e3fa39ccb 100644 (file)
@@ -29,7 +29,7 @@
 # MSH3_INCLUDE_DIRS  The msh3 include directories
 # MSH3_LIBRARIES     The libraries needed to use msh3
 
-if(NOT MSVC OR VCPKG_TOOLCHAIN)
+if(CURL_USE_PKGCONFIG)
   find_package(PkgConfig QUIET)
   pkg_search_module(PC_MSH3 "libmsh3")
 endif()
index deb81bdadb2143b0836cca971bdedf6042616172..c60cda75988733959a68497a355ddb29659d9959 100644 (file)
@@ -30,7 +30,7 @@
 # NGHTTP2_LIBRARIES     The libraries needed to use nghttp2
 # NGHTTP2_VERSION       Version of nghttp2
 
-if(NOT MSVC OR VCPKG_TOOLCHAIN)
+if(CURL_USE_PKGCONFIG)
   find_package(PkgConfig QUIET)
   pkg_search_module(PC_NGHTTP2 "libnghttp2")
 endif()
index cf210e1795ebd4b88058ff598da261fdbd26f6a9..ee1708e0c78d4fd3067b9f01ce70b33b86822f25 100644 (file)
@@ -30,7 +30,7 @@
 # NGHTTP3_LIBRARIES     The libraries needed to use nghttp3
 # NGHTTP3_VERSION       Version of nghttp3
 
-if(NOT MSVC OR VCPKG_TOOLCHAIN)
+if(CURL_USE_PKGCONFIG)
   find_package(PkgConfig QUIET)
   pkg_search_module(PC_NGHTTP3 "libnghttp3")
 endif()
index 3ebf3b91b4def946faf0fe914bc00224ec71f07c..228713d578c5153f5d199d0108cec42cbe0ca6d7 100644 (file)
@@ -38,7 +38,7 @@
 # NGTCP2_LIBRARIES     The libraries needed to use ngtcp2
 # NGTCP2_VERSION       Version of ngtcp2
 
-if(NOT MSVC OR VCPKG_TOOLCHAIN)
+if(CURL_USE_PKGCONFIG)
   find_package(PkgConfig QUIET)
   pkg_search_module(PC_NGTCP2 "libngtcp2")
 endif()
@@ -72,7 +72,7 @@ if(NGTCP2_FIND_COMPONENTS)
 
   if(NGTCP2_CRYPTO_BACKEND)
     string(TOLOWER "ngtcp2_crypto_${NGTCP2_CRYPTO_BACKEND}" _crypto_library)
-    if(NOT MSVC OR VCPKG_TOOLCHAIN)
+    if(CURL_USE_PKGCONFIG)
       pkg_search_module(PC_${_crypto_library} "lib${_crypto_library}")
     endif()
     find_library(${_crypto_library}_LIBRARY
index 02ae13f331494c39df1e7c9a24ffa9a98577547e..a61c61d9dfdd607dc2f0e7c5495b5f237545d152 100644 (file)
@@ -30,7 +30,7 @@
 # NETTLE_LIBRARIES     The nettle library names
 # NETTLE_VERSION       Version of nettle
 
-if(NOT MSVC OR VCPKG_TOOLCHAIN)
+if(CURL_USE_PKGCONFIG)
   find_package(PkgConfig QUIET)
   pkg_search_module(NETTLE "nettle")
 endif()
index bcd54e942dc5a2628c1f414ed352acd2bebae9f9..e7ebb2b992713a26e691079ec0fc3c87b4ef0c27 100644 (file)
@@ -29,7 +29,7 @@
 # QUICHE_INCLUDE_DIRS  The quiche include directories
 # QUICHE_LIBRARIES     The libraries needed to use quiche
 
-if(NOT MSVC OR VCPKG_TOOLCHAIN)
+if(CURL_USE_PKGCONFIG)
   find_package(PkgConfig QUIET)
   pkg_search_module(PC_QUICHE "quiche")
 endif()
index 1e9437ffbaf8c45bc6b370650834f17b794cdf17..0c9d9de4f2ac8f3903332aa36ad98ff437f4d63b 100644 (file)
@@ -30,7 +30,7 @@
 # WolfSSL_LIBRARIES     The wolfssl library names
 # WolfSSL_VERSION       Version of wolfssl
 
-if(NOT MSVC OR VCPKG_TOOLCHAIN)
+if(CURL_USE_PKGCONFIG)
   find_package(PkgConfig QUIET)
   pkg_search_module(PC_WOLFSSL QUIET "wolfssl")
 endif()
index 6574d0896c31f239fe3d1454097c9a8b12a666be..1d5c271c8a89a5138ae983d2e786d368d17675f8 100644 (file)
@@ -30,7 +30,7 @@
 # Zstd_LIBRARIES     The libraries needed to use zstd
 # Zstd_VERSION       Version of zstd
 
-if(NOT MSVC OR VCPKG_TOOLCHAIN)
+if(CURL_USE_PKGCONFIG)
   find_package(PkgConfig QUIET)
   pkg_search_module(PC_Zstd "libzstd")
 endif()
index 2ce8625ef90b3d0b4023c7582d3c8fe7c7e09ba8..5be5d7103a0eaccadfd8a6673726ef2d55d743c1 100644 (file)
 ###########################################################################
 @PACKAGE_INIT@
 
+if(NOT DEFINED CURL_USE_PKGCONFIG)
+  if(NOT MSVC OR VCPKG_TOOLCHAIN)
+    set(CURL_USE_PKGCONFIG ON)
+  else()
+    set(CURL_USE_PKGCONFIG OFF)
+  endif()
+endif()
+
 include(CMakeFindDependencyMacro)
 if(@USE_OPENSSL@)
   find_dependency(OpenSSL @OPENSSL_VERSION_MAJOR@)
index bccd01e9fe6a5199ca1269392c504470789042c7..973c78f24b73a3864d9c11c840fd396d5a2a0331 100644 (file)
@@ -201,6 +201,14 @@ else()
   set(LIB_SELECTED ${LIB_STATIC})
 endif()
 
+# Override to force-disable or force-enable the use of pkg-config.
+if(NOT MSVC OR VCPKG_TOOLCHAIN)
+  set(_curl_use_pkgconfig_default ON)
+else()
+  set(_curl_use_pkgconfig_default OFF)
+endif()
+option(CURL_USE_PKGCONFIG "use pkg-config to detect dependencies" ${_curl_use_pkgconfig_default})
+
 # Initialize CURL_LIBS
 set(CURL_LIBS "")
 set(LIBCURL_PC_REQUIRES_PRIVATE "")
@@ -959,7 +967,7 @@ if(USE_LIBIDN2)
     check_include_file_concat("idn2.h" HAVE_IDN2_H)
   endif()
   if(NOT HAVE_LIBIDN2 OR NOT HAVE_IDN2_H)
-    if(NOT MSVC OR VCPKG_TOOLCHAIN)
+    if(CURL_USE_PKGCONFIG)
       find_package(PkgConfig QUIET)
       pkg_search_module(LIBIDN2 "libidn2")
     endif()
@@ -1038,7 +1046,7 @@ if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
   find_package(libssh CONFIG QUIET)
   if(libssh_FOUND)
     message(STATUS "Found libssh ${libssh_VERSION}")
-  elseif(NOT MSVC OR VCPKG_TOOLCHAIN)
+  elseif(CURL_USE_PKGCONFIG)
     find_package(PkgConfig QUIET)
     pkg_search_module(LIBSSH "libssh")
     if(LIBSSH_FOUND)
@@ -1058,7 +1066,7 @@ endif()
 option(CURL_USE_GSASL "Use GSASL implementation" OFF)
 mark_as_advanced(CURL_USE_GSASL)
 if(CURL_USE_GSASL)
-  if(NOT MSVC OR VCPKG_TOOLCHAIN)
+  if(CURL_USE_PKGCONFIG)
     find_package(PkgConfig REQUIRED)
     pkg_search_module(GSASL REQUIRED "libgsasl")
   else()
@@ -1139,7 +1147,7 @@ if(CURL_USE_LIBUV)
   if(NOT ENABLE_DEBUG)
     message(FATAL_ERROR "Using libuv without debug support enabled is useless")
   endif()
-  if(NOT MSVC OR VCPKG_TOOLCHAIN)
+  if(CURL_USE_PKGCONFIG)
     find_package(PkgConfig QUIET)
     pkg_check_modules(LIBUV "libuv")
   endif()