Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Raef Coles | d97a7e7 | 2021-12-10 14:58:06 +0000 | [diff] [blame] | 2 | # Copyright (c) 2020-2022, Arm Limited. All rights reserved. |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
Raef Coles | 6981732 | 2020-10-19 14:14:14 +0100 | [diff] [blame] | 8 | cmake_minimum_required(VERSION 3.15) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 9 | |
Anton Komlev | ceafd01 | 2021-10-11 23:21:11 +0100 | [diff] [blame] | 10 | include(version.cmake) |
Gyorgy Szing | 30fa987 | 2017-12-05 01:08:47 +0000 | [diff] [blame] | 11 | |
Raef Coles | 9ec67e6 | 2020-07-10 09:40:35 +0100 | [diff] [blame] | 12 | ############################ CONFIGURATION ##################################### |
| 13 | |
Øyvind Rønningstad | a9d5eac | 2021-01-22 14:21:25 +0100 | [diff] [blame] | 14 | if (IS_ABSOLUTE "${TFM_PLATFORM}") |
| 15 | file(RELATIVE_PATH TFM_PLATFORM_RELATIVE_PATH |
| 16 | "${CMAKE_CURRENT_SOURCE_DIR}/platform/ext/target" |
| 17 | ${TFM_PLATFORM}) |
| 18 | set(TFM_PLATFORM "${TFM_PLATFORM_RELATIVE_PATH}" CACHE STRING "Target platform set as an absolute path." FORCE) |
| 19 | endif() |
| 20 | |
Tamas Ban | 6921920 | 2020-10-27 08:13:18 +0000 | [diff] [blame] | 21 | # Some compiler flags depend on the CPU / platform config. This include should |
| 22 | # be run before the toolchain file so the compiler can be configured properly. |
| 23 | if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload.cmake) |
| 24 | Message(FATAL_ERROR "Unsupported TFM_PLATFORM ${TFM_PLATFORM}") |
| 25 | else() |
| 26 | include(platform/ext/target/${TFM_PLATFORM}/preload.cmake) |
| 27 | endif() |
| 28 | |
Raef Coles | fbc34cc | 2020-11-24 14:27:52 +0000 | [diff] [blame] | 29 | if(TFM_SYSTEM_MVE) |
| 30 | message(FATAL_ERROR "Hardware MVE is currently not supported in TF-M") |
| 31 | endif() |
| 32 | if(TFM_SYSTEM_DSP) |
| 33 | message(FATAL_ERROR "Hardware DSP is currently not supported in TF-M") |
| 34 | endif() |
| 35 | |
Jianliang Shen | 89cdb35 | 2021-11-03 10:27:12 +0800 | [diff] [blame] | 36 | # The default build type is release. If debug symbols are needed then |
| 37 | # -DCMAKE_BUILD_TYPE=debug should be used (likewise with other build types) |
| 38 | if (NOT CMAKE_BUILD_TYPE) |
| 39 | set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type: [Debug, Release, RelWithDebInfo, MinSizeRel]" FORCE) |
| 40 | endif() |
| 41 | |
Raef Coles | 958aeef | 2020-10-08 12:12:58 +0100 | [diff] [blame] | 42 | include(config/set_config.cmake) |
Raef Coles | 9ec67e6 | 2020-07-10 09:40:35 +0100 | [diff] [blame] | 43 | |
Raef Coles | 6981732 | 2020-10-19 14:14:14 +0100 | [diff] [blame] | 44 | if(NOT ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles" AND |
| 45 | NOT ${CMAKE_GENERATOR} STREQUAL "Ninja") |
| 46 | Message(FATAL_ERROR "Unsupported generator ${CMAKE_GENERATOR}. Hint: Try -G\"Unix Makefiles\"") |
| 47 | endif() |
| 48 | |
Raef Coles | 6981732 | 2020-10-19 14:14:14 +0100 | [diff] [blame] | 49 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| 50 | |
| 51 | ############################### Compiler configuration ######################### |
| 52 | |
Raef Coles | 6981732 | 2020-10-19 14:14:14 +0100 | [diff] [blame] | 53 | #Legacy compat option - load CMAKE_TOOLCHAIN_FILE as a TFM_TOOLCHAIN_FILE |
| 54 | if (CMAKE_TOOLCHAIN_FILE) |
| 55 | message(DEPRECATION "SETTING CMAKE_TOOLCHAIN_FILE is deprecated. It has been replaced with TFM_TOOLCHAIN_FILE.") |
| 56 | message(DEPRECATION "INTERPRETING -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} as -DTFM_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") |
| 57 | set(TFM_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE}) |
| 58 | unset(CMAKE_TOOLCHAIN_FILE) |
| 59 | endif() |
| 60 | |
Raef Coles | 956bd5c | 2020-11-03 11:30:26 +0000 | [diff] [blame] | 61 | if (NOT IS_ABSOLUTE ${TFM_TOOLCHAIN_FILE}) |
| 62 | message(FATAL_ERROR "SETTING CMAKE_TOOLCHAIN_FILE no longer accepts relative paths. Please supply an absolute path or instead use TFM_TOOLCHAIN_FILE (which does accept relative paths)") |
| 63 | endif() |
| 64 | |
Raef Coles | 6981732 | 2020-10-19 14:14:14 +0100 | [diff] [blame] | 65 | include(${TFM_TOOLCHAIN_FILE}) |
| 66 | set(CMAKE_PROJECT_INCLUDE_BEFORE ${CMAKE_SOURCE_DIR}/cmake/disable_compiler_detection.cmake) |
| 67 | |
| 68 | project("Trusted Firmware M" VERSION ${TFM_VERSION} LANGUAGES C ASM) |
| 69 | tfm_toolchain_reload_compiler() |
| 70 | |
Satish Kumar | 1ff4b95 | 2021-05-06 20:22:43 +0100 | [diff] [blame] | 71 | # Synchronise the install path variables. If CMAKE_INSTALL_PREFIX is manually |
| 72 | # set then set both to the value of that, else set both to the value of |
| 73 | # TFM_INSTALL_PATH. This has to be done after the call to `project()`. |
| 74 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 75 | set(CMAKE_INSTALL_PREFIX ${TFM_INSTALL_PATH} CACHE PATH "" FORCE) |
| 76 | else() |
| 77 | set(TFM_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH "Path to which to install TF-M files" FORCE) |
| 78 | endif() |
| 79 | |
Raef Coles | a31a4b6 | 2020-11-10 09:49:17 +0000 | [diff] [blame] | 80 | ############################ Config Check ###################################### |
| 81 | |
| 82 | include(${CMAKE_SOURCE_DIR}/config/check_config.cmake) |
| 83 | |
| 84 | if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/check_config.cmake) |
| 85 | include(platform/ext/target/${TFM_PLATFORM}/check_config.cmake) |
| 86 | endif() |
| 87 | |
Raef Coles | 9ec67e6 | 2020-07-10 09:40:35 +0100 | [diff] [blame] | 88 | ################################################################################ |
| 89 | |
| 90 | add_subdirectory(lib/ext) |
Tamas Ban | b881bea | 2020-11-04 16:18:36 +0000 | [diff] [blame] | 91 | add_subdirectory(lib/fih) |
Raef Coles | 9ec67e6 | 2020-07-10 09:40:35 +0100 | [diff] [blame] | 92 | add_subdirectory(tools) |
Raef Coles | d97a7e7 | 2021-12-10 14:58:06 +0000 | [diff] [blame] | 93 | |
David Hu | 1a2d483 | 2022-01-18 14:42:04 +0800 | [diff] [blame] | 94 | if(NS) |
| 95 | # Set to ${TFM_TEST_REPO_PATH}/app by default |
| 96 | add_subdirectory(${TFM_APP_PATH} ${CMAKE_CURRENT_BINARY_DIR}/app) |
Raef Coles | d97a7e7 | 2021-12-10 14:58:06 +0000 | [diff] [blame] | 97 | endif() |
David Hu | 1a2d483 | 2022-01-18 14:42:04 +0800 | [diff] [blame] | 98 | if(NS OR TEST_BL2) |
| 99 | add_subdirectory(${TFM_RAW_LOG_PATH} ${CMAKE_CURRENT_BINARY_DIR}/raw_log) |
| 100 | endif() |
| 101 | |
| 102 | add_subdirectory(secure_fw) |
Raef Coles | d97a7e7 | 2021-12-10 14:58:06 +0000 | [diff] [blame] | 103 | |
Raef Coles | 9ec67e6 | 2020-07-10 09:40:35 +0100 | [diff] [blame] | 104 | add_subdirectory(interface) |
| 105 | if(BL2) |
| 106 | add_subdirectory(bl2) |
| 107 | endif() |
Raef Coles | 9ec67e6 | 2020-07-10 09:40:35 +0100 | [diff] [blame] | 108 | |
Raef Coles | d97a7e7 | 2021-12-10 14:58:06 +0000 | [diff] [blame] | 109 | add_subdirectory(platform) |
Raef Coles | 9ec67e6 | 2020-07-10 09:40:35 +0100 | [diff] [blame] | 110 | |
David Hu | 1a2d483 | 2022-01-18 14:42:04 +0800 | [diff] [blame] | 111 | if(TFM_S_REG_TEST OR TFM_NS_REG_TEST OR TEST_BL2) |
| 112 | add_subdirectory(${TFM_TEST_PATH} ${CMAKE_CURRENT_BINARY_DIR}/tests) |
| 113 | endif() |
| 114 | |
Raef Coles | 9ec67e6 | 2020-07-10 09:40:35 +0100 | [diff] [blame] | 115 | include(cmake/install.cmake) |
| 116 | |
| 117 | if(CRYPTO_HW_ACCELERATOR) |
| 118 | add_subdirectory(platform/ext/accelerator) |
| 119 | endif() |