blob: 04bda24de064036898a905c014e899d5e6aeef08 [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001#-------------------------------------------------------------------------------
Antonio de Angeliscf85ba22018-10-09 13:29:40 +01002# Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Antonio de Angelis8908f472018-08-31 15:44:25 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8cmake_minimum_required(VERSION 3.7)
9
10#Tell cmake where our modules can be found
11list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../../cmake)
12
13#Include common stuff to control cmake.
14include("Common/BuildSys")
15
16#Start an embedded project.
17embedded_project_start(CONFIG "${CMAKE_CURRENT_LIST_DIR}/../../../ConfigDefault.cmake")
18project(tfm_crypto LANGUAGES ASM C)
19embedded_project_fixup()
20
Jamie Fox82b87ca2018-12-11 16:41:11 +000021#Some project global settings
Antonio de Angelis8908f472018-08-31 15:44:25 +010022set (CRYPTO_DIR "${CMAKE_CURRENT_LIST_DIR}")
23get_filename_component(TFM_ROOT_DIR "${CRYPTO_DIR}/../../.." ABSOLUTE)
Antonio de Angelis8908f472018-08-31 15:44:25 +010024
Jamie Fox82b87ca2018-12-11 16:41:11 +000025#Get the definition of what files we need to build
Antonio de Angelis8908f472018-08-31 15:44:25 +010026set (ENABLE_CRYPTO ON)
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010027if (NOT DEFINED CRYPTO_ENGINE_MBEDTLS)
28 set (CRYPTO_ENGINE_MBEDTLS ON)
29endif()
30
31if (CRYPTO_ENGINE_MBEDTLS)
32 #Define location of mbed TLS source, build, and installation directory.
33 get_filename_component(MBEDTLS_SOURCE_DIR "${TFM_ROOT_DIR}/../mbedtls" ABSOLUTE)
34 set (MBEDTLS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/mbedtls")
35 set (MBEDTLS_INSTALL_DIR ${MBEDTLS_BINARY_DIR}/mbedtls_install)
36 set (MBEDTLS_TARGET_NAME "mbedtls_crypto_lib")
37endif()
38
Antonio de Angelis8908f472018-08-31 15:44:25 +010039include(CMakeLists.inc)
40
Jamie Fox82b87ca2018-12-11 16:41:11 +000041#Configure how we build our target
Antonio de Angelis8908f472018-08-31 15:44:25 +010042if(DEFINED CORE_TEST)
43 set (TFM_LVL 3)
44else()
45 set (TFM_LVL 1)
46endif()
47
Jamie Fox82b87ca2018-12-11 16:41:11 +000048#Create a list of the C defines
49list(APPEND TFM_CRYPTO_C_DEFINES_LIST __ARM_FEATURE_CMSE=3 __thumb2__ TFM_LVL=${TFM_LVL})
50
51if (CRYPTO_ENGINE_MBEDTLS)
52 list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_ENGINE_MBEDTLS MBEDTLS_CONFIG_FILE="platform/ext/common/tfm_mbedtls_config.h")
53endif()
54
55#Add module configuration parameters in case they are provided during cmake configuration step
56if (DEFINED CRYPTO_KEY_STORAGE_NUM)
57 list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_KEY_STORAGE_NUM=${CRYPTO_KEY_STORAGE_NUM})
58endif()
59if (DEFINED CRYPTO_KEY_MAX_KEY_LENGTH)
60 list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_KEY_MAX_KEY_LENGTH=${CRYPTO_KEY_MAX_KEY_LENGTH})
61endif()
62if (DEFINED CRYPTO_ENGINE_BUF_SIZE)
63 list(APPEND TFM_CRYPTO_C_DEFINES_LIST TFM_CRYPTO_ENGINE_BUF_SIZE=${CRYPTO_ENGINE_BUF_SIZE})
64endif()
65
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010066if (CRYPTO_ENGINE_MBEDTLS)
67 #Set mbed TLS compiler flags
68 set(MBEDTLS_C_FLAGS ${MBEDTLS_C_FLAGS_SERVICES})
Antonio de Angelis8908f472018-08-31 15:44:25 +010069
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010070 #Set preinclude header options for mbed TLS
71 set(MBEDTLS_PREINCLUDE_PREFIX __tfm_crypto__)
72 set(MBEDTLS_PREINCLUDE_HEADER ${CRYPTO_DIR}/mbedtls_global_symbols.h)
73
74 #Build mbed TLS as external project.
75 #This ensures mbed TLS is built with exactly defined settings.
76 #mbed TLS will be used from its install location
77 include(${TFM_ROOT_DIR}/BuildMbedtls.cmake)
78endif()
Antonio de Angelis8908f472018-08-31 15:44:25 +010079
80#Specify what we build (for the crypto service, build as a static library)
81add_library(tfm_crypto STATIC ${ALL_SRC_ASM} ${ALL_SRC_C})
Jamie Fox82b87ca2018-12-11 16:41:11 +000082embedded_set_target_compile_defines(TARGET tfm_crypto LANGUAGE C DEFINES ${TFM_CRYPTO_C_DEFINES_LIST})
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010083if (CRYPTO_ENGINE_MBEDTLS)
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010084 #Add a dependency on the mbed_tls_lib_install target.
85 add_dependencies(tfm_crypto ${MBEDTLS_TARGET_NAME}_install)
86 #Ask the compiler to merge the mbed TLS and the crypto libraries.
87 compiler_merge_library(DEST tfm_crypto LIBS "${MBEDTLS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX_C}mbedcrypto${CMAKE_STATIC_LIBRARY_SUFFIX_C}")
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010088endif()
Jamie Fox82b87ca2018-12-11 16:41:11 +000089
Antonio de Angelis8908f472018-08-31 15:44:25 +010090#Set common compiler and linker flags
91config_setting_shared_compiler_flags(tfm_crypto)
92config_setting_shared_linker_flags(tfm_crypto)
93
94embedded_project_end(tfm_crypto)