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_INCLUDE_DIRS`: The GSS include directories.
# - `GSS_LIBRARIES`: The GSS library names. # - `GSS_LIBRARIES`: The GSS library names.
# - `GSS_LIBRARY_DIRS`: The GSS library directories. # - `GSS_LIBRARY_DIRS`: The GSS library directories.
# - `GSS_PC_REQUIRES`: The GSS pkg-config packages.
# - `GSS_CFLAGS`: Required compiler flags. # - `GSS_CFLAGS`: Required compiler flags.
# - `GSS_VERSION`: This is set to version advertised by pkg-config or read from manifest. # - `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" # 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) if(_GSS_INCLUDE_DIRS)
set(GSS_FLAVOUR "GNU") set(GSS_FLAVOUR "GNU")
set(GSS_PC_REQUIRES "gss")
endif() endif()
endif() endif()
endif() endif()
@ -266,16 +268,19 @@ else()
# _GSS_MODULE_NAME set since CMake 3.16 # _GSS_MODULE_NAME set since CMake 3.16
if(_GSS_MODULE_NAME STREQUAL _gnu_modname OR _GSS_${_gnu_modname}_VERSION) if(_GSS_MODULE_NAME STREQUAL _gnu_modname OR _GSS_${_gnu_modname}_VERSION)
set(GSS_FLAVOUR "GNU") set(GSS_FLAVOUR "GNU")
set(GSS_PC_REQUIRES "gss")
if(NOT _GSS_VERSION) # for old CMake versions? if(NOT _GSS_VERSION) # for old CMake versions?
set(_GSS_VERSION ${_GSS_${_gnu_modname}_VERSION}) set(_GSS_VERSION ${_GSS_${_gnu_modname}_VERSION})
endif() endif()
elseif(_GSS_MODULE_NAME STREQUAL _mit_modname OR _GSS_${_mit_modname}_VERSION) elseif(_GSS_MODULE_NAME STREQUAL _mit_modname OR _GSS_${_mit_modname}_VERSION)
set(GSS_FLAVOUR "MIT") set(GSS_FLAVOUR "MIT")
set(GSS_PC_REQUIRES "mit-krb5-gssapi")
if(NOT _GSS_VERSION) # for old CMake versions? if(NOT _GSS_VERSION) # for old CMake versions?
set(_GSS_VERSION ${_GSS_${_mit_modname}_VERSION}) set(_GSS_VERSION ${_GSS_${_mit_modname}_VERSION})
endif() endif()
else() else()
set(GSS_FLAVOUR "Heimdal") set(GSS_FLAVOUR "Heimdal")
set(GSS_PC_REQUIRES "heimdal-gssapi")
if(NOT _GSS_VERSION) # for old CMake versions? if(NOT _GSS_VERSION) # for old CMake versions?
set(_GSS_VERSION ${_GSS_${_heimdal_modname}_VERSION}) set(_GSS_VERSION ${_GSS_${_heimdal_modname}_VERSION})
endif() endif()

View File

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

View File

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

View File

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

View File

@ -636,7 +636,7 @@ if(CURL_USE_MBEDTLS)
set(USE_MBEDTLS ON) set(USE_MBEDTLS ON)
list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES}) list(APPEND CURL_LIBS ${MBEDTLS_LIBRARIES})
list(APPEND CURL_LIBDIRS ${MBEDTLS_LIBRARY_DIRS}) 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}) include_directories(SYSTEM ${MBEDTLS_INCLUDE_DIRS})
link_directories(${MBEDTLS_LIBRARY_DIRS}) link_directories(${MBEDTLS_LIBRARY_DIRS})
if(MBEDTLS_CFLAGS) if(MBEDTLS_CFLAGS)
@ -726,7 +726,7 @@ if(CURL_USE_RUSTLS)
set(USE_RUSTLS ON) set(USE_RUSTLS ON)
list(APPEND CURL_LIBS ${RUSTLS_LIBRARIES}) list(APPEND CURL_LIBS ${RUSTLS_LIBRARIES})
list(APPEND CURL_LIBDIRS ${RUSTLS_LIBRARY_DIRS}) 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}) include_directories(SYSTEM ${RUSTLS_INCLUDE_DIRS})
link_directories(${RUSTLS_LIBRARY_DIRS}) link_directories(${RUSTLS_LIBRARY_DIRS})
if(RUSTLS_CFLAGS) if(RUSTLS_CFLAGS)
@ -952,7 +952,7 @@ if(USE_MSH3)
find_package(MSH3 REQUIRED) find_package(MSH3 REQUIRED)
list(APPEND CURL_LIBS ${MSH3_LIBRARIES}) list(APPEND CURL_LIBS ${MSH3_LIBRARIES})
list(APPEND CURL_LIBDIRS ${MSH3_LIBRARY_DIRS}) 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}) include_directories(SYSTEM ${MSH3_INCLUDE_DIRS})
link_directories(${MSH3_LIBRARY_DIRS}) link_directories(${MSH3_LIBRARY_DIRS})
if(MSH3_CFLAGS) if(MSH3_CFLAGS)
@ -1041,7 +1041,8 @@ if(NOT CURL_DISABLE_LDAP)
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DLDAP_DEPRECATED=1") list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DLDAP_DEPRECATED=1")
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LDAP_LIBRARY}) list(APPEND CMAKE_REQUIRED_LIBRARIES ${LDAP_LIBRARY})
set(CURL_LIBS "${LDAP_LIBRARY};${CURL_LIBS}") 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) if(HAVE_LIBLBER)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LDAP_LBER_LIBRARY}) list(APPEND CMAKE_REQUIRED_LIBRARIES ${LDAP_LBER_LIBRARY})
set(CURL_LIBS "${LDAP_LBER_LIBRARY};${CURL_LIBS}") 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_LIBS ${GSS_LIBRARIES})
list(APPEND CURL_LIBDIRS ${GSS_LIBRARY_DIRS}) list(APPEND CURL_LIBDIRS ${GSS_LIBRARY_DIRS})
if(GSS_FLAVOUR STREQUAL "GNU") list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${GSS_PC_REQUIRES})
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()
include_directories(SYSTEM ${GSS_INCLUDE_DIRS}) include_directories(SYSTEM ${GSS_INCLUDE_DIRS})
link_directories(${GSS_LIBRARY_DIRS}) link_directories(${GSS_LIBRARY_DIRS})
if(GSS_CFLAGS) if(GSS_CFLAGS)

View File

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

View File

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