Build: Support relative path of toolchain file in command line

The absolute paths of NS toolchain files specified in command line can
be quite long, as they are usually installed under CONFIG_SPE_PATH.

Support relative paths of NS toolchain file in command line.
The relative paths can be converted into absolute ones based on
CONFIG_SPE_PATH.

Signed-off-by: David Hu <david.hu@arm.com>
Change-Id: Ic3f97872e3619eb8d5a82c5ed6aff0dd77945e2e
diff --git a/cmake/toolchain_selection.cmake b/cmake/toolchain_selection.cmake
new file mode 100644
index 0000000..9deefd5
--- /dev/null
+++ b/cmake/toolchain_selection.cmake
@@ -0,0 +1,28 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+# Select toolchain file if it is not specified via command line or the absolutate path
+# is unavailable.
+
+if (NOT DEFINED TFM_TOOLCHAIN_FILE)
+    set(TFM_TOOLCHAIN_FILE    ${CONFIG_SPE_PATH}/cmake/toolchain_ns_GNUARM.cmake)
+endif()
+
+if(NOT IS_ABSOLUTE ${TFM_TOOLCHAIN_FILE})
+    get_filename_component(RELATIVE_DIR ${TFM_TOOLCHAIN_FILE} DIRECTORY)
+    if("${RELATIVE_DIR}" STREQUAL "")
+        # Assume the toolchain is put in ${CONFIG_SPE_PATH}/cmake
+        set(TFM_TOOLCHAIN_FILE "${CONFIG_SPE_PATH}/cmake/${TFM_TOOLCHAIN_FILE}")
+    else()
+        # Assume the relative path is based on ${CONFIG_SPE_PATH}
+        set(TFM_TOOLCHAIN_FILE "${CONFIG_SPE_PATH}/${TFM_TOOLCHAIN_FILE}")
+    endif()
+endif()
+
+if(NOT EXISTS ${TFM_TOOLCHAIN_FILE})
+    message(FATAL_ERROR "TFM_TOOLCHAIN_FILE ${TFM_TOOLCHAIN_FILE} doesn't exist")
+endif()