cmake: make system libraries dl, m, pthread customizable

via `DL_LIBRARY`, `MATH_LIBRARY`, `PTHREAD_LIBRARY` variables.

They are used in Rustls, wolfSSL Find modules.

Also:
- always use `NAMES` keyword in `find_library()` calls.
- respect `find_library()` results for `dl`, `m`, `pthread`.
- formatting.

Closes #15892
This commit is contained in:
Viktor Szakats 2025-01-01 22:55:07 +01:00
parent 9a9498ea1e
commit 27b9e76706
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
4 changed files with 32 additions and 30 deletions

View File

@ -72,35 +72,35 @@ else()
endif() endif()
if(APPLE) if(APPLE)
find_library(SECURITY_FRAMEWORK "Security") find_library(SECURITY_FRAMEWORK NAMES "Security")
mark_as_advanced(SECURITY_FRAMEWORK) mark_as_advanced(SECURITY_FRAMEWORK)
if(NOT SECURITY_FRAMEWORK) if(NOT SECURITY_FRAMEWORK)
message(FATAL_ERROR "Security framework not found") message(FATAL_ERROR "Security framework not found")
endif() endif()
list(APPEND RUSTLS_LIBRARIES "-framework Security") list(APPEND RUSTLS_LIBRARIES "-framework Security")
find_library(FOUNDATION_FRAMEWORK "Foundation") find_library(FOUNDATION_FRAMEWORK NAMES "Foundation")
mark_as_advanced(FOUNDATION_FRAMEWORK) mark_as_advanced(FOUNDATION_FRAMEWORK)
if(NOT FOUNDATION_FRAMEWORK) if(NOT FOUNDATION_FRAMEWORK)
message(FATAL_ERROR "Foundation framework not found") message(FATAL_ERROR "Foundation framework not found")
endif() endif()
list(APPEND RUSTLS_LIBRARIES "-framework Foundation") list(APPEND RUSTLS_LIBRARIES "-framework Foundation")
elseif(NOT WIN32) elseif(NOT WIN32)
find_library(_pthread_library "pthread") find_library(PTHREAD_LIBRARY NAMES "pthread")
if(_pthread_library) if(PTHREAD_LIBRARY)
list(APPEND RUSTLS_LIBRARIES "pthread") list(APPEND RUSTLS_LIBRARIES ${PTHREAD_LIBRARY})
endif() endif()
mark_as_advanced(_pthread_library) mark_as_advanced(PTHREAD_LIBRARY)
find_library(_dl_library "dl") find_library(DL_LIBRARY NAMES "dl")
if(_dl_library) if(DL_LIBRARY)
list(APPEND RUSTLS_LIBRARIES "dl") list(APPEND RUSTLS_LIBRARIES ${DL_LIBRARY})
endif() endif()
mark_as_advanced(_dl_library) mark_as_advanced(DL_LIBRARY)
find_library(_math_library "m") find_library(MATH_LIBRARY NAMES "m")
if(_math_library) if(MATH_LIBRARY)
list(APPEND RUSTLS_LIBRARIES "m") list(APPEND RUSTLS_LIBRARIES ${MATH_LIBRARY})
endif() endif()
mark_as_advanced(_math_library) mark_as_advanced(MATH_LIBRARY)
endif() endif()

View File

@ -91,9 +91,9 @@ else()
endif() endif()
if(NOT WIN32) if(NOT WIN32)
find_library(_math_library "m") find_library(MATH_LIBRARY NAMES "m")
if(_math_library) if(MATH_LIBRARY)
list(APPEND WOLFSSL_LIBRARIES "m") # for log and pow list(APPEND WOLFSSL_LIBRARIES ${MATH_LIBRARY}) # for log and pow
endif() endif()
mark_as_advanced(_math_library) mark_as_advanced(MATH_LIBRARY)
endif() endif()

View File

@ -469,12 +469,11 @@ if(ENABLE_IPV6 AND NOT WIN32)
if(APPLE AND NOT ENABLE_ARES) if(APPLE AND NOT ENABLE_ARES)
set(_use_core_foundation_and_core_services ON) set(_use_core_foundation_and_core_services ON)
find_library(SYSTEMCONFIGURATION_FRAMEWORK "SystemConfiguration") find_library(SYSTEMCONFIGURATION_FRAMEWORK NAMES "SystemConfiguration")
mark_as_advanced(SYSTEMCONFIGURATION_FRAMEWORK) mark_as_advanced(SYSTEMCONFIGURATION_FRAMEWORK)
if(NOT SYSTEMCONFIGURATION_FRAMEWORK) if(NOT SYSTEMCONFIGURATION_FRAMEWORK)
message(FATAL_ERROR "SystemConfiguration framework not found") message(FATAL_ERROR "SystemConfiguration framework not found")
endif() endif()
list(APPEND CURL_LIBS "-framework SystemConfiguration") list(APPEND CURL_LIBS "-framework SystemConfiguration")
endif() endif()
endif() endif()
@ -656,15 +655,15 @@ endif()
if(CURL_USE_SECTRANSP) if(CURL_USE_SECTRANSP)
set(_use_core_foundation_and_core_services ON) set(_use_core_foundation_and_core_services ON)
find_library(SECURITY_FRAMEWORK "Security") find_library(SECURITY_FRAMEWORK NAMES "Security")
mark_as_advanced(SECURITY_FRAMEWORK) mark_as_advanced(SECURITY_FRAMEWORK)
if(NOT SECURITY_FRAMEWORK) if(NOT SECURITY_FRAMEWORK)
message(FATAL_ERROR "Security framework not found") message(FATAL_ERROR "Security framework not found")
endif() endif()
list(APPEND CURL_LIBS "-framework Security")
set(_ssl_enabled ON) set(_ssl_enabled ON)
set(USE_SECTRANSP ON) set(USE_SECTRANSP ON)
list(APPEND CURL_LIBS "-framework Security")
if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "secure-transport") if(CURL_DEFAULT_SSL_BACKEND AND CURL_DEFAULT_SSL_BACKEND STREQUAL "secure-transport")
set(_valid_default_ssl_backend TRUE) set(_valid_default_ssl_backend TRUE)
@ -674,19 +673,19 @@ if(CURL_USE_SECTRANSP)
endif() endif()
if(_use_core_foundation_and_core_services) if(_use_core_foundation_and_core_services)
find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation") find_library(COREFOUNDATION_FRAMEWORK NAMES "CoreFoundation")
mark_as_advanced(COREFOUNDATION_FRAMEWORK) mark_as_advanced(COREFOUNDATION_FRAMEWORK)
find_library(CORESERVICES_FRAMEWORK "CoreServices")
mark_as_advanced(CORESERVICES_FRAMEWORK)
if(NOT COREFOUNDATION_FRAMEWORK) if(NOT COREFOUNDATION_FRAMEWORK)
message(FATAL_ERROR "CoreFoundation framework not found") message(FATAL_ERROR "CoreFoundation framework not found")
endif() endif()
list(APPEND CURL_LIBS "-framework CoreFoundation")
find_library(CORESERVICES_FRAMEWORK NAMES "CoreServices")
mark_as_advanced(CORESERVICES_FRAMEWORK)
if(NOT CORESERVICES_FRAMEWORK) if(NOT CORESERVICES_FRAMEWORK)
message(FATAL_ERROR "CoreServices framework not found") message(FATAL_ERROR "CoreServices framework not found")
endif() endif()
list(APPEND CURL_LIBS "-framework CoreServices")
list(APPEND CURL_LIBS "-framework CoreFoundation" "-framework CoreServices")
endif() endif()
if(CURL_USE_OPENSSL) if(CURL_USE_OPENSSL)

View File

@ -317,6 +317,7 @@ Details via CMake
- `BROTLIDEC_LIBRARY`: Path to `brotlidec` library. - `BROTLIDEC_LIBRARY`: Path to `brotlidec` library.
- `CARES_INCLUDE_DIR`: The c-ares include directory. - `CARES_INCLUDE_DIR`: The c-ares include directory.
- `CARES_LIBRARY`: Path to `cares` library. - `CARES_LIBRARY`: Path to `cares` library.
- `DL_LIBRARY`: Path to `dl` library. (for Rustls)
- `GSS_ROOT_DIR`: Set this variable to the root installation of GSS. (also supported as environment) - `GSS_ROOT_DIR`: Set this variable to the root installation of GSS. (also supported as environment)
- `LDAP_LIBRARY`: Name or full path to `ldap` library. Default: `ldap` - `LDAP_LIBRARY`: Name or full path to `ldap` library. Default: `ldap`
- `LDAP_LBER_LIBRARY`: Name or full path to `lber` library. Default: `lber` - `LDAP_LBER_LIBRARY`: Name or full path to `lber` library. Default: `lber`
@ -335,12 +336,13 @@ Details via CMake
- `LIBSSH2_LIBRARY`: Path to `libssh2` library. - `LIBSSH2_LIBRARY`: Path to `libssh2` library.
- `LIBUV_INCLUDE_DIR`: The libuv include directory. - `LIBUV_INCLUDE_DIR`: The libuv include directory.
- `LIBUV_LIBRARY`: Path to `libuv` library. - `LIBUV_LIBRARY`: Path to `libuv` library.
- `MSH3_INCLUDE_DIR`: The msh3 include directory. - `MATH_LIBRARY`: Path to `m` library. (for Rustls, wolfSSL)
- `MSH3_LIBRARY`: Path to `msh3` library.
- `MBEDTLS_INCLUDE_DIR`: The mbedTLS include directory. - `MBEDTLS_INCLUDE_DIR`: The mbedTLS include directory.
- `MBEDTLS_LIBRARY`: Path to `mbedtls` library. - `MBEDTLS_LIBRARY`: Path to `mbedtls` library.
- `MBEDX509_LIBRARY`: Path to `mbedx509` library. - `MBEDX509_LIBRARY`: Path to `mbedx509` library.
- `MBEDCRYPTO_LIBRARY`: Path to `mbedcrypto` library. - `MBEDCRYPTO_LIBRARY`: Path to `mbedcrypto` library.
- `MSH3_INCLUDE_DIR`: The msh3 include directory.
- `MSH3_LIBRARY`: Path to `msh3` library.
- `NGHTTP2_INCLUDE_DIR`: The nghttp2 include directory. - `NGHTTP2_INCLUDE_DIR`: The nghttp2 include directory.
- `NGHTTP2_LIBRARY`: Path to `nghttp2` library. - `NGHTTP2_LIBRARY`: Path to `nghttp2` library.
- `NGHTTP3_INCLUDE_DIR`: The nghttp3 include directory. - `NGHTTP3_INCLUDE_DIR`: The nghttp3 include directory.
@ -349,6 +351,7 @@ Details via CMake
- `NGTCP2_LIBRARY`: Path to `ngtcp2` library. - `NGTCP2_LIBRARY`: Path to `ngtcp2` library.
- `NETTLE_INCLUDE_DIR`: The nettle include directory. - `NETTLE_INCLUDE_DIR`: The nettle include directory.
- `NETTLE_LIBRARY`: Path to `nettle` library. - `NETTLE_LIBRARY`: Path to `nettle` library.
- `PTHREAD_LIBRARY`: Path to `pthread` library. (for Rustls)
- `QUICHE_INCLUDE_DIR`: The quiche include directory. - `QUICHE_INCLUDE_DIR`: The quiche include directory.
- `QUICHE_LIBRARY`: Path to `quiche` library. - `QUICHE_LIBRARY`: Path to `quiche` library.
- `RUSTLS_INCLUDE_DIR`: The Rustls include directory. - `RUSTLS_INCLUDE_DIR`: The Rustls include directory.