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 | |
Arunachalam Ganapathy | d9e8e1b | 2024-04-19 16:27:14 +0100 | [diff] [blame] | 6 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/tools/common") |
| 7 | include(GitUtils) |
| 8 | |
Mate Toth-Pal | 83a45bd | 2023-09-01 11:17:19 +0200 | [diff] [blame] | 9 | # The Mbed TLS library is not included in the CBMC analysis |
| 10 | if(RMM_CBMC_STATIC_ANALYSIS) |
| 11 | add_library(rmm-mbedtls INTERFACE) |
| 12 | return() |
| 13 | endif() |
| 14 | |
Mate Toth-Pal | c69951d | 2023-03-17 17:30:50 +0100 | [diff] [blame] | 15 | set(MBEDTLS_SRC_DIR "${RMM_SOURCE_DIR}/ext/mbedtls") |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame^] | 16 | set(MBEDTLS_BIN_DIR "${CMAKE_BINARY_DIR}/ext/mbedtls") |
Mate Toth-Pal | c69951d | 2023-03-17 17:30:50 +0100 | [diff] [blame] | 17 | |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame^] | 18 | # 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] | 19 | # For details see commit messages in patch files. |
| 20 | set(MBEDTLS_PATCH_DIR "${RMM_SOURCE_DIR}/configs/mbedtls") |
| 21 | set(MBEDTLS_PATCH_FILES |
| 22 | "${MBEDTLS_PATCH_DIR}/0001-Remove-compiler-options-for-clang.patch" |
Arunachalam Ganapathy | d9e8e1b | 2024-04-19 16:27:14 +0100 | [diff] [blame] | 23 | "${MBEDTLS_PATCH_DIR}/0002-Disable-explicit_bzero.patch") |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame^] | 24 | |
Arunachalam Ganapathy | d9e8e1b | 2024-04-19 16:27:14 +0100 | [diff] [blame] | 25 | Git_Apply_Patches(${MBEDTLS_SRC_DIR} "${MBEDTLS_PATCH_FILES}") |
Mate Toth-Pal | c69951d | 2023-03-17 17:30:50 +0100 | [diff] [blame] | 26 | |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame^] | 27 | # Starting Mbed TLS 3.x release, mbedtls/library/CMakeLists.txt has dependency on |
| 28 | # link_to_source() function that is in mbedtls/CMakeLists.txt, so define a dummy |
| 29 | # link_to_source here. |
| 30 | function(link_to_source base_name) |
| 31 | endfunction(link_to_source) |
Soby Mathew | 73dad84 | 2022-12-16 12:51:01 +0000 | [diff] [blame] | 32 | |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame^] | 33 | # Ensure that the CFlags modifications are local in scope and only apply to |
| 34 | # MbedTLS build |
| 35 | if(RMM_FPU_USE_AT_REL2) |
| 36 | set(BACKUP_C_FLAGS "${CMAKE_C_FLAGS}") |
| 37 | # Enable using floating point registers for mbed TLS |
| 38 | string(REPLACE "-mgeneral-regs-only" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) |
| 39 | # Enable using crypto and sha instructions |
| 40 | string(REGEX REPLACE "(march=[^\\ ]*)" "\\1+sha3+crypto+nosve" CMAKE_C_FLAGS |
| 41 | ${CMAKE_C_FLAGS}) |
Soby Mathew | 02443e9 | 2023-05-12 10:49:27 +0100 | [diff] [blame] | 42 | |
Arunachalam Ganapathy | 188d9e6 | 2024-04-18 13:42:56 +0100 | [diff] [blame^] | 43 | add_subdirectory("${MBEDTLS_SRC_DIR}/library" "${MBEDTLS_BIN_DIR}/library" |
| 44 | EXCLUDE_FROM_ALL) |
| 45 | |
| 46 | set(CMAKE_C_FLAGS "${BACKUP_C_FLAGS}") |
| 47 | else() |
| 48 | add_subdirectory("${MBEDTLS_SRC_DIR}/library" "${MBEDTLS_BIN_DIR}/library" |
| 49 | EXCLUDE_FROM_ALL) |
| 50 | endif() |
| 51 | |
| 52 | # Include targets mbedcrypto |
| 53 | add_library(rmm-mbedtls INTERFACE) |
| 54 | target_include_directories(rmm-mbedtls INTERFACE |
| 55 | "${RMM_SOURCE_DIR}/configs/mbedtls" |
| 56 | "${MBEDTLS_SRC_DIR}/include") |
| 57 | target_compile_definitions(rmm-mbedtls INTERFACE |
| 58 | "-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>") |
| 59 | |
| 60 | target_include_directories(mbedcrypto PUBLIC |
| 61 | "${RMM_SOURCE_DIR}/configs/mbedtls" |
| 62 | "${MBEDTLS_SRC_DIR}/include") |
| 63 | target_compile_definitions(mbedcrypto PUBLIC |
| 64 | "-DMBEDTLS_CONFIG_FILE=<mbedtls_config.h>") |
| 65 | target_link_libraries(rmm-mbedtls INTERFACE mbedcrypto) |