Skip to content

Commit

Permalink
cmake: move pkg-config names to Find modules
Browse files Browse the repository at this point in the history
Make the Find modules set and return their respective `pkg-config`
module name(s) to the CMake build process, which then adds those
to the `Requires:` list.

Before this patch, `pkg-config` module names were maintainted in two
separate places. After this patch, they are maintained in the Find
modules for dependencies that have one (most do).

Re-align existing modules with this change: msh3, mbedtls, rustls.
These modules return their `pkg-config` module name only when
detected via `pkg-config`.

Follow-up to d511ec8 curl#15573
Closes curl#15800
  • Loading branch information
vszakats committed Dec 26, 2024
1 parent a1eaa12 commit fb1883d
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 44 deletions.
5 changes: 4 additions & 1 deletion CMake/FindBrotli.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@
# - `BROTLI_INCLUDE_DIRS`: The brotli include directories.
# - `BROTLI_LIBRARIES`: The brotli library names.
# - `BROTLI_LIBRARY_DIRS`: The brotli library directories.
# - `BROTLI_PC_REQUIRES`: The brotli pkg-config packages.
# - `BROTLI_CFLAGS`: Required compiler flags.
# - `BROTLI_VERSION`: Version of brotli.

set(BROTLI_PC_REQUIRES "libbrotlidec")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED BROTLI_INCLUDE_DIR AND
NOT DEFINED BROTLICOMMON_LIBRARY AND
NOT DEFINED BROTLIDEC_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(BROTLI "libbrotlicommon")
pkg_check_modules(BROTLIDEC "libbrotlidec")
pkg_check_modules(BROTLIDEC ${BROTLI_PC_REQUIRES})
endif()

if(BROTLI_FOUND AND BROTLIDEC_FOUND)
Expand Down
5 changes: 4 additions & 1 deletion CMake/FindCares.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
# - `CARES_INCLUDE_DIRS`: The c-ares include directories.
# - `CARES_LIBRARIES`: The c-ares library names.
# - `CARES_LIBRARY_DIRS`: The c-ares library directories.
# - `CARES_PC_REQUIRES`: The c-ares pkg-config packages.
# - `CARES_CFLAGS`: Required compiler flags.
# - `CARES_VERSION`: Version of c-ares.

set(CARES_PC_REQUIRES "libcares")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED CARES_INCLUDE_DIR AND
NOT DEFINED CARES_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(CARES "libcares")
pkg_check_modules(CARES ${CARES_PC_REQUIRES})
endif()

if(CARES_FOUND)
Expand Down
7 changes: 5 additions & 2 deletions CMake/FindLDAP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@
# - `LDAP_CFLAGS`: Required compiler flags.
# - `LDAP_VERSION`: Version of ldap.

set(LDAP_PC_REQUIRES "ldap")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED LDAP_INCLUDE_DIR AND
NOT DEFINED LDAP_LIBRARY AND
NOT DEFINED LDAP_LBER_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(LDAP "ldap")
pkg_check_modules(LDAP ${LDAP_PC_REQUIRES})
pkg_check_modules(LDAP_LBER "lber")
endif()

Expand All @@ -53,10 +55,11 @@ if(LDAP_FOUND AND LDAP_LBER_FOUND)
list(REVERSE LDAP_LIBRARIES)
list(REMOVE_DUPLICATES LDAP_LIBRARIES)
list(REVERSE LDAP_LIBRARIES)
set(LDAP_PC_REQUIRES "ldap")
string(REPLACE ";" " " LDAP_CFLAGS "${LDAP_CFLAGS}")
message(STATUS "Found LDAP (via pkg-config): ${LDAP_INCLUDE_DIRS} (found version \"${LDAP_VERSION}\")")
else()
set(LDAP_PC_REQUIRES "") # Depend on pkg-config only when found via pkg-config

# On Apple the SDK LDAP gets picked up from
# 'MacOSX.sdk/System/Library/Frameworks/LDAP.framework/Headers', which contains
# ldap.h and lber.h both being stubs to include <ldap.h> and <lber.h>.
Expand Down
5 changes: 4 additions & 1 deletion CMake/FindLibgsasl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
# - `LIBGSASL_INCLUDE_DIRS`: The libgsasl include directories.
# - `LIBGSASL_LIBRARIES`: The libgsasl library names.
# - `LIBGSASL_LIBRARY_DIRS`: The libgsasl library directories.
# - `LIBGSASL_PC_REQUIRES`: The libgsasl pkg-config packages.
# - `LIBGSASL_CFLAGS`: Required compiler flags.
# - `LIBGSASL_VERSION`: Version of libgsasl.

set(LIBGSASL_PC_REQUIRES "libgsasl")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED LIBGSASL_INCLUDE_DIR AND
NOT DEFINED LIBGSASL_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(LIBGSASL "libgsasl")
pkg_check_modules(LIBGSASL ${LIBGSASL_PC_REQUIRES})
endif()

if(LIBGSASL_FOUND)
Expand Down
5 changes: 4 additions & 1 deletion CMake/FindLibidn2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
# - `LIBIDN2_INCLUDE_DIRS`: The libidn2 include directories.
# - `LIBIDN2_LIBRARIES`: The libidn2 library names.
# - `LIBIDN2_LIBRARY_DIRS`: The libidn2 library directories.
# - `LIBIDN2_PC_REQUIRES`: The libidn2 pkg-config packages.
# - `LIBIDN2_CFLAGS`: Required compiler flags.
# - `LIBIDN2_VERSION`: Version of libidn2.

set(LIBIDN2_PC_REQUIRES "libidn2")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED LIBIDN2_INCLUDE_DIR AND
NOT DEFINED LIBIDN2_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(LIBIDN2 "libidn2")
pkg_check_modules(LIBIDN2 ${LIBIDN2_PC_REQUIRES})
endif()

if(LIBIDN2_FOUND)
Expand Down
5 changes: 4 additions & 1 deletion CMake/FindLibpsl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
# - `LIBPSL_INCLUDE_DIRS`: The libpsl include directories.
# - `LIBPSL_LIBRARIES`: The libpsl library names.
# - `LIBPSL_LIBRARY_DIRS`: The libpsl library directories.
# - `LIBPSL_PC_REQUIRES`: The libpsl pkg-config packages.
# - `LIBPSL_CFLAGS`: Required compiler flags.
# - `LIBPSL_VERSION`: Version of libpsl.

set(LIBPSL_PC_REQUIRES "libpsl")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED LIBPSL_INCLUDE_DIR AND
NOT DEFINED LIBPSL_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(LIBPSL "libpsl")
pkg_check_modules(LIBPSL ${LIBPSL_PC_REQUIRES})
endif()

if(LIBPSL_FOUND AND LIBPSL_INCLUDE_DIRS)
Expand Down
5 changes: 4 additions & 1 deletion CMake/FindLibssh.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
# - `LIBSSH_INCLUDE_DIRS`: The libssh include directories.
# - `LIBSSH_LIBRARIES`: The libssh library names.
# - `LIBSSH_LIBRARY_DIRS`: The libssh library directories.
# - `LIBSSH_PC_REQUIRES`: The libssh pkg-config packages.
# - `LIBSSH_CFLAGS`: Required compiler flags.
# - `LIBSSH_VERSION`: Version of libssh.

set(LIBSSH_PC_REQUIRES "libssh")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED LIBSSH_INCLUDE_DIR AND
NOT DEFINED LIBSSH_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(LIBSSH "libssh")
pkg_check_modules(LIBSSH ${LIBSSH_PC_REQUIRES})
endif()

if(LIBSSH_FOUND)
Expand Down
5 changes: 4 additions & 1 deletion CMake/FindLibssh2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
# - `LIBSSH2_INCLUDE_DIRS`: The libssh2 include directories.
# - `LIBSSH2_LIBRARIES`: The libssh2 library names.
# - `LIBSSH2_LIBRARY_DIRS`: The libssh2 library directories.
# - `LIBSSH2_PC_REQUIRES`: The libssh2 pkg-config packages.
# - `LIBSSH2_CFLAGS`: Required compiler flags.
# - `LIBSSH2_VERSION`: Version of libssh2.

set(LIBSSH2_PC_REQUIRES "libssh2")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED LIBSSH2_INCLUDE_DIR AND
NOT DEFINED LIBSSH2_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(LIBSSH2 "libssh2")
pkg_check_modules(LIBSSH2 ${LIBSSH2_PC_REQUIRES})
endif()

if(LIBSSH2_FOUND AND LIBSSH2_INCLUDE_DIRS)
Expand Down
5 changes: 4 additions & 1 deletion CMake/FindLibuv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
# - `LIBUV_INCLUDE_DIRS`: The libuv include directories.
# - `LIBUV_LIBRARIES`: The libuv library names.
# - `LIBUV_LIBRARY_DIRS`: The libuv library directories.
# - `LIBUV_PC_REQUIRES`: The libuv pkg-config packages.
# - `LIBUV_CFLAGS`: Required compiler flags.
# - `LIBUV_VERSION`: Version of libuv.

set(LIBUV_PC_REQUIRES "libuv")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED LIBUV_INCLUDE_DIR AND
NOT DEFINED LIBUV_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(LIBUV "libuv")
pkg_check_modules(LIBUV ${LIBUV_PC_REQUIRES})
endif()

if(LIBUV_FOUND)
Expand Down
7 changes: 5 additions & 2 deletions CMake/FindMSH3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@
# - `MSH3_CFLAGS`: Required compiler flags.
# - `MSH3_VERSION`: Version of msh3.

set(MSH3_PC_REQUIRES "libmsh3")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED MSH3_INCLUDE_DIR AND
NOT DEFINED MSH3_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(MSH3 "libmsh3")
pkg_check_modules(MSH3 ${MSH3_PC_REQUIRES})
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()
set(MSH3_PC_REQUIRES "") # Depend on pkg-config only when found via pkg-config

find_path(MSH3_INCLUDE_DIR NAMES "msh3.h")
find_library(MSH3_LIBRARY NAMES "msh3")

Expand Down
7 changes: 5 additions & 2 deletions CMake/FindMbedTLS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ if(DEFINED MBEDTLS_INCLUDE_DIRS AND NOT DEFINED MBEDTLS_INCLUDE_DIR)
unset(MBEDTLS_INCLUDE_DIRS)
endif()

set(MBEDTLS_PC_REQUIRES "mbedtls")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED MBEDTLS_INCLUDE_DIR AND
NOT DEFINED MBEDTLS_LIBRARY AND
NOT DEFINED MBEDX509_LIBRARY AND
NOT DEFINED MBEDCRYPTO_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(MBEDTLS "mbedtls")
pkg_check_modules(MBEDTLS ${MBEDTLS_PC_REQUIRES})
pkg_check_modules(MBEDX509 "mbedx509")
pkg_check_modules(MBEDCRYPTO "mbedcrypto")
endif()
Expand All @@ -62,10 +64,11 @@ if(MBEDTLS_FOUND AND MBEDX509_FOUND AND MBEDCRYPTO_FOUND)
list(REVERSE MBEDTLS_LIBRARIES)
list(REMOVE_DUPLICATES MBEDTLS_LIBRARIES)
list(REVERSE 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()
set(MBEDTLS_PC_REQUIRES "") # Depend on pkg-config only when found via pkg-config

find_path(MBEDTLS_INCLUDE_DIR NAMES "mbedtls/ssl.h")
find_library(MBEDTLS_LIBRARY NAMES "mbedtls" "libmbedtls")
find_library(MBEDX509_LIBRARY NAMES "mbedx509" "libmbedx509")
Expand Down
5 changes: 4 additions & 1 deletion CMake/FindNGHTTP2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
# - `NGHTTP2_INCLUDE_DIRS`: The nghttp2 include directories.
# - `NGHTTP2_LIBRARIES`: The nghttp2 library names.
# - `NGHTTP2_LIBRARY_DIRS`: The nghttp2 library directories.
# - `NGHTTP2_PC_REQUIRES`: The nghttp2 pkg-config packages.
# - `NGHTTP2_CFLAGS`: Required compiler flags.
# - `NGHTTP2_VERSION`: Version of nghttp2.

set(NGHTTP2_PC_REQUIRES "libnghttp2")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED NGHTTP2_INCLUDE_DIR AND
NOT DEFINED NGHTTP2_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(NGHTTP2 "libnghttp2")
pkg_check_modules(NGHTTP2 ${NGHTTP2_PC_REQUIRES})
endif()

if(NGHTTP2_FOUND)
Expand Down
5 changes: 4 additions & 1 deletion CMake/FindNGHTTP3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
# - `NGHTTP3_INCLUDE_DIRS`: The nghttp3 include directories.
# - `NGHTTP3_LIBRARIES`: The nghttp3 library names.
# - `NGHTTP3_LIBRARY_DIRS`: The nghttp3 library directories.
# - `NGHTTP3_PC_REQUIRES`: The nghttp3 pkg-config packages.
# - `NGHTTP3_CFLAGS`: Required compiler flags.
# - `NGHTTP3_VERSION`: Version of nghttp3.

set(NGHTTP3_PC_REQUIRES "libnghttp3")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED NGHTTP3_INCLUDE_DIR AND
NOT DEFINED NGHTTP3_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(NGHTTP3 "libnghttp3")
pkg_check_modules(NGHTTP3 ${NGHTTP3_PC_REQUIRES})
endif()

if(NGHTTP3_FOUND)
Expand Down
12 changes: 10 additions & 2 deletions CMake/FindNGTCP2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
# - `NGTCP2_INCLUDE_DIRS`: The ngtcp2 include directories.
# - `NGTCP2_LIBRARIES`: The ngtcp2 library names.
# - `NGTCP2_LIBRARY_DIRS`: The ngtcp2 library directories.
# - `NGTCP2_PC_REQUIRES`: The ngtcp2 pkg-config packages.
# - `NGTCP2_CFLAGS`: Required compiler flags.
# - `NGTCP2_VERSION`: Version of ngtcp2.

Expand All @@ -62,18 +63,25 @@ if(NGTCP2_FIND_COMPONENTS)
endif()
endif()

set(NGTCP2_PC_REQUIRES "libngtcp2")
if(_ngtcp2_crypto_backend)
set(NGTCP2_CRYPTO_PC_REQUIRES "lib${_crypto_library_lower}")
endif()

if(CURL_USE_PKGCONFIG AND
NOT DEFINED NGTCP2_INCLUDE_DIR AND
NOT DEFINED NGTCP2_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(NGTCP2 "libngtcp2")
pkg_check_modules(NGTCP2 ${NGTCP2_PC_REQUIRES})
if(_ngtcp2_crypto_backend)
pkg_check_modules("${_crypto_library_upper}" "lib${_crypto_library_lower}")
pkg_check_modules("${_crypto_library_upper}" ${NGTCP2_CRYPTO_PC_REQUIRES})
else()
set("${_crypto_library_upper}_FOUND" TRUE)
endif()
endif()

list(APPEND NGTCP2_PC_REQUIRES ${NGTCP2_CRYPTO_PC_REQUIRES})

if(NGTCP2_FOUND AND "${${_crypto_library_upper}_FOUND}")
list(APPEND NGTCP2_LIBRARIES "${${_crypto_library_upper}_LIBRARIES}")
list(REMOVE_DUPLICATES NGTCP2_LIBRARIES)
Expand Down
5 changes: 4 additions & 1 deletion CMake/FindNettle.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
# - `NETTLE_INCLUDE_DIRS`: The nettle include directories.
# - `NETTLE_LIBRARIES`: The nettle library names.
# - `NETTLE_LIBRARY_DIRS`: The nettle library directories.
# - `NETTLE_PC_REQUIRES`: The nettle pkg-config packages.
# - `NETTLE_CFLAGS`: Required compiler flags.
# - `NETTLE_VERSION`: Version of nettle.

set(NETTLE_PC_REQUIRES "nettle")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED NETTLE_INCLUDE_DIR AND
NOT DEFINED NETTLE_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(NETTLE "nettle")
pkg_check_modules(NETTLE ${NETTLE_PC_REQUIRES})
endif()

if(NETTLE_FOUND)
Expand Down
5 changes: 4 additions & 1 deletion CMake/FindQuiche.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
# - `QUICHE_INCLUDE_DIRS`: The quiche include directories.
# - `QUICHE_LIBRARIES`: The quiche library names.
# - `QUICHE_LIBRARY_DIRS`: The quiche library directories.
# - `QUICHE_PC_REQUIRES`: The quiche pkg-config packages.
# - `QUICHE_CFLAGS`: Required compiler flags.
# - `QUICHE_VERSION`: Version of quiche.

set(QUICHE_PC_REQUIRES "quiche")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED QUICHE_INCLUDE_DIR AND
NOT DEFINED QUICHE_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(QUICHE "quiche")
pkg_check_modules(QUICHE ${QUICHE_PC_REQUIRES})
endif()

if(QUICHE_FOUND)
Expand Down
7 changes: 5 additions & 2 deletions CMake/FindRustls.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@
# - `RUSTLS_CFLAGS`: Required compiler flags.
# - `RUSTLS_VERSION`: Version of Rustls.

set(RUSTLS_PC_REQUIRES "rustls")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED RUSTLS_INCLUDE_DIR AND
NOT DEFINED RUSTLS_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(RUSTLS "rustls")
pkg_check_modules(RUSTLS ${RUSTLS_PC_REQUIRES})
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()
set(RUSTLS_PC_REQUIRES "") # Depend on pkg-config only when found via pkg-config

find_path(RUSTLS_INCLUDE_DIR NAMES "rustls.h")
find_library(RUSTLS_LIBRARY NAMES "rustls")

Expand Down
5 changes: 4 additions & 1 deletion CMake/FindWolfSSL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# - `WOLFSSL_INCLUDE_DIRS`: The wolfSSL include directories.
# - `WOLFSSL_LIBRARIES`: The wolfSSL library names.
# - `WOLFSSL_LIBRARY_DIRS`: The wolfSSL library directories.
# - `WOLFSSL_PC_REQUIRES`: The wolfSSL pkg-config packages.
# - `WOLFSSL_CFLAGS`: Required compiler flags.
# - `WOLFSSL_VERSION`: Version of wolfSSL.

Expand All @@ -46,11 +47,13 @@ if(DEFINED WolfSSL_LIBRARY AND NOT DEFINED WOLFSSL_LIBRARY)
set(WOLFSSL_LIBRARY "${WolfSSL_LIBRARY}")
endif()

set(WOLFSSL_PC_REQUIRES "wolfssl")

if(CURL_USE_PKGCONFIG AND
NOT DEFINED WOLFSSL_INCLUDE_DIR AND
NOT DEFINED WOLFSSL_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(WOLFSSL "wolfssl")
pkg_check_modules(WOLFSSL ${WOLFSSL_PC_REQUIRES})
endif()

if(WOLFSSL_FOUND)
Expand Down
Loading

0 comments on commit fb1883d

Please sign in to comment.