]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: allow `pkg-config` in more envs
authorViktor Szakats <commit@vsz.me>
Sat, 10 Aug 2024 07:33:18 +0000 (09:33 +0200)
committerViktor Szakats <commit@vsz.me>
Mon, 12 Aug 2024 12:57:10 +0000 (14:57 +0200)
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

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
CMakeLists.txt

index 35687ab9d261db3314dcb5840218f5abf830523a..07e4fd0444f24ca54aac60463c7f75446d134762 100644 (file)
@@ -53,11 +53,12 @@ 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(UNIX)
+  if(NOT MSVC OR VCPKG_TOOLCHAIN)
     find_package(PkgConfig QUIET)
     pkg_search_module(_GSS ${_mit_modname} ${_heimdal_modname})
     list(APPEND _gss_root_hints "${_GSS_PREFIX}")
-  elseif(WIN32)
+  endif()
+  if(WIN32)
     list(APPEND _gss_root_hints "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MIT\\Kerberos;InstallDir]")
   endif()
 endif()
index 146887d07f5e9e1015ba19b45a06859aa3503d69..59e8c31dbbdb9b270996ae0f88e71b94be7bb57a 100644 (file)
@@ -29,7 +29,7 @@
 # MSH3_INCLUDE_DIRS  The msh3 include directories
 # MSH3_LIBRARIES     The libraries needed to use msh3
 
-if(UNIX)
+if(NOT MSVC OR VCPKG_TOOLCHAIN)
   find_package(PkgConfig QUIET)
   pkg_search_module(PC_MSH3 "libmsh3")
 endif()
index a15785348fbccd0d50e39a9428b5e6f119ad918d..deb81bdadb2143b0836cca971bdedf6042616172 100644 (file)
@@ -30,7 +30,7 @@
 # NGHTTP2_LIBRARIES     The libraries needed to use nghttp2
 # NGHTTP2_VERSION       Version of nghttp2
 
-if(UNIX)
+if(NOT MSVC OR VCPKG_TOOLCHAIN)
   find_package(PkgConfig QUIET)
   pkg_search_module(PC_NGHTTP2 "libnghttp2")
 endif()
index ea25eb63a12a3d825d55467906a287de36a35725..cf210e1795ebd4b88058ff598da261fdbd26f6a9 100644 (file)
@@ -30,7 +30,7 @@
 # NGHTTP3_LIBRARIES     The libraries needed to use nghttp3
 # NGHTTP3_VERSION       Version of nghttp3
 
-if(UNIX)
+if(NOT MSVC OR VCPKG_TOOLCHAIN)
   find_package(PkgConfig QUIET)
   pkg_search_module(PC_NGHTTP3 "libnghttp3")
 endif()
index 1d4fb38c1d85c413e649efaebc13e688eaed3457..3ebf3b91b4def946faf0fe914bc00224ec71f07c 100644 (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
index 8dcdecfe9fa04408bd8bdaec3c2321aab8c7e1aa..02ae13f331494c39df1e7c9a24ffa9a98577547e 100644 (file)
@@ -30,7 +30,7 @@
 # NETTLE_LIBRARIES     The nettle library names
 # NETTLE_VERSION       Version of nettle
 
-if(UNIX)
+if(NOT MSVC OR VCPKG_TOOLCHAIN)
   find_package(PkgConfig QUIET)
   pkg_search_module(NETTLE "nettle")
 endif()
index 59d3136f2c6eab41a45329cdfb0f6d5a300e7731..bcd54e942dc5a2628c1f414ed352acd2bebae9f9 100644 (file)
@@ -29,7 +29,7 @@
 # QUICHE_INCLUDE_DIRS  The quiche include directories
 # QUICHE_LIBRARIES     The libraries needed to use quiche
 
-if(UNIX)
+if(NOT MSVC OR VCPKG_TOOLCHAIN)
   find_package(PkgConfig QUIET)
   pkg_search_module(PC_QUICHE "quiche")
 endif()
index dd87c9ec608da23d55b884370d6b3234e1a8d1d5..1e9437ffbaf8c45bc6b370650834f17b794cdf17 100644 (file)
 # WolfSSL_LIBRARIES     The wolfssl library names
 # WolfSSL_VERSION       Version of wolfssl
 
-find_package(PkgConfig QUIET)
-pkg_search_module(PC_WOLFSSL QUIET "wolfssl")
+if(NOT MSVC OR VCPKG_TOOLCHAIN)
+  find_package(PkgConfig QUIET)
+  pkg_search_module(PC_WOLFSSL QUIET "wolfssl")
+endif()
 
 find_path(WolfSSL_INCLUDE_DIR
   NAMES "wolfssl/ssl.h"
index 836396b862379617e6feeda757d65cf6bad56386..6574d0896c31f239fe3d1454097c9a8b12a666be 100644 (file)
@@ -30,7 +30,7 @@
 # Zstd_LIBRARIES     The libraries needed to use zstd
 # Zstd_VERSION       Version of zstd
 
-if(UNIX)
+if(NOT MSVC OR VCPKG_TOOLCHAIN)
   find_package(PkgConfig QUIET)
   pkg_search_module(PC_Zstd "libzstd")
 endif()
index dbeb1c30db109207c9f282d97d4c59e99f68c004..bccd01e9fe6a5199ca1269392c504470789042c7 100644 (file)
@@ -959,7 +959,7 @@ if(USE_LIBIDN2)
     check_include_file_concat("idn2.h" HAVE_IDN2_H)
   endif()
   if(NOT HAVE_LIBIDN2 OR NOT HAVE_IDN2_H)
-    if(UNIX)
+    if(NOT MSVC OR VCPKG_TOOLCHAIN)
       find_package(PkgConfig QUIET)
       pkg_search_module(LIBIDN2 "libidn2")
     endif()
@@ -1038,7 +1038,7 @@ if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
   find_package(libssh CONFIG QUIET)
   if(libssh_FOUND)
     message(STATUS "Found libssh ${libssh_VERSION}")
-  else()
+  elseif(NOT MSVC OR VCPKG_TOOLCHAIN)
     find_package(PkgConfig QUIET)
     pkg_search_module(LIBSSH "libssh")
     if(LIBSSH_FOUND)
@@ -1058,10 +1058,16 @@ endif()
 option(CURL_USE_GSASL "Use GSASL implementation" OFF)
 mark_as_advanced(CURL_USE_GSASL)
 if(CURL_USE_GSASL)
-  find_package(PkgConfig REQUIRED)
-  pkg_search_module(GSASL REQUIRED "libgsasl")
-  list(APPEND CURL_LIBS ${GSASL_LINK_LIBRARIES})
-  set(USE_GSASL ON)
+  if(NOT MSVC OR VCPKG_TOOLCHAIN)
+    find_package(PkgConfig REQUIRED)
+    pkg_search_module(GSASL REQUIRED "libgsasl")
+  else()
+    message(WARNING "GSASL has been requested but requires a platform with pkg-config support. Skipping.")
+  endif()
+  if(GSASL_FOUND)
+    list(APPEND CURL_LIBS ${GSASL_LINK_LIBRARIES})
+    set(USE_GSASL ON)
+  endif()
 endif()
 
 option(CURL_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
@@ -1133,8 +1139,10 @@ if(CURL_USE_LIBUV)
   if(NOT ENABLE_DEBUG)
     message(FATAL_ERROR "Using libuv without debug support enabled is useless")
   endif()
-  find_package(PkgConfig QUIET)
-  pkg_check_modules(LIBUV "libuv")
+  if(NOT MSVC OR VCPKG_TOOLCHAIN)
+    find_package(PkgConfig QUIET)
+    pkg_check_modules(LIBUV "libuv")
+  endif()
   if(LIBUV_FOUND)
     list(APPEND CURL_LIBS ${LIBUV_LINK_LIBRARIES})
     list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libuv")