blob: 9019eaa5f121be66063a8fbdc9e794378ee5fc21 [file] [log] [blame]
Chris Kayfdee5cb2021-08-19 14:38:45 +01001#[=======================================================================[.rst:
2TFAMetadata
3-----------
4
5.. default-domain:: cmake
6
7Metadata management utilities for TF-A.
8
9TF-A uses a set of JSON-formatted metadata files to manage some of its
10configuration data. This module provides a stable CMake interface for retrieving
11values from these metadata files.
Chris Kay2e4ea1d2021-07-21 12:29:13 +010012
13.. command:: tfa_platforms
14
15.. code-block:: cmake
16
17 tfa_platforms(<out-var>)
18
19Return 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
27Return the path to the platform ``<platform>`` in ``<out-var>``.
Chris Kayfdee5cb2021-08-19 14:38:45 +010028#]=======================================================================]
29
30include_guard()
31
32include(ArmAssert)
33include(ArmExpand)
34
35include(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
43arm_assert(CONDITION EXISTS "${CMAKE_SOURCE_DIR}/metadata.json")
44
45file(READ "${CMAKE_SOURCE_DIR}/metadata.json" global-metadata)
46arm_expand(OUTPUT global-metadata STRING "${global-metadata}")
47
48#
Chris Kayf3e8afa2021-07-22 15:04:39 +010049# 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
55arm_config_option(
56 NAME TFA_METADATA_PLATFORMS_PATH ADVANCED
57 HELP "Path to an alternative platforms metadata file."
58 TYPE FILEPATH)
59
60if(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}")
98endif()
99
100#
Chris Kayfdee5cb2021-08-19 14:38:45 +0100101# Internal global metadata API.
102#
103
Chris Kay2e4ea1d2021-07-21 12:29:13 +0100104macro(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}")
117endmacro()
118
Chris Kayfdee5cb2021-08-19 14:38:45 +0100119tfa_json_getter(tfa_metadata
120 JSON "${global-metadata}")
121
Chris Kay2e4ea1d2021-07-21 12:29:13 +0100122tfa_json_getter(tfa_metadata_platforms
123 JSON "${global-metadata}" PARENT tfa_metadata
124 PATH "platforms")
125
126tfa_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 Kayfdee5cb2021-08-19 14:38:45 +0100132#
133# External global metadata API.
134#
Chris Kay2e4ea1d2021-07-21 12:29:13 +0100135
136tfa_json_getter(tfa_platforms
137 JSON "${global-metadata}" PARENT tfa_metadata_platforms
138 DECODE MEMBERS)
139
140tfa_json_getter(tfa_platform_path
141 JSON "${global-metadata}" PARENT tfa_metadata_platforms_platform
142 DECODE STRING)