Build: Convert lib dir to modern cmake

Rewrite cmake files inside the lib directory. Adds subdirectories for
external dependencies that are now fetched automatically by cmake. Add
patches for external repos that require them.

WARNING: This change will not build in isolation, it requires _all_
other cmake changes to successfully build. It is split out only for
clarity of changes.

Change-Id: I545fd9278fbccb56c4216ffd5a390e35787dc41a
Signed-off-by: Raef Coles <raef.coles@arm.com>
diff --git a/lib/ext/mcuboot/CMakeLists.txt b/lib/ext/mcuboot/CMakeLists.txt
new file mode 100644
index 0000000..5fcdfd9
--- /dev/null
+++ b/lib/ext/mcuboot/CMakeLists.txt
@@ -0,0 +1,30 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+include(FetchContent)
+set(FETCHCONTENT_QUIET FALSE)
+
+# Set to not download submodules if that option is available
+if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
+    cmake_policy(SET CMP0097 NEW)
+endif()
+
+if ("${MCUBOOT_PATH}" STREQUAL "DOWNLOAD")
+    FetchContent_Declare(mcuboot
+        GIT_REPOSITORY https://github.com/JuulLabs-OSS/mcuboot.git
+        GIT_TAG v${MCUBOOT_VERSION}
+        GIT_SHALLOW TRUE
+        GIT_PROGRESS TRUE
+        GIT_SUBMODULES ""
+    )
+
+    FetchContent_GetProperties(mcuboot)
+    if(NOT mcuboot_POPULATED)
+        FetchContent_Populate(mcuboot)
+        set(MCUBOOT_PATH ${mcuboot_SOURCE_DIR} CACHE PATH "Path to MCUBOOT (or DOWNLOAD to get automatically" FORCE)
+    endif()
+endif()