| #------------------------------------------------------------------------------- |
| # Copyright (c) 2018-2019, Arm Limited. All rights reserved. |
| # |
| # SPDX-License-Identifier: BSD-3-Clause |
| # |
| #------------------------------------------------------------------------------- |
| |
| cmake_minimum_required(VERSION 3.7) |
| |
| #Tell cmake where our modules can be found |
| list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../../cmake) |
| |
| #Include common stuff to control cmake. |
| include("Common/BuildSys") |
| |
| #Start an embedded project. |
| embedded_project_start(CONFIG "${CMAKE_CURRENT_LIST_DIR}/../../../ConfigDefault.cmake") |
| project(tfm_crypto LANGUAGES ASM C) |
| embedded_project_fixup() |
| |
| #Some project global settings |
| set (CRYPTO_DIR "${CMAKE_CURRENT_LIST_DIR}") |
| get_filename_component(TFM_ROOT_DIR "${CRYPTO_DIR}/../../.." ABSOLUTE) |
| |
| #Get the definition of what files we need to build |
| set (ENABLE_CRYPTO ON) |
| if (NOT DEFINED CRYPTO_ENGINE_MBEDTLS) |
| set (CRYPTO_ENGINE_MBEDTLS ON) |
| endif() |
| |
| if (CRYPTO_ENGINE_MBEDTLS) |
| #Define location of mbed TLS source, build, and installation directory. |
| get_filename_component(MBEDTLS_SOURCE_DIR "${TFM_ROOT_DIR}/../mbedtls" ABSOLUTE) |
| set (MBEDTLS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/mbedtls") |
| set (MBEDTLS_INSTALL_DIR ${MBEDTLS_BINARY_DIR}/mbedtls_install) |
| set (MBEDTLS_TARGET_NAME "mbedtls_crypto_lib") |
| endif() |
| |
| include(CMakeLists.inc) |
| |
| #Configure how we build our target |
| if(DEFINED CORE_TEST) |
| set (TFM_LVL 3) |
| else() |
| set (TFM_LVL 1) |
| endif() |
| |
| #Create a list of the C defines |
| list(APPEND TFM_CRYPTO_C_DEFINES_LIST __ARM_FEATURE_CMSE=3 __thumb2__ TFM_LVL=${TFM_LVL}) |
| |
| if (CRYPTO_ENGINE_MBEDTLS) |
| list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_ENGINE_MBEDTLS MBEDTLS_CONFIG_FILE="platform/ext/common/tfm_mbedtls_config.h") |
| endif() |
| |
| #Add module configuration parameters in case they are provided during cmake configuration step |
| if (DEFINED CRYPTO_KEY_STORAGE_NUM) |
| list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_KEY_STORAGE_NUM=${CRYPTO_KEY_STORAGE_NUM}) |
| endif() |
| if (DEFINED CRYPTO_KEY_MAX_KEY_LENGTH) |
| list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_KEY_MAX_KEY_LENGTH=${CRYPTO_KEY_MAX_KEY_LENGTH}) |
| endif() |
| if (DEFINED CRYPTO_ENGINE_BUF_SIZE) |
| list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_ENGINE_BUF_SIZE=${CRYPTO_ENGINE_BUF_SIZE}) |
| endif() |
| if (TFM_PSA_API AND DEFINED CRYPTO_IOVEC_BUFFER_SIZE) |
| list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_IOVEC_BUFFER_SIZE=${CRYPTO_IOVEC_BUFFER_SIZE}) |
| endif() |
| |
| if (CRYPTO_ENGINE_MBEDTLS) |
| #Set mbed TLS compiler flags |
| set(MBEDTLS_C_FLAGS ${MBEDTLS_C_FLAGS_SERVICES}) |
| |
| #Set preinclude header options for mbed TLS |
| set(MBEDTLS_PREINCLUDE_PREFIX __tfm_crypto__) |
| set(MBEDTLS_PREINCLUDE_HEADER ${CRYPTO_DIR}/mbedtls_global_symbols.h) |
| |
| #Build mbed TLS as external project. |
| #This ensures mbed TLS is built with exactly defined settings. |
| #mbed TLS will be used from its install location |
| include(${TFM_ROOT_DIR}/BuildMbedtls.cmake) |
| endif() |
| |
| #Specify what we build (for the crypto service, build as a static library) |
| add_library(tfm_crypto STATIC ${ALL_SRC_ASM} ${ALL_SRC_C}) |
| embedded_set_target_compile_defines(TARGET tfm_crypto LANGUAGE C DEFINES ${TFM_CRYPTO_C_DEFINES_LIST}) |
| if (CRYPTO_ENGINE_MBEDTLS) |
| #Add a dependency on the mbed_tls_lib_install target. |
| add_dependencies(tfm_crypto ${MBEDTLS_TARGET_NAME}_install) |
| #Ask the compiler to merge the mbed TLS and the crypto libraries. |
| compiler_merge_library(DEST tfm_crypto LIBS "${MBEDTLS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX_C}mbedcrypto${CMAKE_STATIC_LIBRARY_SUFFIX_C}") |
| endif() |
| |
| #Set common compiler and linker flags |
| config_setting_shared_compiler_flags(tfm_crypto) |
| config_setting_shared_linker_flags(tfm_crypto) |
| |
| embedded_project_end(tfm_crypto) |