cmake/FindMbedTLS: add workaround for missing static MSVC mbedcrypto.lib 4.0.0

Seen with mbedTLS 4.0.0. mbedTLS 4.0.0 renamed `mbedcrypto` lib to
`tfpsacrypto`, while also keeping a copy under the old name to aid
transition. However, this compatibility logic is broken for MSVC static
builds, and the old name missing.

Work around by looking for the new name in the raw detection codepath.

Note that using `pkg-config`-based detection also works as a workaround.

Reported-by: tawmoto on github
Fixes #20616
Ref: https://github.com/Mbed-TLS/mbedtls/blob/v4.0.0/library/CMakeLists.txt#L275-L282
Ref: https://github.com/Mbed-TLS/mbedtls/issues/10605

Closes #20617
This commit is contained in:
Viktor Szakats 2026-02-18 13:21:19 +01:00
parent 4497dbd9ac
commit 7e203c15e6
No known key found for this signature in database

View File

@ -72,11 +72,12 @@ else()
if(MBEDTLS_USE_STATIC_LIBS)
find_library(MBEDTLS_LIBRARY NAMES "mbedtls_static" "libmbedtls_static" "mbedtls" "libmbedtls")
find_library(MBEDX509_LIBRARY NAMES "mbedx509_static" "libmbedx509_static" "mbedx509" "libmbedx509")
find_library(MBEDCRYPTO_LIBRARY NAMES "mbedcrypto_static" "libmbedcrypto_static" "mbedcrypto" "libmbedcrypto")
find_library(MBEDCRYPTO_LIBRARY NAMES "mbedcrypto_static" "libmbedcrypto_static" "mbedcrypto" "libmbedcrypto"
"tfpsacrypto_static" "libtfpsacrypto_static" "tfpsacrypto" "libtfpsacrypto")
else()
find_library(MBEDTLS_LIBRARY NAMES "mbedtls" "libmbedtls")
find_library(MBEDX509_LIBRARY NAMES "mbedx509" "libmbedx509")
find_library(MBEDCRYPTO_LIBRARY NAMES "mbedcrypto" "libmbedcrypto")
find_library(MBEDCRYPTO_LIBRARY NAMES "mbedcrypto" "libmbedcrypto" "tfpsacrypto" "libtfpsacrypto")
endif()
unset(MBEDTLS_VERSION CACHE)