Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [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. |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [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) |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 9 | find_package(Python3) |
| 10 | |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 11 | ############################### Manifest declaration ########################### |
| 12 | |
| 13 | list(APPEND TEMP_MANIFEST_LISTS ${TFM_MANIFEST_LIST}) |
David Hu | b269420 | 2021-07-15 14:58:39 +0800 | [diff] [blame] | 14 | |
David Hu | 12f2587 | 2021-08-23 14:55:46 +0800 | [diff] [blame] | 15 | if (TFM_NS_REG_TEST OR TFM_S_REG_TEST) |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 16 | list(APPEND TEMP_MANIFEST_LISTS ${TFM_TEST_PATH}/secure_fw/tfm_test_manifest_list.yaml) |
Kevin Peng | 65064c5 | 2021-10-27 17:12:17 +0800 | [diff] [blame] | 17 | endif() |
| 18 | |
| 19 | if ("${TEST_PSA_API}" STREQUAL "IPC") |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 20 | list(APPEND TEMP_MANIFEST_LISTS ${CMAKE_CURRENT_SOURCE_DIR}/tfm_psa_ff_test_manifest_list.yaml) |
David Hu | b269420 | 2021-07-15 14:58:39 +0800 | [diff] [blame] | 21 | endif() |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 22 | |
David Hu | f5f1209 | 2021-07-12 16:11:47 +0800 | [diff] [blame] | 23 | if (TFM_EXTRA_MANIFEST_LIST_FILES) |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 24 | list(APPEND TEMP_MANIFEST_LISTS ${TFM_EXTRA_MANIFEST_LIST_FILES}) |
David Hu | f5f1209 | 2021-07-12 16:11:47 +0800 | [diff] [blame] | 25 | endif() |
| 26 | |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 27 | # Build up the manifest list arrays: |
| 28 | # - CONFIGURED_MANIFEST_LISTS: |
| 29 | # Array of Manifest lists under build directory which are the output of configure_file(). |
| 30 | # - MANIFEST_LIST_PATHS: |
| 31 | # Array of paths of the input manifest lists of configure_file(). |
| 32 | # They are NOT the paths of CONFIGURED_MANIFEST_LISTS. |
| 33 | # They can be used to build up manifest file paths if manifest file paths are |
| 34 | # relative ones in the manifest lists. |
| 35 | # - COMBINED_LIST: |
| 36 | # A combined list of the above two, with the following format: |
| 37 | # [configured_list_a, path_of_list_a, configured_list_b, path_of_list_b ... ] |
| 38 | set(POSTFIX 1) |
| 39 | |
| 40 | foreach(MANIFEST_LIST IN LISTS TEMP_MANIFEST_LISTS) |
| 41 | if (NOT EXISTS ${MANIFEST_LIST}) |
| 42 | message(FATAL_ERROR "Manifest list ${MANIFEST_LIST} doesn't exist") |
| 43 | endif() |
| 44 | |
| 45 | get_filename_component(MANIFEST_LIST_NAME ${MANIFEST_LIST} NAME_WLE) |
| 46 | set(CONFIGURED_LIST |
| 47 | ${CMAKE_CURRENT_BINARY_DIR}/${MANIFEST_LIST_NAME}_${POSTFIX}.yaml) |
| 48 | |
| 49 | configure_file(${MANIFEST_LIST} ${CONFIGURED_LIST}) |
| 50 | list(APPEND CONFIGURED_MANIFEST_LISTS ${CONFIGURED_LIST}) |
| 51 | list(APPEND COMBINED_LIST ${CONFIGURED_LIST}) |
| 52 | |
| 53 | get_filename_component(MANIFEST_LIST_PATH ${MANIFEST_LIST} DIRECTORY) |
| 54 | list(APPEND MANIFEST_LIST_PATHS ${MANIFEST_LIST_PATH}) |
| 55 | list(APPEND COMBINED_LIST ${MANIFEST_LIST_PATH}) |
| 56 | |
| 57 | math(EXPR POSTFIX "${POSTFIX} + 1") |
| 58 | endforeach() |
| 59 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 60 | ############################### File list declaration ########################## |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 61 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 62 | set(GENERATED_FILE_LISTS ${CMAKE_CURRENT_SOURCE_DIR}/tfm_generated_file_list.yaml) |
| 63 | set(GENERATED_FILE_LISTS ${GENERATED_FILE_LISTS} ${TFM_EXTRA_GENERATED_FILE_LIST_PATH}) |
| 64 | |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 65 | ############################### Dependency generation ########################## |
| 66 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 67 | function(parse_field_from_yaml files field output_variable) |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 68 | set(local_variable "") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 69 | foreach(yaml_file ${files}) |
| 70 | # Load the lines that refer to the key we selected |
| 71 | file(STRINGS ${yaml_file} temp_variable REGEX " *\"${field}\":") |
| 72 | # Take only the value of the key |
| 73 | list(TRANSFORM temp_variable REPLACE " *\"${field}\": *" ";") |
| 74 | # Remove all commas |
| 75 | list(TRANSFORM temp_variable REPLACE "," "") |
| 76 | # Remove all quote marks |
| 77 | list(TRANSFORM temp_variable REPLACE "\"" "") |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 78 | list(APPEND local_variable ${temp_variable}) |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 79 | endforeach() |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 80 | set(${output_variable} ${local_variable} PARENT_SCOPE) |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 81 | endfunction() |
| 82 | |
| 83 | parse_field_from_yaml("${GENERATED_FILE_LISTS}" template TEMPLATE_FILES) |
| 84 | # Replace relative paths with absolute paths |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 85 | # Paths used in GENERATED_FILE_LISTS are all relative to TF-M root (${CMAKE_SOURCE_DIR}) |
Ken Liu | a2ac1f9 | 2020-10-12 10:58:21 +0800 | [diff] [blame] | 86 | list(TRANSFORM TEMPLATE_FILES REPLACE "^([^/\\][^:].*)" "${CMAKE_SOURCE_DIR}/\\1") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 87 | |
| 88 | parse_field_from_yaml("${GENERATED_FILE_LISTS}" output OUTPUT_FILES) |
| 89 | # Replace relative paths with absolute paths |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 90 | # Paths used in GENERATED_FILE_LISTS are all relative to TF-M root (${CMAKE_SOURCE_DIR}) |
Ken Liu | a2ac1f9 | 2020-10-12 10:58:21 +0800 | [diff] [blame] | 91 | list(TRANSFORM OUTPUT_FILES REPLACE "^([^/\\][^:].*)" "${CMAKE_BINARY_DIR}/generated/\\1") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 92 | |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 93 | # Each manifest list may have different original path |
| 94 | # Parse them one by one |
| 95 | set(INDEX 0) |
| 96 | foreach(CONFIGURED_LIST ${CONFIGURED_MANIFEST_LISTS}) |
| 97 | list(GET MANIFEST_LIST_PATHS ${INDEX} PATH_OF_LIST) |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 98 | |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 99 | parse_field_from_yaml(${CONFIGURED_LIST} manifest MANIFESTS) |
| 100 | foreach(MANIFEST ${MANIFESTS}) |
| 101 | # The path of each manifest must be absolute path or relative path to |
| 102 | # the path of manifest list that holds it |
| 103 | if (NOT IS_ABSOLUTE ${MANIFEST}) |
| 104 | set(MANIFEST "${PATH_OF_LIST}/${MANIFEST}") |
| 105 | endif() |
| 106 | list(APPEND MANIFEST_FILES ${MANIFEST}) |
| 107 | endforeach() |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 108 | |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 109 | math(EXPR INDEX "${INDEX} + 1") |
Kevin Peng | 1b8177b | 2021-12-07 15:06:25 +0800 | [diff] [blame] | 110 | endforeach() |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 111 | |
| 112 | ############################### Command declaration ############################ |
| 113 | |
| 114 | # Workaround for heap support |
| 115 | if ("${TEST_PSA_API}" STREQUAL "IPC") |
| 116 | execute_process( |
| 117 | WORKING_DIRECTORY ${PSA_ARCH_TESTS_PATH}/api-tests |
| 118 | COMMAND ${Python3_EXECUTABLE} tools/scripts/manifest_update.py |
| 119 | ) |
| 120 | endif() |
| 121 | |
Raef Coles | e43c020 | 2020-09-28 14:11:53 +0100 | [diff] [blame] | 122 | add_custom_target(tfm_generated_files |
| 123 | SOURCES ${OUTPUT_FILES} |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 124 | ) |
| 125 | |
Kevin Peng | c32279d | 2022-02-10 11:11:55 +0800 | [diff] [blame] | 126 | if (CONFIG_TFM_PARSE_MANIFEST_QUIET) |
Jimmy Brisson | 89d4f8d | 2021-06-23 10:17:36 -0500 | [diff] [blame] | 127 | set(PARSE_MANIFEST_QUIET_FLAG "-q") |
| 128 | else() |
| 129 | set(PARSE_MANIFEST_QUIET_FLAG "") |
| 130 | endif() |
| 131 | |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 132 | set(MANIFEST_COMMAND |
| 133 | ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tfm_parse_manifest_list.py |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 134 | -m ${COMBINED_LIST} |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 135 | -f ${GENERATED_FILE_LISTS} |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 136 | -l ${TFM_ISOLATION_LEVEL} |
| 137 | -b ${CONFIG_TFM_SPM_BACKEND} |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 138 | -o ${CMAKE_BINARY_DIR}/generated |
| 139 | ${PARSE_MANIFEST_QUIET_FLAG}) |
| 140 | |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 141 | add_custom_command(OUTPUT ${OUTPUT_FILES} |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 142 | COMMAND ${MANIFEST_COMMAND} |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 143 | DEPENDS ${TEMPLATE_FILES} ${MANIFEST_FILES} |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 144 | DEPENDS ${TEMP_MANIFEST_LISTS} ${CONFIGURED_MANIFEST_LISTS} ${GENERATED_FILE_LISTS} |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 145 | ) |
| 146 | |
| 147 | # The files need to be generated before cmake will allow them to be used as |
| 148 | # sources. Due to issue with custom_command scoping the easiest way to do this |
Raef Coles | e43c020 | 2020-09-28 14:11:53 +0100 | [diff] [blame] | 149 | # is to run the script at cmake-time. |
| 150 | execute_process( |
Kevin Peng | 3dd051c | 2022-07-13 11:02:03 +0800 | [diff] [blame] | 151 | COMMAND ${MANIFEST_COMMAND} |
Raef Coles | e43c020 | 2020-09-28 14:11:53 +0100 | [diff] [blame] | 152 | RESULT_VARIABLE RET |
| 153 | ) |
| 154 | |
Sherry Zhang | f58f2bd | 2022-01-10 17:21:11 +0800 | [diff] [blame] | 155 | if(RET EQUAL 0) |
| 156 | include(${CMAKE_BINARY_DIR}/generated/tools/config_impl.cmake) |
| 157 | else() |
David Hu | d394817 | 2022-08-01 15:12:24 +0200 | [diff] [blame] | 158 | message(FATAL_ERROR "File generation failed") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 159 | endif() |