cmake: allow pkg-config in more envs

Before this patch, `pkg-config` was used for `UNIX` builds only (with
a few exceptions like wolfSSL, libssh, gsasl, libuv). This patch extends
`pkg-config` use to all envs except: `MSVC` without vcpkg. Meaning MSVC
with vcpkg will now use it. Also mingw on Windows.

Also apply the new condition to options where `pkg-config` was used
unconditionally (= for all targets). These are:
`-DCURL_USE_WOLFSSL=ON`, `-DCURL_USE_LIBSSH=ON`,
`-DCURL_USE_GSASL=ON` and `-DCURL_USE_LIBUV=ON`

This patch may still cause regressions for cross-builds (e.g. mingw
cross-build from Unix) and potentially other cases. If that happens, we
recommend using some of these methods to explicitly disable `pkg-config`
when using CMake:
- CMake option: `-DPKG_CONFIG_EXECUTABLE=`
  (or `-DPKG_CONFIG_EXECUTABLE=nonexistent` or similar)
  This is similar to the (curl-specific) `PKG_CONFIG` env for autotools.
- export env: `PKG_CONFIG_LIBDIR=`
  (or `PKG_CONFIG_PATH`, `PKG_CONFIG_SYSROOT_DIR`,
  or the CMake-specific `PKG_CONFIG`)

We may improve control over this in a future patch, also allowing opting
in MSVC (without vcpkg).

Ref: #14405
Ref: #14408
Ref: #14140
Closes #14483
This commit is contained in:
Viktor Szakats 2024-08-10 09:33:18 +02:00
parent d222dbe788
commit 9dfdc6ff42
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
10 changed files with 31 additions and 20 deletions

View file

@ -38,7 +38,7 @@
# NGTCP2_LIBRARIES The libraries needed to use ngtcp2
# NGTCP2_VERSION Version of ngtcp2
if(UNIX)
if(NOT MSVC OR VCPKG_TOOLCHAIN)
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(UNIX)
if(NOT MSVC OR VCPKG_TOOLCHAIN)
pkg_search_module(PC_${_crypto_library} "lib${_crypto_library}")
endif()
find_library(${_crypto_library}_LIBRARY