Soby Mathew | 73dad84 | 2022-12-16 12:51:01 +0000 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: BSD-3-Clause |
| 3 | # SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | # |
| 5 | |
Mate Toth-Pal | 83a45bd | 2023-09-01 11:17:19 +0200 | [diff] [blame] | 6 | # The Mbed TLS library is not included in the CBMC analysis |
| 7 | if(RMM_CBMC_STATIC_ANALYSIS) |
| 8 | add_library(rmm-mbedtls INTERFACE) |
| 9 | return() |
| 10 | endif() |
| 11 | |
Mate Toth-Pal | c69951d | 2023-03-17 17:30:50 +0100 | [diff] [blame] | 12 | set(MBEDTLS_SRC_DIR "${RMM_SOURCE_DIR}/ext/mbedtls") |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame] | 13 | set(MBEDTLS_BIN_DIR "${CMAKE_BINARY_DIR}/ext/mbedtls") |
Mate Toth-Pal | c69951d | 2023-03-17 17:30:50 +0100 | [diff] [blame] | 14 | |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame] | 15 | # Patch Mbed TLS before add_subdirectory() this allows to patch CMake files. |
Mate Toth-Pal | c69951d | 2023-03-17 17:30:50 +0100 | [diff] [blame] | 16 | # For details see commit messages in patch files. |
| 17 | set(MBEDTLS_PATCH_DIR "${RMM_SOURCE_DIR}/configs/mbedtls") |
| 18 | set(MBEDTLS_PATCH_FILES |
| 19 | "${MBEDTLS_PATCH_DIR}/0001-Remove-compiler-options-for-clang.patch" |
Mate Toth-Pal | 01b8fb2 | 2025-02-19 17:24:30 +0100 | [diff] [blame] | 20 | "${MBEDTLS_PATCH_DIR}/0002-Disable-explicit_bzero.patch" |
| 21 | "${MBEDTLS_PATCH_DIR}/0003-refactor-alloc-Use-the-heap-structure-provided-by-ap.patch") |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame] | 22 | |
Arunachalam Ganapathy | d9e8e1b | 2024-04-19 16:27:14 +0100 | [diff] [blame] | 23 | Git_Apply_Patches(${MBEDTLS_SRC_DIR} "${MBEDTLS_PATCH_FILES}") |
Mate Toth-Pal | c69951d | 2023-03-17 17:30:50 +0100 | [diff] [blame] | 24 | |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame] | 25 | # Starting Mbed TLS 3.x release, mbedtls/library/CMakeLists.txt has dependency on |
| 26 | # link_to_source() function that is in mbedtls/CMakeLists.txt, so define a dummy |
| 27 | # link_to_source here. |
| 28 | function(link_to_source base_name) |
| 29 | endfunction(link_to_source) |
Soby Mathew | 73dad84 | 2022-12-16 12:51:01 +0000 | [diff] [blame] | 30 | |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame] | 31 | # Ensure that the CFlags modifications are local in scope and only apply to |
| 32 | # MbedTLS build |
| 33 | if(RMM_FPU_USE_AT_REL2) |
| 34 | set(BACKUP_C_FLAGS "${CMAKE_C_FLAGS}") |
| 35 | # Enable using floating point registers for mbed TLS |
| 36 | string(REPLACE "-mgeneral-regs-only" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) |
| 37 | # Enable using crypto and sha instructions |
| 38 | string(REGEX REPLACE "(march=[^\\ ]*)" "\\1+sha3+crypto+nosve" CMAKE_C_FLAGS |
| 39 | ${CMAKE_C_FLAGS}) |
Soby Mathew | 02443e9 | 2023-05-12 10:49:27 +0100 | [diff] [blame] | 40 | |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame] | 41 | add_subdirectory("${MBEDTLS_SRC_DIR}/library" "${MBEDTLS_BIN_DIR}/library" |
| 42 | EXCLUDE_FROM_ALL) |
| 43 | |
| 44 | set(CMAKE_C_FLAGS "${BACKUP_C_FLAGS}") |
| 45 | else() |
| 46 | add_subdirectory("${MBEDTLS_SRC_DIR}/library" "${MBEDTLS_BIN_DIR}/library" |
| 47 | EXCLUDE_FROM_ALL) |
| 48 | endif() |
| 49 | |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame] | 50 | add_library(rmm-mbedtls INTERFACE) |
| 51 | target_include_directories(rmm-mbedtls INTERFACE |
| 52 | "${RMM_SOURCE_DIR}/configs/mbedtls" |
| 53 | "${MBEDTLS_SRC_DIR}/include") |
| 54 | target_compile_definitions(rmm-mbedtls INTERFACE |
Arunachalam Ganapathy | 2da0ed8 | 2024-05-31 13:55:06 +0100 | [diff] [blame] | 55 | "-DMBEDTLS_CONFIG_FILE=<rmm_mbedtls_config.h>") |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame] | 56 | |
Arunachalam Ganapathy | 33e3bdc | 2024-04-10 20:55:40 +0100 | [diff] [blame] | 57 | # Include targets mbedcrypto, mbedx509 |
| 58 | set(MBEDTLS_LIBS mbedcrypto) |
Arunachalam Ganapathy | 56aeccc | 2024-10-24 15:03:55 +0100 | [diff] [blame] | 59 | if(RMM_V1_1) |
Arunachalam Ganapathy | 33e3bdc | 2024-04-10 20:55:40 +0100 | [diff] [blame] | 60 | list(APPEND MBEDTLS_LIBS mbedx509) |
| 61 | endif() |
| 62 | |
| 63 | foreach(MBEDTLS_LIB IN ITEMS ${MBEDTLS_LIBS}) |
| 64 | target_include_directories(${MBEDTLS_LIB} PUBLIC |
| 65 | "${RMM_SOURCE_DIR}/configs/mbedtls" |
| 66 | "${MBEDTLS_SRC_DIR}/include") |
| 67 | target_compile_definitions(${MBEDTLS_LIB} PUBLIC |
| 68 | "-DMBEDTLS_CONFIG_FILE=<rmm_mbedtls_config.h>") |
| 69 | target_link_libraries(rmm-mbedtls INTERFACE ${MBEDTLS_LIB}) |
Mate Toth-Pal | c83c305 | 2025-02-06 10:32:10 +0100 | [diff] [blame] | 70 | target_link_libraries(${MBEDTLS_LIB} PRIVATE rmm-lib-allocator) |
Arunachalam Ganapathy | 33e3bdc | 2024-04-10 20:55:40 +0100 | [diff] [blame] | 71 | endforeach() |