Migrate Mbed TLS to use LazyFetch

In Mbed TLS 3.2 the necessary functionality was implemented to support
adding Mbed TLS as a CMake package. This makes it possible to use the
FetchContent feature of CMake (and in turn the LazyFetch module of TS)
to download and build Mbed TLS. All of the other external CMake projects
in TS already use the LazyFetch module, which reduces code duplication
by introducing functions that encapsulate the standard "fetch, patch,
configure, build" steps that are necessary for building CMake projects.

This commit replaces the existing Mbed TLS build procedure to use
LazyFetch instead. It also moves the config options of Mbed TLS from
command line arguments in the MbedTLS.cmake file into a dedicated config
file (or in CMake terminology, an "initial CMake cache" file).

Signed-off-by: Balint Dobszay <balint.dobszay@arm.com>
Change-Id: I0aa32f0f847abc3045db4031fefd2cd4e4b684e7
diff --git a/external/MbedTLS/mbedtls-init-cache.cmake.in b/external/MbedTLS/mbedtls-init-cache.cmake.in
new file mode 100644
index 0000000..62d33ef
--- /dev/null
+++ b/external/MbedTLS/mbedtls-init-cache.cmake.in
@@ -0,0 +1,22 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+set(CMAKE_INSTALL_PREFIX @BUILD_INSTALL_DIR@ CACHE STRING "")
+set(CMAKE_TOOLCHAIN_FILE @TS_EXTERNAL_LIB_TOOLCHAIN_FILE@ CACHE STRING "")
+
+set(ENABLE_PROGRAMS Off CACHE BOOL "")
+set(ENABLE_TESTING Off CACHE BOOL "")
+set(UNSAFE_BUILD On CACHE BOOL "")
+set(EXTERNAL_DEFINITIONS -DMBEDTLS_USER_CONFIG_FILE="@MBEDTLS_USER_CONFIG_FILE@" CACHE STRING "")
+set(EXTERNAL_INCLUDE_PATHS @MBEDTLS_EXTRA_INCLUDES@ CACHE STRING "")
+
+string(TOUPPER @CMAKE_CROSSCOMPILING@ CMAKE_CROSSCOMPILING) # CMake expects TRUE
+if (CMAKE_CROSSCOMPILING)
+	set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE STRING "")
+endif()
+
+@_cmake_fragment@