Build: add build type support

Refactor cmake files to support setting the "build type" following CMake
idioms. A "build type" is a set of compiler flags controlling code
optimization and debug information generation. For more information on
the supported types and their meaning please refer to the documentation.

This change extends build type support to external components too. The
build type of each component can be independently controlled using
command line settings. For details about the supported types and
settings, please refer to the cmake file of the external component and
the documentation of the external project.

This change tries to be backwards compatible and selects the default
build type to be "Debug". This may change in the future.

Change-Id: Ic041140bb8d4aaf0f07be9c4cac0638c03996eb5
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
diff --git a/deployments/deployment.cmake b/deployments/deployment.cmake
index e1aaed0..3e13a54 100644
--- a/deployments/deployment.cmake
+++ b/deployments/deployment.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -55,4 +55,22 @@
 define_property(TARGET PROPERTY TS_PLATFORM_DRIVER_DEPENDENCIES
   BRIEF_DOCS "List of platform driver interfaces used for a deployment."
   FULL_DOCS "Used by the platform specific builder to specify a configuration for the built platform components."
-  )
\ No newline at end of file
+  )
+
+# Set default build type to Debug
+if (NOT CMAKE_BUILD_TYPE)
+  set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type.")
+endif()
+
+# List of supported build types. Needs to be in alignment with the toolchain file
+set(TS_SUPPORTED_BUILD_TYPES DEBUG "MINSIZEREL" "MINSIZWITHDEBINFO" "RELEASE" "RELWITHDEBINFO" CACHE
+  STRING "List of supported build types.")
+
+# Convert the build type string to upper case to help case insensitive comparison.
+string(TOUPPER "${CMAKE_BUILD_TYPE}" UC_CMAKE_BUILD_TYPE CACHE STRING "Easy to compare build type.")
+mark_as_advanced(UC_CMAKE_BUILD_TYPE)
+
+# Validate build type
+if (NOT "${UC_CMAKE_BUILD_TYPE}" IN_LIST TS_SUPPORTED_BUILD_TYPES)
+	message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\" specified in CMAKE_BUILD_TYPE.")
+endif()