From d62f137bcdc3905d85cce836ba445f20686e17a3 Mon Sep 17 00:00:00 2001 From: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> Date: Tue, 21 Apr 2026 14:41:35 +0200 Subject: [PATCH] feat(zephyr): support v4.4 - fix(cmake): only create alias if it doesn't exist: Zephyr v4.4 has moved to MbedTLS 4.x in following PR: https://github.com/zephyrproject-rtos/zephyr/pull/104031 Zephyr now uses MbedTLS' CMakeLists, which exports targets with NAMESPACE MbedTLS::, therefore MbedTLS::mbedtls, MbedTLS::mbedx509, MbedTLS::tfpsacrypto aliases already exist - fix(zephyr): v4.4: include correct mbedtls config based on zephyr version CONFIG_MBEDTLS_CFG_FILE was deprecated. Instead, CONFIG_MBEDTLS_CONFIG_FILE shall be used. This change supports both based on Kconfig symbols. Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com> --- CMakeLists.txt | 14 +++++++++++--- zephyr/CMakeLists.txt | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 776f4056..c3388d02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -801,9 +801,17 @@ target_compile_options( PUBLIC -DLIBCOAP_PACKAGE_BUILD="${LIBCOAP_PACKAGE_BUILD}") if(ZEPHYR_BASE) -target_compile_options( - ${COAP_LIBRARY_NAME} - PUBLIC -DMBEDTLS_CONFIG_FILE="${CONFIG_MBEDTLS_CFG_FILE}" -I${ZEPHYR_MBEDTLS_CMAKE_DIR}/configs) + # Zephyr >= v4.4: + if(DEFINED CONFIG_MBEDTLS_CONFIG_FILE) + target_compile_options(${COAP_LIBRARY_NAME} + PUBLIC -DMBEDTLS_CONFIG_FILE="${CONFIG_MBEDTLS_CONFIG_FILE}" -I${ZEPHYR_MBEDTLS_CMAKE_DIR}/configs) + # Zephyr < v4.4: + elseif(DEFINED CONFIG_MBEDTLS_CFG_FILE) + target_compile_options(${COAP_LIBRARY_NAME} + PUBLIC -DMBEDTLS_CONFIG_FILE="${CONFIG_MBEDTLS_CFG_FILE}" -I${ZEPHYR_MBEDTLS_CMAKE_DIR}/configs) + else() + message(WARNING "No usable MBEDTLS config Kconfig symbol found") + endif() endif() # ! ZEPHYR_BASE add_library( diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 8a36ae6f..c734585c 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -159,7 +159,10 @@ if(CONFIG_LIBCOAP) if(CONFIG_MBEDTLS) if(TARGET mbedTLS) target_include_directories(mbedTLS INTERFACE ${ZEPHYR_LIBCOAP_MODULE_DIR}/include) - add_library(MbedTLS::mbedtls ALIAS mbedTLS) + # Only create alias if it doesn't already exist (Zephyr v4.4+ has it) + if(NOT TARGET MbedTLS::mbedtls) + add_library(MbedTLS::mbedtls ALIAS mbedTLS) + endif() else() message(WARNING "mbedTLS target not found.") endif()