Chris Kay | fdee5cb | 2021-08-19 14:38:45 +0100 | [diff] [blame] | 1 | #[=======================================================================[.rst: |
| 2 | TFAMetadata |
| 3 | ----------- |
| 4 | |
| 5 | .. default-domain:: cmake |
| 6 | |
| 7 | Metadata management utilities for TF-A. |
| 8 | |
| 9 | TF-A uses a set of JSON-formatted metadata files to manage some of its |
| 10 | configuration data. This module provides a stable CMake interface for retrieving |
| 11 | values from these metadata files. |
Chris Kay | 2e4ea1d | 2021-07-21 12:29:13 +0100 | [diff] [blame^] | 12 | |
| 13 | .. command:: tfa_platforms |
| 14 | |
| 15 | .. code-block:: cmake |
| 16 | |
| 17 | tfa_platforms(<out-var>) |
| 18 | |
| 19 | Return the list of supported platforms in ``<out-var>``. |
| 20 | |
| 21 | .. command:: tfa_platform_path |
| 22 | |
| 23 | .. code-block:: cmake |
| 24 | |
| 25 | tfa_platform_path(<out-var> PLATFORM <platform>) |
| 26 | |
| 27 | Return the path to the platform ``<platform>`` in ``<out-var>``. |
Chris Kay | fdee5cb | 2021-08-19 14:38:45 +0100 | [diff] [blame] | 28 | #]=======================================================================] |
| 29 | |
| 30 | include_guard() |
| 31 | |
| 32 | include(ArmAssert) |
| 33 | include(ArmExpand) |
| 34 | |
| 35 | include(TFAJsonUtilities) |
| 36 | |
| 37 | # |
| 38 | # Read the global metadata file. This is a JSON-formatted file that contains |
| 39 | # information about the contents of the repository that are relevant to the |
| 40 | # build system. |
| 41 | # |
| 42 | |
| 43 | arm_assert(CONDITION EXISTS "${CMAKE_SOURCE_DIR}/metadata.json") |
| 44 | |
| 45 | file(READ "${CMAKE_SOURCE_DIR}/metadata.json" global-metadata) |
| 46 | arm_expand(OUTPUT global-metadata STRING "${global-metadata}") |
| 47 | |
| 48 | # |
| 49 | # Internal global metadata API. |
| 50 | # |
| 51 | |
Chris Kay | 2e4ea1d | 2021-07-21 12:29:13 +0100 | [diff] [blame^] | 52 | macro(tfa_metadata_platforms_platform_postprocess) |
| 53 | # |
| 54 | # Ensure relative paths are made relative to the current source directory, |
| 55 | # which should be the top-level project directory. The initial JSON string |
| 56 | # value is passed via the `value` variable. |
| 57 | # |
| 58 | |
| 59 | tfa_json_decode_string(platform-path "${value}") |
| 60 | |
| 61 | cmake_path(ABSOLUTE_PATH platform-path |
| 62 | BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") |
| 63 | |
| 64 | tfa_json_encode_string(value "${platform-path}") |
| 65 | endmacro() |
| 66 | |
Chris Kay | fdee5cb | 2021-08-19 14:38:45 +0100 | [diff] [blame] | 67 | tfa_json_getter(tfa_metadata |
| 68 | JSON "${global-metadata}") |
| 69 | |
Chris Kay | 2e4ea1d | 2021-07-21 12:29:13 +0100 | [diff] [blame^] | 70 | tfa_json_getter(tfa_metadata_platforms |
| 71 | JSON "${global-metadata}" PARENT tfa_metadata |
| 72 | PATH "platforms") |
| 73 | |
| 74 | tfa_json_getter(tfa_metadata_platforms_platform |
| 75 | JSON "${global-metadata}" PARENT tfa_metadata_platforms |
| 76 | PATH "@PLATFORM@" ARGUMENTS PLATFORM |
| 77 | POSTPROCESS tfa_metadata_platforms_platform_postprocess |
| 78 | ERROR_MESSAGE "No such platform: @PLATFORM@.") |
| 79 | |
Chris Kay | fdee5cb | 2021-08-19 14:38:45 +0100 | [diff] [blame] | 80 | # |
| 81 | # External global metadata API. |
| 82 | # |
Chris Kay | 2e4ea1d | 2021-07-21 12:29:13 +0100 | [diff] [blame^] | 83 | |
| 84 | tfa_json_getter(tfa_platforms |
| 85 | JSON "${global-metadata}" PARENT tfa_metadata_platforms |
| 86 | DECODE MEMBERS) |
| 87 | |
| 88 | tfa_json_getter(tfa_platform_path |
| 89 | JSON "${global-metadata}" PARENT tfa_metadata_platforms_platform |
| 90 | DECODE STRING) |