Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2020, Arm Limited. All rights reserved. |
| 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 | |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 13 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tfm_manifest_list.yaml |
| 14 | ${CMAKE_CURRENT_BINARY_DIR}/tfm_manifest_list.yaml) |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 15 | |
| 16 | set(MANIFEST_LISTS ${CMAKE_CURRENT_BINARY_DIR}/tfm_manifest_list.yaml) |
| 17 | set(MANIFEST_LISTS ${MANIFEST_LISTS} ${TFM_EXTRA_MANIFEST_LIST_PATH}) |
| 18 | |
| 19 | if ("${TEST_PSA_API}" STREQUAL "IPC") |
Raef Coles | 558487a | 2020-10-29 13:09:44 +0000 | [diff] [blame] | 20 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tfm_psa_ff_test_manifest_list.yaml |
| 21 | ${CMAKE_CURRENT_BINARY_DIR}/tfm_psa_ff_test_manifest_list.yaml) |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 22 | |
| 23 | set(MANIFEST_LISTS ${MANIFEST_LISTS} ${CMAKE_CURRENT_BINARY_DIR}/tfm_psa_ff_test_manifest_list.yaml) |
| 24 | endif() |
| 25 | |
| 26 | ############################### File list declaration ########################## |
| 27 | |
| 28 | set(GENERATED_FILE_LISTS ${CMAKE_CURRENT_SOURCE_DIR}/tfm_generated_file_list.yaml) |
| 29 | set(GENERATED_FILE_LISTS ${GENERATED_FILE_LISTS} ${TFM_EXTRA_GENERATED_FILE_LIST_PATH}) |
| 30 | |
| 31 | ############################### Dependency generation ########################## |
| 32 | |
| 33 | function(parse_field_from_yaml files field output_variable) |
| 34 | set(${output_variable} "" PARENT_SCOPE) |
| 35 | foreach(yaml_file ${files}) |
| 36 | # Load the lines that refer to the key we selected |
| 37 | file(STRINGS ${yaml_file} temp_variable REGEX " *\"${field}\":") |
| 38 | # Take only the value of the key |
| 39 | list(TRANSFORM temp_variable REPLACE " *\"${field}\": *" ";") |
| 40 | # Remove all commas |
| 41 | list(TRANSFORM temp_variable REPLACE "," "") |
| 42 | # Remove all quote marks |
| 43 | list(TRANSFORM temp_variable REPLACE "\"" "") |
| 44 | set(${output_variable} ${${output_variable}} ${temp_variable} PARENT_SCOPE) |
| 45 | endforeach() |
| 46 | endfunction() |
| 47 | |
| 48 | parse_field_from_yaml("${GENERATED_FILE_LISTS}" template TEMPLATE_FILES) |
| 49 | # Replace relative paths with absolute paths |
Ken Liu | a2ac1f9 | 2020-10-12 10:58:21 +0800 | [diff] [blame] | 50 | list(TRANSFORM TEMPLATE_FILES REPLACE "^([^/\\][^:].*)" "${CMAKE_SOURCE_DIR}/\\1") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 51 | |
| 52 | parse_field_from_yaml("${GENERATED_FILE_LISTS}" output OUTPUT_FILES) |
| 53 | # Replace relative paths with absolute paths |
Ken Liu | a2ac1f9 | 2020-10-12 10:58:21 +0800 | [diff] [blame] | 54 | list(TRANSFORM OUTPUT_FILES REPLACE "^([^/\\][^:].*)" "${CMAKE_BINARY_DIR}/generated/\\1") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 55 | |
| 56 | parse_field_from_yaml("${MANIFEST_LISTS}" manifest MANIFEST_FILES) |
| 57 | # Replace relative paths with absolute paths |
Ken Liu | a2ac1f9 | 2020-10-12 10:58:21 +0800 | [diff] [blame] | 58 | list(TRANSFORM MANIFEST_FILES REPLACE "^([^/\\][^:].*)" "${CMAKE_SOURCE_DIR}/\\1") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 59 | |
| 60 | ############################### Command declaration ############################ |
| 61 | |
| 62 | # Workaround for heap support |
| 63 | if ("${TEST_PSA_API}" STREQUAL "IPC") |
| 64 | execute_process( |
| 65 | WORKING_DIRECTORY ${PSA_ARCH_TESTS_PATH}/api-tests |
| 66 | COMMAND ${Python3_EXECUTABLE} tools/scripts/manifest_update.py |
| 67 | ) |
| 68 | endif() |
| 69 | |
Raef Coles | e43c020 | 2020-09-28 14:11:53 +0100 | [diff] [blame] | 70 | add_custom_target(tfm_generated_files |
| 71 | SOURCES ${OUTPUT_FILES} |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 72 | ) |
| 73 | |
| 74 | add_custom_command(OUTPUT ${OUTPUT_FILES} |
| 75 | COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tfm_parse_manifest_list.py |
| 76 | -m ${MANIFEST_LISTS} |
| 77 | -f ${GENERATED_FILE_LISTS} |
| 78 | -o ${CMAKE_BINARY_DIR}/generated |
| 79 | DEPENDS ${TEMPLATE_FILES} ${MANIFEST_FILES} |
| 80 | DEPENDS ${MANIFEST_LISTS} |
| 81 | ) |
| 82 | |
| 83 | # The files need to be generated before cmake will allow them to be used as |
| 84 | # 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] | 85 | # is to run the script at cmake-time. |
| 86 | execute_process( |
| 87 | COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tfm_parse_manifest_list.py |
| 88 | -m ${MANIFEST_LISTS} |
| 89 | -f ${GENERATED_FILE_LISTS} |
| 90 | -o ${CMAKE_BINARY_DIR}/generated |
| 91 | RESULT_VARIABLE RET |
| 92 | ) |
| 93 | |
| 94 | if(NOT RET EQUAL 0) |
| 95 | message(FATAL_ERROR "File generation failed") |
Raef Coles | f42f088 | 2020-07-10 10:01:58 +0100 | [diff] [blame] | 96 | endif() |