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 | # |
Chris Kay | f3e8afa | 2021-07-22 15:04:39 +0100 | [diff] [blame^] | 49 | # Allow the user to provide their own platform list metadata. This allows |
| 50 | # developers to use out-of-tree platforms (platforms that live outside of this |
| 51 | # repository). The platforms list given by this file is superimposed onto the |
| 52 | # global metadata file. |
| 53 | # |
| 54 | |
| 55 | arm_config_option( |
| 56 | NAME TFA_METADATA_PLATFORMS_PATH ADVANCED |
| 57 | HELP "Path to an alternative platforms metadata file." |
| 58 | TYPE FILEPATH) |
| 59 | |
| 60 | if(TFA_METADATA_PLATFORMS_PATH) |
| 61 | cmake_path(GET TFA_METADATA_PLATFORMS_PATH |
| 62 | PARENT_PATH TFA_METADATA_PLATFORMS_DIR) |
| 63 | |
| 64 | arm_assert( |
| 65 | CONDITION EXISTS "${TFA_METADATA_PLATFORMS_PATH}" |
| 66 | MESSAGE "The path to the platforms metadata file " |
| 67 | "(`TFA_METADATA_PLATFORMS_PATH`) does not exist:\n" |
| 68 | |
| 69 | "${TFA_METADATA_PLATFORMS_PATH}") |
| 70 | |
| 71 | file(READ "${TFA_METADATA_PLATFORMS_PATH}" platforms-metadata) |
| 72 | arm_expand(OUTPUT platforms-metadata STRING "${platforms-metadata}") |
| 73 | |
| 74 | tfa_json_get(platforms JSON "${platforms-metadata}" DECODE MEMBERS) |
| 75 | |
| 76 | foreach(platform IN LISTS platforms) |
| 77 | # |
| 78 | # Fix up relative paths in the platforms metadata JSON file so that any |
| 79 | # relative paths are relative to the metadata file, rather than to the |
| 80 | # current source directory. |
| 81 | # |
| 82 | |
| 83 | tfa_json_get(platform-path JSON "${platforms-metadata}" |
| 84 | PATH "${platform}" DECODE STRING) |
| 85 | |
| 86 | cmake_path(ABSOLUTE_PATH platform-path |
| 87 | BASE_DIRECTORY "${TFA_METADATA_PLATFORMS_DIR}") |
| 88 | |
| 89 | tfa_json_encode_string(platform-path "${platform-path}") |
| 90 | string(JSON platforms-metadata SET "${platforms-metadata}" |
| 91 | "${platform}" "${platform-path}") |
| 92 | endforeach() |
| 93 | |
| 94 | tfa_json_merge(global-metadata |
| 95 | BOTTOM "${global-metadata}" |
| 96 | BOTTOM_PATH "platforms" |
| 97 | TOP "${platforms-metadata}") |
| 98 | endif() |
| 99 | |
| 100 | # |
Chris Kay | fdee5cb | 2021-08-19 14:38:45 +0100 | [diff] [blame] | 101 | # Internal global metadata API. |
| 102 | # |
| 103 | |
Chris Kay | 2e4ea1d | 2021-07-21 12:29:13 +0100 | [diff] [blame] | 104 | macro(tfa_metadata_platforms_platform_postprocess) |
| 105 | # |
| 106 | # Ensure relative paths are made relative to the current source directory, |
| 107 | # which should be the top-level project directory. The initial JSON string |
| 108 | # value is passed via the `value` variable. |
| 109 | # |
| 110 | |
| 111 | tfa_json_decode_string(platform-path "${value}") |
| 112 | |
| 113 | cmake_path(ABSOLUTE_PATH platform-path |
| 114 | BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") |
| 115 | |
| 116 | tfa_json_encode_string(value "${platform-path}") |
| 117 | endmacro() |
| 118 | |
Chris Kay | fdee5cb | 2021-08-19 14:38:45 +0100 | [diff] [blame] | 119 | tfa_json_getter(tfa_metadata |
| 120 | JSON "${global-metadata}") |
| 121 | |
Chris Kay | 2e4ea1d | 2021-07-21 12:29:13 +0100 | [diff] [blame] | 122 | tfa_json_getter(tfa_metadata_platforms |
| 123 | JSON "${global-metadata}" PARENT tfa_metadata |
| 124 | PATH "platforms") |
| 125 | |
| 126 | tfa_json_getter(tfa_metadata_platforms_platform |
| 127 | JSON "${global-metadata}" PARENT tfa_metadata_platforms |
| 128 | PATH "@PLATFORM@" ARGUMENTS PLATFORM |
| 129 | POSTPROCESS tfa_metadata_platforms_platform_postprocess |
| 130 | ERROR_MESSAGE "No such platform: @PLATFORM@.") |
| 131 | |
Chris Kay | fdee5cb | 2021-08-19 14:38:45 +0100 | [diff] [blame] | 132 | # |
| 133 | # External global metadata API. |
| 134 | # |
Chris Kay | 2e4ea1d | 2021-07-21 12:29:13 +0100 | [diff] [blame] | 135 | |
| 136 | tfa_json_getter(tfa_platforms |
| 137 | JSON "${global-metadata}" PARENT tfa_metadata_platforms |
| 138 | DECODE MEMBERS) |
| 139 | |
| 140 | tfa_json_getter(tfa_platform_path |
| 141 | JSON "${global-metadata}" PARENT tfa_metadata_platforms_platform |
| 142 | DECODE STRING) |