Build: Split NS and Secure regression tests build

Seperate NS and Secure regressin test builds.

  - TF-M secure build integrates secure regression tests and test
    services via test/secure_regression.
  - Non-secure regression tests are built via test/ns_regression.
  - Pass tf-m-tests test config to TF-M secure build via argument
    CONFIG_TFM_TEST_CONFIG_FILE.
  - Fix issues when no regression test is enabled.

Signed-off-by: David Hu <david.hu@arm.com>
Change-Id: I1e550bf6d6a36a220275743c3312a61f7ae2c78e
diff --git a/cmake/utils.cmake b/cmake/utils.cmake
index 2717293..2fd6dbb 100644
--- a/cmake/utils.cmake
+++ b/cmake/utils.cmake
@@ -54,3 +54,34 @@
     message(STATUS "${footer}")
 endfunction()
 
+# Collect arguments via command line.
+# cmd_line: the output argument to collect the arguments via command line
+#
+# Those command line arguments will be passed to ExternalProject_Add().
+# Those arguments shall not be populated by the settings parsed inside each ExternalProject_Add()
+function(collect_build_cmd_args cmd_line)
+
+    get_cmake_property(CACHE_ARGS CACHE_VARIABLES)
+    foreach(CACHE_ARG ${CACHE_ARGS})
+        get_property(ARG_HELPSTRING CACHE "${CACHE_ARG}" PROPERTY HELPSTRING)
+        if("${ARG_HELPSTRING}" MATCHES "variable specified on the command line")
+            get_property(CACHE_ARG_TYPE CACHE ${CACHE_ARG} PROPERTY TYPE)
+            set(ARG_VAL ${${CACHE_ARG}})
+
+            # CMake automatically converts relative paths passed via command line into absolute
+            # ones. Since external projects have different base directories compared to root
+            # directory, relative paths will be incorrectly converted inside external projects.
+            # Enforce all the relative paths into abosulte paths before collecting them in the
+            # build command argument list.
+            if(NOT ${ARG_VAL} STREQUAL "")
+                if(IS_DIRECTORY ${ARG_VAL} AND NOT IS_ABSOLUTE ${ARG_VAL})
+                    get_filename_component(ABS_PATH ${ARG_VAL} ABSOLUTE)
+                    set(ARG_VAL ${ABS_PATH})
+                endif()
+            endif()
+            list(APPEND TEMP_CMD_LINE "-D${CACHE_ARG}:${CACHE_ARG_TYPE}=${ARG_VAL}")
+        endif()
+    endforeach()
+
+    set(${cmd_line} ${TEMP_CMD_LINE} PARENT_SCOPE)
+endfunction()