Jianliang Shen | 1c4f1c2 | 2022-03-07 15:56:06 +0800 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
David Hu | cc14498 | 2023-01-16 12:24:27 +0800 | [diff] [blame] | 2 | # Copyright (c) 2022-2023, Arm Limited. All rights reserved. |
Jianliang Shen | 1c4f1c2 | 2022-03-07 15:56:06 +0800 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
Anton Komlev | 1ba9ea3 | 2023-08-17 11:39:08 +0100 | [diff] [blame] | 8 | set(TARGET_PATH "${CMAKE_CURRENT_LIST_DIR}/../platform/ext/target") |
Jianliang Shen | 1c4f1c2 | 2022-03-07 15:56:06 +0800 | [diff] [blame] | 9 | |
| 10 | if (NOT IS_ABSOLUTE "${TFM_PLATFORM}" AND NOT IS_DIRECTORY "${TARGET_PATH}/${TFM_PLATFORM}") |
| 11 | # If TFM_PLATFORM is not a relative patch to ${TARGET_PATH}, then it could |
| 12 | # be a platform name, for example an521. Search directories which contain |
Kevin Peng | 79aabb8 | 2023-11-01 10:30:17 +0800 | [diff] [blame] | 13 | # the "cpuarch.cmake" and find the matching one. |
Jianliang Shen | 1c4f1c2 | 2022-03-07 15:56:06 +0800 | [diff] [blame] | 14 | |
Kevin Peng | f38456c | 2023-10-31 15:35:50 +0800 | [diff] [blame] | 15 | # Get the list of directories which have cpuarch.cmake |
| 16 | file(GLOB_RECURSE PLATFORM_PATHS ${TARGET_PATH} "cpuarch.cmake") |
Jianliang Shen | 1c4f1c2 | 2022-03-07 15:56:06 +0800 | [diff] [blame] | 17 | |
| 18 | # Search the list with platform name and store the result in PLATFORM_PATHS |
Jianliang Shen | a94e252 | 2022-07-20 16:37:52 +0800 | [diff] [blame] | 19 | list(FILTER PLATFORM_PATHS INCLUDE REGEX "/${TFM_PLATFORM}/") |
Jianliang Shen | 1c4f1c2 | 2022-03-07 15:56:06 +0800 | [diff] [blame] | 20 | |
| 21 | # Get the length of list PLATFORM_PATHS |
| 22 | list(LENGTH PLATFORM_PATHS _PLATFORM_NUM) |
| 23 | |
| 24 | if (${_PLATFORM_NUM} STREQUAL 1) |
| 25 | # Get the absolute path of the platform |
| 26 | get_filename_component(PLATFORM_ABS_PATH ${PLATFORM_PATHS} DIRECTORY) |
| 27 | set(TFM_PLATFORM ${PLATFORM_ABS_PATH} CACHE STRING "Target platform set as an absolute path." FORCE) |
| 28 | elseif (${_PLATFORM_NUM} STREQUAL 0) |
| 29 | Message(FATAL_ERROR "Platform ${TFM_PLATFORM} is not found in TF-M") |
| 30 | elseif (${_PLATFORM_NUM} GREATER 1) |
| 31 | Message(FATAL_ERROR "Two or more platforms ${TFM_PLATFORM} are found in TF-M") |
| 32 | endif() |
| 33 | endif() |
| 34 | |
| 35 | # If TFM_PLATFORM is an absolute path which maybe inputed by developer or |
| 36 | # transformed from platform name by the process above, it will be converted to |
| 37 | # relative path here. |
| 38 | if (IS_ABSOLUTE "${TFM_PLATFORM}") |
| 39 | file(RELATIVE_PATH TFM_PLATFORM_RELATIVE_PATH ${TARGET_PATH} ${TFM_PLATFORM}) |
| 40 | set(TFM_PLATFORM "${TFM_PLATFORM_RELATIVE_PATH}" CACHE STRING "Target platform set as an relative path." FORCE) |
| 41 | endif() |
| 42 | |
Kevin Peng | a2b6802 | 2023-01-13 13:54:05 +0800 | [diff] [blame] | 43 | set(TARGET_PLATFORM_PATH ${TARGET_PATH}/${TFM_PLATFORM}) |
| 44 | |
| 45 | if (NOT EXISTS ${TARGET_PLATFORM_PATH}/CMakeLists.txt) |
Jianliang Shen | 1c4f1c2 | 2022-03-07 15:56:06 +0800 | [diff] [blame] | 46 | Message(FATAL_ERROR "Unsupported TFM_PLATFORM ${TFM_PLATFORM}") |
Jianliang Shen | 1c4f1c2 | 2022-03-07 15:56:06 +0800 | [diff] [blame] | 47 | endif() |