build: omit certain deps from libcurl.pc unless found via pkg-config

The idea of linking dependencies found to `libcurl.pc` turns out not
to work in practice in some cases.

Specifically: gss, ldap, mbedtls, libmsh3, rustls

A `.pc` may not work or be missing for a couple of reasons:
- not all build methods generate it: mbedTLS, Rustls
- generated file is broken: msh3
  Ref: https://github.com/nibanks/msh3/pull/225
- installed package flavour isn't shipping with one:
  FreeBSD GSS, OmniOS LDAP, macOS LDAP

The effect of such issues shall be subtle in theory, because
`libcurl.pc` normally lists these dependencies in the `Requires.private`
section meant for static linking. But, e.g. `pkg-config --exists`
requires these to be present, and builds sometimes use this check
regardless of build type. This bug is not present in `pkgconf`; it only
checks for them when `--static` is also passed.

Fix these by adding affected `.pc` references to `libcurl.pc` only when
we detected the dependency via `pkg-config`.

There are a few side-effects of this solution:
- references are never added for dependencies where curl doesn't
  implement `pkg-config` detection. These are:
  - autotools: ldap, mbedtls, msh3
  - cmake: ldap (pending #15273)
- generated `libcurl.pc` depends on the build-time environment.
- generated `libcurl.pc` depends on curl build tool (cmake, autotools).
- generated `libcurl.pc` depends on curl build implementation details.

Make an exception for GNU GSS, where I blindly guess that `gss.pc` is
always available, as no issues were reported.

Other, not mentioned, dependencies continue to be added regardless
of the detection method.

Reported-by: Harmen Stoppels, Thomas, Daniel Engberg, Andy Fiddaman
Fixes #15469
Fixes #15507
Fixes #15535
Fixes https://github.com/curl/curl/pull/15163#issuecomment-2473358444
Closes #15573
This commit is contained in:
Viktor Szakats 2024-11-13 14:44:05 +01:00
parent e0e93d4314
commit d511ec8b0a
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
9 changed files with 44 additions and 21 deletions

View File

@ -34,6 +34,7 @@
# - `GSS_INCLUDE_DIRS`: The GSS include directories.
# - `GSS_LIBRARIES`: The GSS library names.
# - `GSS_LIBRARY_DIRS`: The GSS library directories.
# - `GSS_PC_REQUIRES`: The GSS pkg-config packages.
# - `GSS_CFLAGS`: Required compiler flags.
# - `GSS_VERSION`: This is set to version advertised by pkg-config or read from manifest.
# In case the library is found but no version info available it is set to "unknown"
@ -212,6 +213,7 @@ if(NOT _GSS_FOUND) # Not found by pkg-config. Let us take more traditional appr
if(_GSS_INCLUDE_DIRS)
set(GSS_FLAVOUR "GNU")
set(GSS_PC_REQUIRES "gss")
endif()
endif()
endif()
@ -266,16 +268,19 @@ else()
# _GSS_MODULE_NAME set since CMake 3.16
if(_GSS_MODULE_NAME STREQUAL _gnu_modname OR _GSS_${_gnu_modname}_VERSION)
set(GSS_FLAVOUR "GNU")
set(GSS_PC_REQUIRES "gss")
if(NOT _GSS_VERSION) # for old CMake versions?
set(_GSS_VERSION ${_GSS_${_gnu_modname}_VERSION})
endif()
elseif(_GSS_MODULE_NAME STREQUAL _mit_modname OR _GSS_${_mit_modname}_VERSION)
set(GSS_FLAVOUR "MIT")
set(GSS_PC_REQUIRES "mit-krb5-gssapi")
if(NOT _GSS_VERSION) # for old CMake versions?
set(_GSS_VERSION ${_GSS_${_mit_modname}_VERSION})
endif()
else()
set(GSS_FLAVOUR "Heimdal")
set(GSS_PC_REQUIRES "heimdal-gssapi")
if(NOT _GSS_VERSION) # for old CMake versions?
set(_GSS_VERSION ${_GSS_${_heimdal_modname}_VERSION})
endif()

View File

@ -34,6 +34,7 @@
# - `MSH3_INCLUDE_DIRS`: The msh3 include directories.
# - `MSH3_LIBRARIES`: The msh3 library names.
# - `MSH3_LIBRARY_DIRS`: The msh3 library directories.
# - `MSH3_PC_REQUIRES`: The msh3 pkg-config packages.
# - `MSH3_CFLAGS`: Required compiler flags.
# - `MSH3_VERSION`: Version of msh3.
@ -45,6 +46,7 @@ if(CURL_USE_PKGCONFIG AND
endif()
if(MSH3_FOUND)
set(MSH3_PC_REQUIRES "libmsh3")
string(REPLACE ";" " " MSH3_CFLAGS "${MSH3_CFLAGS}")
message(STATUS "Found MSH3 (via pkg-config): ${MSH3_INCLUDE_DIRS} (found version \"${MSH3_VERSION}\")")
else()

View File

@ -36,6 +36,7 @@
# - `MBEDTLS_INCLUDE_DIRS`: The mbedTLS include directories.
# - `MBEDTLS_LIBRARIES`: The mbedTLS library names.
# - `MBEDTLS_LIBRARY_DIRS`: The mbedTLS library directories.
# - `MBEDTLS_PC_REQUIRES`: The mbedTLS pkg-config packages.
# - `MBEDTLS_CFLAGS`: Required compiler flags.
# - `MBEDTLS_VERSION`: Version of mbedTLS.
@ -59,6 +60,7 @@ endif()
if(MBEDTLS_FOUND AND MBEDX509_FOUND AND MBEDCRYPTO_FOUND)
list(APPEND MBEDTLS_LIBRARIES ${MBEDX509_LIBRARIES} ${MBEDCRYPTO_LIBRARIES})
list(REMOVE_DUPLICATES MBEDTLS_LIBRARIES)
set(MBEDTLS_PC_REQUIRES "mbedtls")
string(REPLACE ";" " " MBEDTLS_CFLAGS "${MBEDTLS_CFLAGS}")
message(STATUS "Found MbedTLS (via pkg-config): ${MBEDTLS_INCLUDE_DIRS} (found version \"${MBEDTLS_VERSION}\")")
else()

View File

@ -34,6 +34,7 @@
# - `RUSTLS_INCLUDE_DIRS`: The Rustls include directories.
# - `RUSTLS_LIBRARIES`: The Rustls library names.
# - `RUSTLS_LIBRARY_DIRS`: The Rustls library directories.
# - `RUSTLS_PC_REQUIRES`: The Rustls pkg-config packages.
# - `RUSTLS_CFLAGS`: Required compiler flags.
# - `RUSTLS_VERSION`: Version of Rustls.
@ -45,6 +46,7 @@ if(CURL_USE_PKGCONFIG AND
endif()
if(RUSTLS_FOUND)
set(RUSTLS_PC_REQUIRES "rustls")
string(REPLACE ";" " " RUSTLS_CFLAGS "${RUSTLS_CFLAGS}")
message(STATUS "Found Rustls (via pkg-config): ${RUSTLS_INCLUDE_DIRS} (found version \"${RUSTLS_VERSION}\")")
else()

View File

@ -636,7 +636,7 @@ if(CURL_USE_MBEDTLS)
set(USE_MBEDTLS ON)
list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
list(APPEND CURL_LIBDIRS ${MBEDTLS_LIBRARY_DIRS})
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "mbedtls")
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${MBEDTLS_PC_REQUIRES})
include_directories(SYSTEM ${MBEDTLS_INCLUDE_DIRS})
link_directories(${MBEDTLS_LIBRARY_DIRS})
if(MBEDTLS_CFLAGS)
@ -726,7 +726,7 @@ if(CURL_USE_RUSTLS)
set(USE_RUSTLS ON)
list(APPEND CURL_LIBS ${RUSTLS_LIBRARIES})
list(APPEND CURL_LIBDIRS ${RUSTLS_LIBRARY_DIRS})
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "rustls")
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${RUSTLS_PC_REQUIRES})
include_directories(SYSTEM ${RUSTLS_INCLUDE_DIRS})
link_directories(${RUSTLS_LIBRARY_DIRS})
if(RUSTLS_CFLAGS)
@ -952,7 +952,7 @@ if(USE_MSH3)
find_package(MSH3 REQUIRED)
list(APPEND CURL_LIBS ${MSH3_LIBRARIES})
list(APPEND CURL_LIBDIRS ${MSH3_LIBRARY_DIRS})
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libmsh3")
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${MSH3_PC_REQUIRES})
include_directories(SYSTEM ${MSH3_INCLUDE_DIRS})
link_directories(${MSH3_LIBRARY_DIRS})
if(MSH3_CFLAGS)
@ -1041,7 +1041,8 @@ if(NOT CURL_DISABLE_LDAP)
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DLDAP_DEPRECATED=1")
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LDAP_LIBRARY})
set(CURL_LIBS "${LDAP_LIBRARY};${CURL_LIBS}")
set(LIBCURL_PC_REQUIRES_PRIVATE "ldap;${LIBCURL_PC_REQUIRES_PRIVATE}")
# FIXME: uncomment once pkg-config-based detection landed: https://github.com/curl/curl/pull/15273
# set(LIBCURL_PC_REQUIRES_PRIVATE "${LDAP_PC_REQUIRES};${LIBCURL_PC_REQUIRES_PRIVATE}")
if(HAVE_LIBLBER)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LDAP_LBER_LIBRARY})
set(CURL_LIBS "${LDAP_LBER_LIBRARY};${CURL_LIBS}")
@ -1248,13 +1249,7 @@ if(CURL_USE_GSSAPI)
list(APPEND CURL_LIBS ${GSS_LIBRARIES})
list(APPEND CURL_LIBDIRS ${GSS_LIBRARY_DIRS})
if(GSS_FLAVOUR STREQUAL "GNU")
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "gss")
elseif(GSS_FLAVOUR STREQUAL "MIT")
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "mit-krb5-gssapi")
else() # Heimdal
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "heimdal-gssapi")
endif()
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${GSS_PC_REQUIRES})
include_directories(SYSTEM ${GSS_INCLUDE_DIRS})
link_directories(${GSS_LIBRARY_DIRS})
if(GSS_CFLAGS)

View File

@ -565,7 +565,9 @@ AC_DEFUN([CURL_CHECK_LIBS_LDAP], [
else
LIBS="$curl_cv_ldap_LIBS $curl_cv_save_LIBS"
fi
LIBCURL_PC_REQUIRES_PRIVATE="ldap $LIBCURL_PC_REQUIRES_PRIVATE"
if false; then
LIBCURL_PC_REQUIRES_PRIVATE="ldap $LIBCURL_PC_REQUIRES_PRIVATE"
fi
AC_MSG_RESULT([$curl_cv_ldap_LIBS])
;;
esac

View File

@ -2015,12 +2015,14 @@ if test x"$want_gss" = xyes; then
AC_DEFINE(HAVE_GSSAPI, 1, [if you have GSS-API libraries])
HAVE_GSSAPI=1
curl_gss_msg="enabled (MIT Kerberos/Heimdal)"
link_pkgconfig=''
if test -n "$gnu_gss"; then
curl_gss_msg="enabled (GNU GSS)"
LDFLAGS="$LDFLAGS $GSSAPI_LIB_DIR"
LDFLAGSPC="$LDFLAGSPC $GSSAPI_LIB_DIR"
LIBS="-lgss $LIBS"
link_pkgconfig=1
elif test -z "$GSSAPI_LIB_DIR"; then
case $host in
*-apple-*)
@ -2040,11 +2042,13 @@ if test x"$want_gss" = xyes; then
elif test "$PKGCONFIG" != "no"; then
gss_libs=`$PKGCONFIG --libs mit-krb5-gssapi`
LIBS="$gss_libs $LIBS"
link_pkgconfig=1
elif test -f "$KRB5CONFIG"; then
dnl krb5-config doesn't have --libs-only-L or similar, put everything
dnl into LIBS
gss_libs=`$KRB5CONFIG --libs gssapi`
LIBS="$gss_libs $LIBS"
link_pkgconfig=1
else
case $host in
*-hp-hpux*)
@ -2077,12 +2081,14 @@ if test x"$want_gss" = xyes; then
;;
esac
fi
if test -n "$gnu_gss"; then
LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE gss"
elif test "x$not_mit" = "x1"; then
LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE heimdal-gssapi"
else
LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE mit-krb5-gssapi"
if test -n "$link_pkgconfig"; then
if test -n "$gnu_gss"; then
LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE gss"
elif test "x$not_mit" = "x1"; then
LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE heimdal-gssapi"
else
LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE mit-krb5-gssapi"
fi
fi
else
CPPFLAGS="$save_CPPFLAGS"
@ -3761,7 +3767,9 @@ if test X"$want_msh3" != Xno; then
CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$DIR_MSH3"
export CURL_LIBRARY_PATH
AC_MSG_NOTICE([Added $DIR_MSH3 to CURL_LIBRARY_PATH])
LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE libmsh3"
if false; then
LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE libmsh3"
fi
experimental="$experimental HTTP3"
)
],

View File

@ -104,7 +104,9 @@ if test "x$OPT_MBEDTLS" != xno; then
AC_MSG_NOTICE([Added $mbedtlslib to CURL_LIBRARY_PATH])
fi
fi
LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE mbedtls"
if false; then
LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE mbedtls"
fi
fi
fi dnl mbedTLS not disabled

View File

@ -112,6 +112,8 @@ if test "x$OPT_RUSTLS" != xno; then
;;
esac
link_pkgconfig=''
if test "$PKGTEST" = "yes"; then
CURL_CHECK_PKGCONFIG(rustls, [$RUSTLS_PCDIR])
@ -140,6 +142,7 @@ if test "x$OPT_RUSTLS" != xno; then
dnl additional libs may be necessary. Hope that we
dnl don't need any.
LIBS="$SSL_LIBS $LIBS"
link_pkgconfig=1
ssl_msg="rustls"
AC_DEFINE(USE_RUSTLS, 1, [if Rustls is enabled])
AC_SUBST(USE_RUSTLS, [1])
@ -176,7 +179,9 @@ if test "x$OPT_RUSTLS" != xno; then
AC_MSG_NOTICE([Added $LIB_RUSTLS to CURL_LIBRARY_PATH])
fi
fi
LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE rustls"
if test -n "$link_pkgconfig"; then
LIBCURL_PC_REQUIRES_PRIVATE="$LIBCURL_PC_REQUIRES_PRIVATE rustls"
fi
fi
test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"