blob: 02f1b179b5469e266371565c453ef1c10f232a25 [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
26# The CFlags modifications are local in scope and only apply to MbedTLS build
27if(RMM_FPU_USE_AT_REL2)
28 # Enable using floating point registers for mbed TLS
29 string(REPLACE "-mgeneral-regs-only" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
30 # Enable using crypto and sha instructions
31 string(REGEX REPLACE "(march=[^\\ ]*)" "\\1+sha3+crypto" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
32 # Enable using SHA256 and SHA512 instructions in MbedTLS
33 string(APPEND CMAKE_C_FLAGS
34 " -DMBEDTLS_SHA256_USE_A64_CRYPTO_ONLY=1 "
35 " -DMBEDTLS_SHA512_USE_A64_CRYPTO_ONLY=1 ")
36endif()
37
38#
39# Add the mbedtls subdirectory and exclude all targets in mbedtls from
40# default `all` target
41#
Soby Mathew372484a2023-04-20 14:40:52 +010042add_subdirectory("${RMM_SOURCE_DIR}/ext/mbedtls" "${CMAKE_BINARY_DIR}/ext/mbedtls" EXCLUDE_FROM_ALL)
Soby Mathew73dad842022-12-16 12:51:01 +000043
44target_link_libraries(rmm-mbedtls INTERFACE mbedtls)