1#-------------------------------------------------------------------------------
2# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8# The Configuration sequence is captured in the documentation, in
9# docs/getting_started/tfm_build_instructions.rst under Cmake Configuration. If
10# the sequence is updated here the docs must also be updated.
11
12# The default build type is MinSizeRel. If debug symbols are needed then
13# -DCMAKE_BUILD_TYPE=debug should be used (likewise with other build types)
14if (NOT CMAKE_BUILD_TYPE)
15    set(CMAKE_BUILD_TYPE "MinSizeRel" CACHE STRING "Build type: [Debug, Release, RelWithDebInfo, MinSizeRel]" FORCE)
16endif()
17
18if (TFM_LIB_MODEL)
19    message(FATAL_ERROR "Library Model is deprecated, please DO NOT use TFM_LIB_MODEL anymore."
20                        "SFN model is a replacement for Library Model. You can use -DCONFIG_TFM_SPM_BACKEND=SFN to select SFN model.")
21endif()
22
23# Load extra config
24if (TFM_EXTRA_CONFIG_PATH)
25    include(${TFM_EXTRA_CONFIG_PATH})
26endif()
27
28# Set TF-M project config header file
29add_library(tfm_config INTERFACE)
30
31# Load PSA config, setting options not already set
32if (TEST_PSA_API)
33    include(config/tests/config_test_psa_api.cmake)
34endif()
35
36# Load build type config, setting options not already set
37string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWERCASE)
38if (EXISTS ${CMAKE_SOURCE_DIR}/config/build_type/${CMAKE_BUILD_TYPE_LOWERCASE}.cmake)
39    include(${CMAKE_SOURCE_DIR}/config/build_type/${CMAKE_BUILD_TYPE_LOWERCASE}.cmake)
40endif()
41
42# Load platform config, setting options not already set
43if (EXISTS ${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/config.cmake)
44    include(platform/ext/target/${TFM_PLATFORM}/config.cmake)
45endif()
46
47# Load configs generated from Kconfig
48include(${CMAKE_SOURCE_DIR}/config/kconfig.cmake)
49
50# Parse tf-m-tests config prior to platform specific config.cmake
51# Some platforms select different configuration according when regression tests
52# are enabled.
53include(lib/ext/tf-m-tests/reg_parse.cmake)
54
55# Load profile config, setting options not already set
56if (TFM_PROFILE)
57    include(config/profile/${TFM_PROFILE}.cmake)
58endif()
59
60# Load Secure Partition settings according to regression configuration as all SPs are disabled
61# by default
62if(TFM_S_REG_TEST OR TFM_NS_REG_TEST)
63    include(${CMAKE_CURRENT_LIST_DIR}/tests/regression_config.cmake)
64endif()
65
66include(${CMAKE_SOURCE_DIR}/config/tfm_build_log_config.cmake)
67
68# Load TF-M model specific default config
69# Load IPC backend config if isolation level is explicitly specified to 2/3 or IPC backend is
70# selected via build command line. Otherwise, load SFN backend config by default.
71# If a pair of invalid settings are passed via command line, it will be captured later via config
72# check.
73# Also select IPC model by default for multi-core platform unless it has already selected SFN model
74if ((DEFINED TFM_ISOLATION_LEVEL AND TFM_ISOLATION_LEVEL GREATER 1) OR
75    CONFIG_TFM_SPM_BACKEND STREQUAL "IPC" OR
76    TFM_MULTI_CORE_TOPOLOGY)
77    include(config/tfm_ipc_config_default.cmake)
78else()
79    #The default backend is SFN
80    include(config/tfm_sfn_config_default.cmake)
81endif()
82
83# Load bl1 config
84if (BL1 AND PLATFORM_DEFAULT_BL1)
85    include(${CMAKE_SOURCE_DIR}/bl1/config/bl1_config_default.cmake)
86endif()
87
88# Load MCUboot specific default.cmake
89if (NOT DEFINED BL2 OR BL2)
90    include(${CMAKE_SOURCE_DIR}/bl2/ext/mcuboot/mcuboot_default_config.cmake)
91endif()
92
93# Include FWU partition configs.
94include(config/tfm_fwu_config.cmake)
95
96# Include coprocessor configs
97include(config/cp_config_default.cmake)
98
99# Load defaults, setting options not already set
100include(config/config_base.cmake)
101
102# Fetch tf-m-tests repo during config, if NS or regression test is required.
103# Therefore tf-m-tests configs can be set with TF-M configs since their configs
104# are coupled.
105include(lib/ext/tf-m-tests/fetch_repo.cmake)
106
107# Set secure log configs
108# It also depends on regression test config.
109include(config/tfm_secure_log.cmake)
110
111# Set user defined TF-M config header file
112if(PROJECT_CONFIG_HEADER_FILE)
113    if(NOT EXISTS ${PROJECT_CONFIG_HEADER_FILE})
114        message(FATAL_ERROR "${PROJECT_CONFIG_HEADER_FILE} does not exist! Please use absolute path.")
115    endif()
116    target_compile_definitions(tfm_config
117        INTERFACE
118            PROJECT_CONFIG_HEADER_FILE="${PROJECT_CONFIG_HEADER_FILE}"
119    )
120endif()
121
122# Set platform defined TF-M config header file
123set(TARGET_CONFIG_HEADER_FILE "${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/config_tfm_target.h")
124if(EXISTS ${TARGET_CONFIG_HEADER_FILE})
125    target_compile_definitions(tfm_config
126        INTERFACE
127            TARGET_CONFIG_HEADER_FILE="${TARGET_CONFIG_HEADER_FILE}"
128    )
129endif()
130