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
# 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}")
# 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()
# 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()
# 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()
# 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()
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
# 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()
# 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()
# 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()
# 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()
###########################################################################
@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@)
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 "")
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()
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)
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()
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()