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 | |
| 6 | find_package(Python3 COMPONENTS Interpreter REQUIRED) |
| 7 | |
| 8 | add_library(rmm-mbedtls INTERFACE) |
| 9 | target_include_directories(rmm-mbedtls INTERFACE ${RMM_SOURCE_DIR}/configs/mbedtls) |
| 10 | target_compile_definitions(rmm-mbedtls INTERFACE MBEDTLS_CONFIG_FILE=<mbedtls_config.h>) |
| 11 | |
| 12 | include_directories(${RMM_SOURCE_DIR}/configs/mbedtls) |
| 13 | add_compile_definitions(MBEDTLS_CONFIG_FILE=<mbedtls_config.h>) |
| 14 | |
Soby Mathew | d2d394e | 2023-01-04 14:41:17 +0000 | [diff] [blame] | 15 | # |
| 16 | # Workaround for CMake not detecting size of pointer on AArch64 toolchain and |
| 17 | # causing MbedTLS compilation to print warning during configuration. |
| 18 | # |
| 19 | if(RMM_ARCH STREQUAL aarch64) |
| 20 | set(CMAKE_SIZEOF_VOID_P 8) |
| 21 | endif() |
| 22 | |
Soby Mathew | 73dad84 | 2022-12-16 12:51:01 +0000 | [diff] [blame] | 23 | set(ENABLE_PROGRAMS OFF CACHE BOOL "Setting for mbedtls program") |
| 24 | set(ENABLE_TESTING OFF CACHE BOOL "Setting for mbedtls tests") |
| 25 | |
Soby Mathew | 02443e9 | 2023-05-12 10:49:27 +0100 | [diff] [blame] | 26 | # Ensure that the CFlags modifications are local in scope and only apply to |
| 27 | # MbedTLS build |
| 28 | set(BACKUP_C_CLAGS "${CMAKE_C_FLAGS}") |
| 29 | |
Soby Mathew | 73dad84 | 2022-12-16 12:51:01 +0000 | [diff] [blame] | 30 | if(RMM_FPU_USE_AT_REL2) |
| 31 | # Enable using floating point registers for mbed TLS |
| 32 | string(REPLACE "-mgeneral-regs-only" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) |
| 33 | # Enable using crypto and sha instructions |
| 34 | string(REGEX REPLACE "(march=[^\\ ]*)" "\\1+sha3+crypto" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) |
| 35 | # Enable using SHA256 and SHA512 instructions in MbedTLS |
| 36 | string(APPEND CMAKE_C_FLAGS |
| 37 | " -DMBEDTLS_SHA256_USE_A64_CRYPTO_ONLY=1 " |
| 38 | " -DMBEDTLS_SHA512_USE_A64_CRYPTO_ONLY=1 ") |
| 39 | endif() |
| 40 | |
| 41 | # |
| 42 | # Add the mbedtls subdirectory and exclude all targets in mbedtls from |
| 43 | # default `all` target |
| 44 | # |
Soby Mathew | 372484a | 2023-04-20 14:40:52 +0100 | [diff] [blame] | 45 | add_subdirectory("${RMM_SOURCE_DIR}/ext/mbedtls" "${CMAKE_BINARY_DIR}/ext/mbedtls" EXCLUDE_FROM_ALL) |
Soby Mathew | 73dad84 | 2022-12-16 12:51:01 +0000 | [diff] [blame] | 46 | |
| 47 | target_link_libraries(rmm-mbedtls INTERFACE mbedtls) |
Soby Mathew | 02443e9 | 2023-05-12 10:49:27 +0100 | [diff] [blame] | 48 | |
| 49 | # Restore the original CXX flags. |
| 50 | set(CMAKE_C_FLAGS "${BACKUP_C_FLAGS}") |