blob: 43b9d886f13678fe76b19d625e097dd9022e6bef [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#
49# Internal global metadata API.
50#
51
Chris Kay2e4ea1d2021-07-21 12:29:13 +010052macro(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}")
65endmacro()
66
Chris Kayfdee5cb2021-08-19 14:38:45 +010067tfa_json_getter(tfa_metadata
68 JSON "${global-metadata}")
69
Chris Kay2e4ea1d2021-07-21 12:29:13 +010070tfa_json_getter(tfa_metadata_platforms
71 JSON "${global-metadata}" PARENT tfa_metadata
72 PATH "platforms")
73
74tfa_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 Kayfdee5cb2021-08-19 14:38:45 +010080#
81# External global metadata API.
82#
Chris Kay2e4ea1d2021-07-21 12:29:13 +010083
84tfa_json_getter(tfa_platforms
85 JSON "${global-metadata}" PARENT tfa_metadata_platforms
86 DECODE MEMBERS)
87
88tfa_json_getter(tfa_platform_path
89 JSON "${global-metadata}" PARENT tfa_metadata_platforms_platform
90 DECODE STRING)