blob: 13c528be8d95dcce59f9a45d9ce29d7d8191706e [file] [log] [blame]
Jianliang Shen1c4f1c22022-03-07 15:56:06 +08001#-------------------------------------------------------------------------------
David Hucc144982023-01-16 12:24:27 +08002# Copyright (c) 2022-2023, Arm Limited. All rights reserved.
Jianliang Shen1c4f1c22022-03-07 15:56:06 +08003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
Anton Komlev1ba9ea32023-08-17 11:39:08 +01008set(TARGET_PATH "${CMAKE_CURRENT_LIST_DIR}/../platform/ext/target")
Jianliang Shen1c4f1c22022-03-07 15:56:06 +08009
10if (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 Peng79aabb82023-11-01 10:30:17 +080013 # the "cpuarch.cmake" and find the matching one.
Jianliang Shen1c4f1c22022-03-07 15:56:06 +080014
Kevin Pengf38456c2023-10-31 15:35:50 +080015 # Get the list of directories which have cpuarch.cmake
16 file(GLOB_RECURSE PLATFORM_PATHS ${TARGET_PATH} "cpuarch.cmake")
Jianliang Shen1c4f1c22022-03-07 15:56:06 +080017
18 # Search the list with platform name and store the result in PLATFORM_PATHS
Jianliang Shena94e2522022-07-20 16:37:52 +080019 list(FILTER PLATFORM_PATHS INCLUDE REGEX "/${TFM_PLATFORM}/")
Jianliang Shen1c4f1c22022-03-07 15:56:06 +080020
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()
33endif()
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.
38if (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)
41endif()
42
Kevin Penga2b68022023-01-13 13:54:05 +080043set(TARGET_PLATFORM_PATH ${TARGET_PATH}/${TFM_PLATFORM})
44
45if (NOT EXISTS ${TARGET_PLATFORM_PATH}/CMakeLists.txt)
Jianliang Shen1c4f1c22022-03-07 15:56:06 +080046 Message(FATAL_ERROR "Unsupported TFM_PLATFORM ${TFM_PLATFORM}")
Jianliang Shen1c4f1c22022-03-07 15:56:06 +080047endif()