build(cmake): add metadata management utilities
This change introduces what we will refer to as the "global metadata
file": `metadata.json`. We will use this file going forward to declare
static, project-wide configuration data. This allows us to reduce the
amount of churn going on in the CMake script list files - which are
going to be much less familiar to newcomers - to support new platforms,
cores and features.
To facilitate rapid retrieval of structured (JSON-based) project data,
an additional set of CMake utilities are introduced here to simplify
retrieval and manipulation of the project metadata from the scripts.
Change-Id: Idd8518fb17e7a309f82344e228ddecc6e329792b
Signed-off-by: Chris Kay <chris.kay@arm.com>
diff --git a/cmake/Modules/TFAMetadata.cmake b/cmake/Modules/TFAMetadata.cmake
new file mode 100644
index 0000000..56243cc
--- /dev/null
+++ b/cmake/Modules/TFAMetadata.cmake
@@ -0,0 +1,41 @@
+#[=======================================================================[.rst:
+TFAMetadata
+-----------
+
+.. default-domain:: cmake
+
+Metadata management utilities for TF-A.
+
+TF-A uses a set of JSON-formatted metadata files to manage some of its
+configuration data. This module provides a stable CMake interface for retrieving
+values from these metadata files.
+#]=======================================================================]
+
+include_guard()
+
+include(ArmAssert)
+include(ArmExpand)
+
+include(TFAJsonUtilities)
+
+#
+# Read the global metadata file. This is a JSON-formatted file that contains
+# information about the contents of the repository that are relevant to the
+# build system.
+#
+
+arm_assert(CONDITION EXISTS "${CMAKE_SOURCE_DIR}/metadata.json")
+
+file(READ "${CMAKE_SOURCE_DIR}/metadata.json" global-metadata)
+arm_expand(OUTPUT global-metadata STRING "${global-metadata}")
+
+#
+# Internal global metadata API.
+#
+
+tfa_json_getter(tfa_metadata
+ JSON "${global-metadata}")
+
+#
+# External global metadata API.
+#
diff --git a/docs/cmake/manual/module/internal/TFAMetadata.rst b/docs/cmake/manual/module/internal/TFAMetadata.rst
new file mode 100644
index 0000000..0c0b469
--- /dev/null
+++ b/docs/cmake/manual/module/internal/TFAMetadata.rst
@@ -0,0 +1,5 @@
+.. cmake-module:: ../../../../../cmake/Modules/TFAMetadata.cmake
+
+--------------
+
+*Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.*
diff --git a/metadata.json b/metadata.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/metadata.json
@@ -0,0 +1 @@
+{}
diff --git a/schemas/metadata.schema.json b/schemas/metadata.schema.json
new file mode 100644
index 0000000..0163363
--- /dev/null
+++ b/schemas/metadata.schema.json
@@ -0,0 +1,7 @@
+{
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
+ "type": "object",
+ "required": [],
+ "additionalProperties": false,
+ "properties": {}
+}