Build: Generalize build steps for various toolchains

Various toolchains have different behaviours and requirements in CMake
implementation.
Generalize several steps in build sequence in NS build, to conceal
differences between various toolchains.

 - Accept TFM_TOOLCHAIN_FILE from command line as the existing build
   system does. TFM_TOOLCHAIN_FILE conceals different setup steps in
   toolchains.
 - Call tfm_toolchain_reload_compiler() after project() to support
   Armclang to setup compiler flags after project().
 - Code of some build steps is moved from TF-M NS build example to
   tests build. NS target names are hard-coded in those steps.
   Remove those code from TF-M to avoid coupling NS and S again.

Signed-off-by: David Hu <david.hu@arm.com>
Change-Id: I1a2964ffed83e45f3d0aafce7ac4f4e9b553f3a6
diff --git a/tests_reg/CMakeLists.txt b/tests_reg/CMakeLists.txt
index 29c1501..e3f7685 100644
--- a/tests_reg/CMakeLists.txt
+++ b/tests_reg/CMakeLists.txt
@@ -10,9 +10,8 @@
     message(FATAL_ERROR "CONFIG_SPE_PATH = ${CONFIG_SPE_PATH} is not defined or incorrect. Please provide full path to TF-M build artifacts using -DCONFIG_SPE_PATH=")
 endif()
 
-if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
-    set(CROSS_COMPILE         arm-none-eabi)
-    set(CMAKE_TOOLCHAIN_FILE  ${CONFIG_SPE_PATH}/cmake/toolchain_ns_GNUARM.cmake)
+if (NOT DEFINED TFM_TOOLCHAIN_FILE)
+    set(TFM_TOOLCHAIN_FILE    ${CONFIG_SPE_PATH}/cmake/toolchain_ns_GNUARM.cmake)
 endif()
 
 # A platform sprecific MCPU and architecture flags for NS side
@@ -35,7 +34,9 @@
 
 add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../lib/ext ${CMAKE_BINARY_DIR}/lib/ext)
 
+include(${TFM_TOOLCHAIN_FILE})
 project(tfm_ns LANGUAGES C)
+tfm_toolchain_reload_compiler()
 
 add_executable(tfm_ns)
 
@@ -67,3 +68,5 @@
     PRIVATE
         $<$<C_COMPILER_ID:GNU>:-Wl,-Map=${CMAKE_BINARY_DIR}/bin/tfm_ns.map>
 )
+
+add_convert_to_bin_target(tfm_ns)