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/mbedcrypto/0003-Add-include-mbedtls-to-include-property-of-targets.patch b/lib/ext/mbedcrypto/0003-Add-include-mbedtls-to-include-property-of-targets.patch
new file mode 100644
index 0000000..7564f84
--- /dev/null
+++ b/lib/ext/mbedcrypto/0003-Add-include-mbedtls-to-include-property-of-targets.patch
@@ -0,0 +1,60 @@
+From 37095546fc7eca29d5a790a7d7d0a1314b173dd3 Mon Sep 17 00:00:00 2001
+From: Raef Coles <raef.coles@arm.com>
+Date: Wed, 2 Sep 2020 10:04:05 +0100
+Subject: [PATCH 3/6] Add include/mbedtls to include property of targets
+
+Signed-off-by: Raef Coles <raef.coles@arm.com>
+---
+ CMakeLists.txt         | 3 +--
+ library/CMakeLists.txt | 8 ++++++--
+ 2 files changed, 7 insertions(+), 4 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 5d970b9fd..949a50b2b 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -217,14 +217,13 @@ if(ENABLE_ZLIB_SUPPORT)
+     endif(ZLIB_FOUND)
+ endif(ENABLE_ZLIB_SUPPORT)
+ 
+-add_subdirectory(include)
+-
+ add_subdirectory(3rdparty)
+ include_directories(${thirdparty_inc})
+ list(APPEND libs ${thirdparty_lib})
+ add_definitions(${thirdparty_def})
+ 
+ add_subdirectory(library)
++add_subdirectory(include)
+ 
+ if(ENABLE_PROGRAMS)
+     add_subdirectory(programs)
+diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt
+index fe74de25d..02cd157bb 100644
+--- a/library/CMakeLists.txt
++++ b/library/CMakeLists.txt
+@@ -192,7 +192,9 @@ if(USE_STATIC_MBEDTLS_LIBRARY)
+     set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto)
+     target_link_libraries(${mbedcrypto_static_target} ${libs})
+     target_include_directories(${mbedcrypto_static_target}
+-        PUBLIC ${MBEDTLS_DIR}/include/)
++        PUBLIC ${MBEDTLS_DIR}/include/
++        PUBLIC ${MBEDTLS_DIR}/include/mbedtls/
++    )
+ 
+     add_library(${mbedx509_static_target} STATIC ${src_x509})
+     set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509)
+@@ -213,7 +215,9 @@ if(USE_SHARED_MBEDTLS_LIBRARY)
+     set_target_properties(${mbedcrypto_target} PROPERTIES VERSION 2.23.0 SOVERSION 5)
+     target_link_libraries(${mbedcrypto_target} ${libs})
+     target_include_directories(${mbedcrypto_target}
+-        PUBLIC ${MBEDTLS_DIR}/include/)
++        PUBLIC ${MBEDTLS_DIR}/include/
++        PUBLIC ${MBEDTLS_DIR}/include/mbedtls/
++    )
+ 
+     add_library(${mbedx509_target} SHARED ${src_x509})
+     set_target_properties(${mbedx509_target} PROPERTIES VERSION 2.23.0 SOVERSION 1)
+-- 
+2.20.1
+