Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Kevin Peng | 3880066 | 2021-07-14 10:28:23 +0800 | [diff] [blame] | 2 | # Copyright (c) 2020-2021, 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 | |
| 11 | ############################### Manifest declaration ########################### |
| 12 | |
Kevin Peng | 3880066 | 2021-07-14 10:28:23 +0800 | [diff] [blame] | 13 | get_filename_component(list_name ${TFM_MANIFEST_LIST} NAME) |
| 14 | configure_file(${TFM_MANIFEST_LIST} ${CMAKE_CURRENT_BINARY_DIR}/${list_name}) |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 15 | |
Kevin Peng | 3880066 | 2021-07-14 10:28:23 +0800 | [diff] [blame] | 16 | set(MANIFEST_LISTS ${CMAKE_CURRENT_BINARY_DIR}/${list_name}) |
David Hu | b269420 | 2021-07-15 14:58:39 +0800 | [diff] [blame] | 17 | |
| 18 | if (TFM_EXTRA_MANIFEST_LIST_FILES) |
| 19 | # Build up out-of-tree manifest list array |
| 20 | # Each manifest list occupies two elements in out-of-tree manifest list array: |
| 21 | # - Manifest list path under build directory after configure_file() |
| 22 | # - The original path of manifest list in source directory. It can be used to |
| 23 | # build up manifest file path if manifest file path is a relative one in |
| 24 | # manifest list. |
| 25 | set(POSTFIX 1) |
| 26 | |
| 27 | foreach(MANIFEST_LIST IN LISTS TFM_EXTRA_MANIFEST_LIST_FILES) |
| 28 | if (NOT EXISTS ${MANIFEST_LIST}) |
| 29 | message(FATAL_ERROR "Extra manifest list ${MANIFEST_LIST} doesn't exist") |
| 30 | endif() |
| 31 | |
| 32 | get_filename_component(MANIFEST_LIST_NAME ${MANIFEST_LIST} NAME_WLE) |
| 33 | set(TEMP_MANIFEST_LIST |
| 34 | ${CMAKE_CURRENT_BINARY_DIR}/${MANIFEST_LIST_NAME}_${POSTFIX}.yaml) |
| 35 | |
| 36 | configure_file(${MANIFEST_LIST} ${TEMP_MANIFEST_LIST}) |
| 37 | list(APPEND OUT_OF_TREE_MANIFEST_LIST ${TEMP_MANIFEST_LIST}) |
| 38 | |
| 39 | get_filename_component(MANIFEST_LIST_PATH ${MANIFEST_LIST} DIRECTORY) |
| 40 | # Append the manifest list original path. |
| 41 | # Manifest file path can be a relative one to manifest list. |
| 42 | list(APPEND OUT_OF_TREE_MANIFEST_LIST ${MANIFEST_LIST_PATH}) |
| 43 | |
| 44 | math(EXPR POSTFIX "${POSTFIX} + 1") |
| 45 | endforeach() |
| 46 | endif() |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 47 | |
| 48 | if ("${TEST_PSA_API}" STREQUAL "IPC") |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 49 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tfm_psa_ff_test_manifest_list.yaml |
| 50 | ${CMAKE_CURRENT_BINARY_DIR}/tfm_psa_ff_test_manifest_list.yaml) |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 51 | |
| 52 | set(MANIFEST_LISTS ${MANIFEST_LISTS} ${CMAKE_CURRENT_BINARY_DIR}/tfm_psa_ff_test_manifest_list.yaml) |
| 53 | endif() |
| 54 | |
| 55 | ############################### File list declaration ########################## |
| 56 | |
| 57 | set(GENERATED_FILE_LISTS ${CMAKE_CURRENT_SOURCE_DIR}/tfm_generated_file_list.yaml) |
| 58 | set(GENERATED_FILE_LISTS ${GENERATED_FILE_LISTS} ${TFM_EXTRA_GENERATED_FILE_LIST_PATH}) |
| 59 | |
| 60 | ############################### Dependency generation ########################## |
| 61 | |
| 62 | function(parse_field_from_yaml files field output_variable) |
| 63 | set(${output_variable} "" PARENT_SCOPE) |
| 64 | foreach(yaml_file ${files}) |
| 65 | # Load the lines that refer to the key we selected |
| 66 | file(STRINGS ${yaml_file} temp_variable REGEX " *\"${field}\":") |
| 67 | # Take only the value of the key |
| 68 | list(TRANSFORM temp_variable REPLACE " *\"${field}\": *" ";") |
| 69 | # Remove all commas |
| 70 | list(TRANSFORM temp_variable REPLACE "," "") |
| 71 | # Remove all quote marks |
| 72 | list(TRANSFORM temp_variable REPLACE "\"" "") |
| 73 | set(${output_variable} ${${output_variable}} ${temp_variable} PARENT_SCOPE) |
| 74 | endforeach() |
| 75 | endfunction() |
| 76 | |
| 77 | parse_field_from_yaml("${GENERATED_FILE_LISTS}" template TEMPLATE_FILES) |
| 78 | # Replace relative paths with absolute paths |
Ken Liu | a2ac1f9 | 2020-10-12 10:58:21 +0800 | [diff] [blame] | 79 | list(TRANSFORM TEMPLATE_FILES REPLACE "^([^/\\][^:].*)" "${CMAKE_SOURCE_DIR}/\\1") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 80 | |
| 81 | parse_field_from_yaml("${GENERATED_FILE_LISTS}" output OUTPUT_FILES) |
| 82 | # Replace relative paths with absolute paths |
Ken Liu | a2ac1f9 | 2020-10-12 10:58:21 +0800 | [diff] [blame] | 83 | list(TRANSFORM OUTPUT_FILES REPLACE "^([^/\\][^:].*)" "${CMAKE_BINARY_DIR}/generated/\\1") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 84 | |
| 85 | parse_field_from_yaml("${MANIFEST_LISTS}" manifest MANIFEST_FILES) |
| 86 | # Replace relative paths with absolute paths |
Ken Liu | a2ac1f9 | 2020-10-12 10:58:21 +0800 | [diff] [blame] | 87 | list(TRANSFORM MANIFEST_FILES REPLACE "^([^/\\][^:].*)" "${CMAKE_SOURCE_DIR}/\\1") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 88 | |
| 89 | ############################### Command declaration ############################ |
| 90 | |
| 91 | # Workaround for heap support |
| 92 | if ("${TEST_PSA_API}" STREQUAL "IPC") |
| 93 | execute_process( |
| 94 | WORKING_DIRECTORY ${PSA_ARCH_TESTS_PATH}/api-tests |
| 95 | COMMAND ${Python3_EXECUTABLE} tools/scripts/manifest_update.py |
| 96 | ) |
| 97 | endif() |
| 98 | |
Raef Coles | e43c020 | 2020-09-28 14:11:53 +0100 | [diff] [blame] | 99 | add_custom_target(tfm_generated_files |
| 100 | SOURCES ${OUTPUT_FILES} |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 101 | ) |
| 102 | |
| 103 | add_custom_command(OUTPUT ${OUTPUT_FILES} |
| 104 | COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tfm_parse_manifest_list.py |
| 105 | -m ${MANIFEST_LISTS} |
| 106 | -f ${GENERATED_FILE_LISTS} |
| 107 | -o ${CMAKE_BINARY_DIR}/generated |
David Hu | b269420 | 2021-07-15 14:58:39 +0800 | [diff] [blame] | 108 | -e ${OUT_OF_TREE_MANIFEST_LIST} |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 109 | DEPENDS ${TEMPLATE_FILES} ${MANIFEST_FILES} |
| 110 | DEPENDS ${MANIFEST_LISTS} |
| 111 | ) |
| 112 | |
| 113 | # The files need to be generated before cmake will allow them to be used as |
| 114 | # 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] | 115 | # is to run the script at cmake-time. |
| 116 | execute_process( |
| 117 | COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tfm_parse_manifest_list.py |
| 118 | -m ${MANIFEST_LISTS} |
| 119 | -f ${GENERATED_FILE_LISTS} |
| 120 | -o ${CMAKE_BINARY_DIR}/generated |
David Hu | b269420 | 2021-07-15 14:58:39 +0800 | [diff] [blame] | 121 | -e ${OUT_OF_TREE_MANIFEST_LIST} |
Raef Coles | e43c020 | 2020-09-28 14:11:53 +0100 | [diff] [blame] | 122 | RESULT_VARIABLE RET |
| 123 | ) |
| 124 | |
| 125 | if(NOT RET EQUAL 0) |
| 126 | message(FATAL_ERROR "File generation failed") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 127 | endif() |