blob: a39f3e65e6e142d9b9ab6be35e80fd4bc09e7968 [file] [log] [blame]
Soby Mathew73dad842022-12-16 12:51:01 +00001#
2# SPDX-License-Identifier: BSD-3-Clause
3# SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4#
5
6find_package(Python3 COMPONENTS Interpreter REQUIRED)
7
8add_library(rmm-mbedtls INTERFACE)
9target_include_directories(rmm-mbedtls INTERFACE ${RMM_SOURCE_DIR}/configs/mbedtls)
10target_compile_definitions(rmm-mbedtls INTERFACE MBEDTLS_CONFIG_FILE=<mbedtls_config.h>)
11
12include_directories(${RMM_SOURCE_DIR}/configs/mbedtls)
13add_compile_definitions(MBEDTLS_CONFIG_FILE=<mbedtls_config.h>)
14
Soby Mathewd2d394e2023-01-04 14:41:17 +000015#
16# Workaround for CMake not detecting size of pointer on AArch64 toolchain and
17# causing MbedTLS compilation to print warning during configuration.
18#
19if(RMM_ARCH STREQUAL aarch64)
20 set(CMAKE_SIZEOF_VOID_P 8)
21endif()
22
Soby Mathew73dad842022-12-16 12:51:01 +000023set(ENABLE_PROGRAMS OFF CACHE BOOL "Setting for mbedtls program")
24set(ENABLE_TESTING OFF CACHE BOOL "Setting for mbedtls tests")
25
Soby Mathew02443e92023-05-12 10:49:27 +010026# Ensure that the CFlags modifications are local in scope and only apply to
27# MbedTLS build
28set(BACKUP_C_CLAGS "${CMAKE_C_FLAGS}")
29
Soby Mathew73dad842022-12-16 12:51:01 +000030if(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 ")
39endif()
40
41#
42# Add the mbedtls subdirectory and exclude all targets in mbedtls from
43# default `all` target
44#
Soby Mathew372484a2023-04-20 14:40:52 +010045add_subdirectory("${RMM_SOURCE_DIR}/ext/mbedtls" "${CMAKE_BINARY_DIR}/ext/mbedtls" EXCLUDE_FROM_ALL)
Soby Mathew73dad842022-12-16 12:51:01 +000046
47target_link_libraries(rmm-mbedtls INTERFACE mbedtls)
Soby Mathew02443e92023-05-12 10:49:27 +010048
49# Restore the original CXX flags.
50set(CMAKE_C_FLAGS "${BACKUP_C_FLAGS}")