Build: Cmake build system

 -- Cmake based build system
 -- Only armclang supported currently

Change-Id: I162357439bb1c871cba3a1c614822ef0b7a73e89
Signed-off-by: Abhishek Pandit <abhishek.pandit@arm.com>
diff --git a/test/CMakeLists.inc b/test/CMakeLists.inc
new file mode 100644
index 0000000..694ab75
--- /dev/null
+++ b/test/CMakeLists.inc
@@ -0,0 +1,33 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2017, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#Definitions to compile the "test" module.
+#This file assumes it will be included from a project specific cmakefile, and
+#will not create a library or executable.
+#Inputs:
+#	TFM_ROOT_DIR - root directory of the TF-M repo.
+#
+#Outputs:
+#	Will modify include directories to make the source compile.
+#	ALL_SRC_C: C source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	ALL_SRC_CXX: C++ source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	ALL_SRC_ASM: assembly source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	Include directories will be modified by using the include_directories() commands as needed.
+
+#Get the current directory where this file is located.
+if(NOT DEFINED TFM_ROOT_DIR)
+	message(FATAL_ERROR "Please set TFM_ROOT_DIR before including this file.")
+endif()
+
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/spm ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core ABSOLUTE)
+# add the framework
+include(${CMAKE_CURRENT_LIST_DIR}/framework/CMakeLists.inc)
+include(${CMAKE_CURRENT_LIST_DIR}/suites/core/CMakeLists.inc)
+include(${CMAKE_CURRENT_LIST_DIR}/suites/invert/CMakeLists.inc)
+include(${CMAKE_CURRENT_LIST_DIR}/suites/sst/CMakeLists.inc)
+include(${CMAKE_CURRENT_LIST_DIR}/test_services/CMakeLists.inc)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..2779982
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,81 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2017, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+cmake_minimum_required(VERSION 3.7)
+
+#Tell cmake where our modules can be found
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake)
+
+#Include common stuff to control cmake.
+include("Common/BuildSys")
+
+#Start an embedded project.
+embedded_project_start(CONFIG "${CMAKE_CURRENT_LIST_DIR}/../ConfigDefault.cmake")
+project(tfm_tests LANGUAGES ASM C)
+embedded_project_fixup()
+
+get_filename_component(TFM_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
+
+#Check incoming configuration options
+if (NOT DEFINED SERVICES_TEST_ENABLED)
+	message(FATAL_ERROR "Incomplete build configuration: SERVICES_TEST_ENABLED is undefined. ")
+endif()
+
+if (NOT DEFINED CORE_TEST)
+	message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ")
+endif()
+
+if(CORE_TEST)
+	set (TFM_LVL 3)
+else()
+	set (TFM_LVL 1)
+endif()
+
+#Configure our options as needed.
+if (CORE_TEST_INTERACTIVE OR CORE_TEST_POSITIVE)
+	set(ENABLE_CORE_TESTS True)
+	set(ENABLE_CORE_TESTS_2 True)
+else()
+	set(ENABLE_CORE_TESTS False)
+	set(ENABLE_CORE_TESTS_2 False)
+endif()
+
+if (NOT DEFINED CMSIS_5_DIR)
+	set(CMSIS_5_DIR ${TFM_ROOT_DIR}/../CMSIS_5)
+endif()
+set(ENABLE_SECURE_STORAGE_SERVICE_TESTS TRUE)
+set(ENABLE_INVERT_SERVICE_TESTS TRUE)
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeLists.inc)
+
+#Build the secure library
+add_library(tfm_secure_tests STATIC ${ALL_SRC_C} ${ALL_SRC_C_S})
+embedded_set_target_compile_defines(TARGET tfm_secure_tests LANGUAGE C DEFINES __thumb2__ __ARM_FEATURE_CMSE=3 TFM_LVL=${TFM_LVL} APPEND)
+
+
+#Build the non-secure library
+set(CMAKE_STATIC_LIBRARY_PREFIX_C "lib")
+add_library(tfm_non_secure_tests STATIC ${ALL_SRC_C} ${ALL_SRC_C_NS})
+embedded_set_target_compile_defines(TARGET tfm_non_secure_tests LANGUAGE C DEFINES __thumb2__ __ARM_FEATURE_CMSE=3 __DOMAIN_NS=1 APPEND)
+#__DOMAIN_NS=1
+
+if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+  SET(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Default install location for tfm_storage." FORCE)
+endif()
+
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/framework/integ_test.h
+				${CMAKE_CURRENT_SOURCE_DIR}/suites/core/non_secure/svc_core_test_ns.h
+				${CMAKE_CURRENT_SOURCE_DIR}/suites/sst/non_secure/os_wrapper.h
+		DESTINATION tfm/test/inc)
+
+install(TARGETS tfm_non_secure_tests
+		DESTINATION tfm/test/lib
+		PUBLIC_HEADER DESTINATION tfm/test/inc)
+
+
+embedded_project_end(tfm_non_secure_tests)
+embedded_project_end(tfm_secure_tests)
+
diff --git a/test/framework/CMakeLists.inc b/test/framework/CMakeLists.inc
new file mode 100644
index 0000000..0f22dbc
--- /dev/null
+++ b/test/framework/CMakeLists.inc
@@ -0,0 +1,46 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2017, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#Definitions to compile the "test framework" module.
+#This file assumes it will be included from a project specific cmakefile, and
+#will not create a library or executable.
+#Inputs:
+#	TFM_ROOT_DIR - root directory of the TF-M repo.
+#
+#Outputs:
+#	Will modify include directories to make the source compile.
+#	ALL_SRC_C: C source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	ALL_SRC_CXX: C++ source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	ALL_SRC_ASM: assembly source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	Include directories will be modified by using the include_directories() commands as needed.
+
+#Get the current directory where this file is located.
+set(TEST_FRAMEWORK_DIR ${CMAKE_CURRENT_LIST_DIR})
+if(NOT DEFINED TFM_ROOT_DIR)
+	message(FATAL_ERROR "Please set TFM_ROOT_DIR before including this file.")
+endif()
+
+set (TEST_FRAMEWORK_C_SRC "${TEST_FRAMEWORK_DIR}/helpers.c"
+		"${TEST_FRAMEWORK_DIR}/integ_test_helper.c"
+		"${TEST_FRAMEWORK_DIR}/test_framework.c"
+	)
+
+set (TEST_FRAMEWORK_C_SRC_NS "${TEST_FRAMEWORK_DIR}/non_secure_suites.c"
+	)
+
+set (TEST_FRAMEWORK_C_SRC_S "${TEST_FRAMEWORK_DIR}/secure_suites.c"
+	)
+
+#Append all our source files to global lists.
+list(APPEND ALL_SRC_C ${TEST_FRAMEWORK_C_SRC})
+list(APPEND ALL_SRC_C_S ${TEST_FRAMEWORK_C_SRC_S})
+list(APPEND ALL_SRC_C_NS ${TEST_FRAMEWORK_C_SRC_NS})
+
+#Setting include directories
+embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
+
diff --git a/test/suites/core/CMakeLists.inc b/test/suites/core/CMakeLists.inc
new file mode 100644
index 0000000..4c516d1
--- /dev/null
+++ b/test/suites/core/CMakeLists.inc
@@ -0,0 +1,49 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2017, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#Definitions to compile the "core test" module.
+#This file assumes it will be included from a project specific cmakefile, and
+#will not create a library or executable.
+#Inputs:
+#	TFM_ROOT_DIR - root directory of the TF-M repo.
+#
+#Outputs:
+#	Will modify include directories to make the source compile.
+#	ALL_SRC_C: C source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	ALL_SRC_CXX: C++ source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	ALL_SRC_ASM: assembly source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	Include directories will be modified by using the include_directories() commands as needed.
+
+#Get the current directory where this file is located.
+set(CORE_TEST_DIR ${CMAKE_CURRENT_LIST_DIR})
+if(NOT DEFINED TFM_ROOT_DIR)
+	message(FATAL_ERROR "Please set TFM_ROOT_DIR before including this file.")
+endif()
+
+if (NOT DEFINED CORE_TEST_SERVICES)
+	message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined. ")
+elseif (CORE_TEST_SERVICES)
+	list(APPEND ALL_SRC_C_NS "${CORE_TEST_DIR}/non_secure/core_test_api.c"
+		"${CORE_TEST_DIR}/non_secure/svc_core_test_ns.c")
+endif()
+
+if (NOT DEFINED CORE_TEST_POSITIVE)
+	message(FATAL_ERROR "Incomplete build configuration: CORE_TEST_POSITIVE is undefined. ")
+elseif (CORE_TEST_POSITIVE)
+	list(APPEND ALL_SRC_C_NS "${CORE_TEST_DIR}/non_secure/core_ns_positive_testsuite.c")
+endif()
+
+if (NOT DEFINED CORE_TEST_INTERACTIVE)
+	message(FATAL_ERROR "Incomplete build configuration: CORE_TEST_INTERACTIVE is undefined. ")
+elseif (CORE_TEST_INTERACTIVE)
+	list(APPEND ALL_SRC_C_NS "${CORE_TEST_DIR}/non_secure/core_ns_interactive_testsuite.c")
+endif()
+
+#Setting include directories
+embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
+
diff --git a/test/suites/invert/CMakeLists.inc b/test/suites/invert/CMakeLists.inc
new file mode 100644
index 0000000..1fc55af
--- /dev/null
+++ b/test/suites/invert/CMakeLists.inc
@@ -0,0 +1,36 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2017, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#Definitions to compile the "secure invert test" module.
+#This file assumes it will be included from a project specific cmakefile, and
+#will not create a library or executable.
+#Inputs:
+#	TFM_ROOT_DIR - root directory of the TF-M repo.
+#
+#Outputs:
+#	Will modify include directories to make the source compile.
+#	ALL_SRC_C: C source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	ALL_SRC_CXX: C++ source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	ALL_SRC_ASM: assembly source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	Include directories will be modified by using the include_directories() commands as needed.
+
+#Get the current directory where this file is located.
+set(SECURE_INVERT_TEST_DIR ${CMAKE_CURRENT_LIST_DIR})
+if(NOT DEFINED TFM_ROOT_DIR)
+	message(FATAL_ERROR "Please set TFM_ROOT_DIR before including this file.")
+endif()
+
+if (NOT DEFINED ENABLE_INVERT_SERVICE_TESTS)
+	message(FATAL_ERROR "Incomplete build configuration: ENABLE_INVERT_SERVICE_TESTS is undefined. ")
+elseif(ENABLE_INVERT_SERVICE_TESTS)
+	list(APPEND ALL_SRC_C_S "${SECURE_INVERT_TEST_DIR}/secure/invert_s_interface_testsuite.c")
+	list(APPEND ALL_SRC_C_NS "${SECURE_INVERT_TEST_DIR}/non_secure/invert_ns_interface_testsuite.c")
+
+	#Setting include directories
+	embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
+	embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
+endif()
diff --git a/test/suites/sst/CMakeLists.inc b/test/suites/sst/CMakeLists.inc
new file mode 100644
index 0000000..125649d
--- /dev/null
+++ b/test/suites/sst/CMakeLists.inc
@@ -0,0 +1,49 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2017, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#Definitions to compile the "secure storage test" module.
+#This file assumes it will be included from a project specific cmakefile, and
+#will not create a library or executable.
+#Inputs:
+#	TFM_ROOT_DIR - root directory of the TF-M repo.
+#
+#Outputs:
+#	Will modify include directories to make the source compile.
+#	ALL_SRC_C: C source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	ALL_SRC_CXX: C++ source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	ALL_SRC_ASM: assembly source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	Include directories will be modified by using the include_directories() commands as needed.
+
+#Get the current directory where this file is located.
+set(SECURE_STORAGE_TEST_DIR ${CMAKE_CURRENT_LIST_DIR})
+if(NOT DEFINED TFM_ROOT_DIR)
+	message(FATAL_ERROR "Please set TFM_ROOT_DIR before including this file.")
+endif()
+
+if(NOT DEFINED CMSIS_5_DIR)
+	message(FATAL_ERROR "Please set CMSIS_5_DIR before including this file.")
+endif()
+
+if (NOT DEFINED ENABLE_SECURE_STORAGE_SERVICE_TESTS)
+	message(FATAL_ERROR "Incomplete build configuration: ENABLE_SECURE_STORAGE_SERVICE_TESTS is undefined. ")
+elseif (ENABLE_SECURE_STORAGE_SERVICE_TESTS)
+	list(APPEND ALL_SRC_C_S "${SECURE_STORAGE_TEST_DIR}/secure/s_test_helpers.c"
+			"${SECURE_STORAGE_TEST_DIR}/secure/sst_sec_interface_testsuite.c"
+			"${SECURE_STORAGE_TEST_DIR}/secure/sst_reliability_testsuite.c"
+			"${SECURE_STORAGE_TEST_DIR}/secure/sst_policy_testsuite.c"
+		)
+
+	list(APPEND ALL_SRC_C_NS "${SECURE_STORAGE_TEST_DIR}/non_secure/sst_ns_interface_testsuite.c")
+
+	#Setting include directories
+	embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
+	embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
+
+	embedded_include_directories(PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Include ABSOLUTE)
+	embedded_include_directories(PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/Include ABSOLUTE)
+	embedded_include_directories(PATH ${CMSIS_5_DIR}/CMSIS/RTOS2/RTX/Config  ABSOLUTE)
+endif()
diff --git a/test/test_services/CMakeLists.inc b/test/test_services/CMakeLists.inc
new file mode 100644
index 0000000..c5b57bd
--- /dev/null
+++ b/test/test_services/CMakeLists.inc
@@ -0,0 +1,54 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2017, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#Definitions to compile the "secure services" module.
+#This file assumes it will be included from a project specific cmakefile, and
+#will not create a library or executable.
+#Inputs:
+#	TFM_ROOT_DIR - root directory of the TF-M repository.
+#
+#Outputs:
+#	Will modify include directories to make the source compile.
+#	ALL_SRC_C: C source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	ALL_SRC_CXX: C++ source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	ALL_SRC_ASM: assembly source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
+#	Include directories will be modified by using the include_directories() commands as needed.
+
+#Get the current directory where this file is located.
+set(CORE_TEST_DIR ${CMAKE_CURRENT_LIST_DIR})
+
+#Check input variables
+if (NOT DEFINED TFM_ROOT_DIR)
+	message(FATAL_ERROR "Please set TFM_ROOT_DIR before including this file.")
+endif()
+
+if (NOT DEFINED ENABLE_CORE_TESTS)
+	message(FATAL_ERROR "Incomplete build configuration: ENABLE_CORE_TESTS is undefined. ")
+elseif(ENABLE_CORE_TESTS)
+	list(APPEND ALL_SRC_C_S "${CORE_TEST_DIR}/tfm_core_test/tfm_ss_core_test.c"
+		"${CORE_TEST_DIR}/tfm_core_test/tfm_ss_core_test_veneers.c"
+		)
+endif()
+
+if (NOT DEFINED ENABLE_CORE_TESTS_2)
+	message(FATAL_ERROR "Incomplete build configuration: ENABLE_CORE_TESTS_2 is undefined. ")
+elseif(ENABLE_CORE_TESTS_2)
+	list(APPEND ALL_SRC_C_S "${CORE_TEST_DIR}/tfm_core_test_2/tfm_ss_core_test_2_veneers.c"
+		"${CORE_TEST_DIR}/tfm_core_test_2/tfm_ss_core_test_2.c"
+		)
+endif()
+
+embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
+embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
+
+set(PLATFORM_DIR ${TFM_ROOT_DIR}/platform)
+embedded_include_directories(PATH "${PLATFORM_DIR}/cmsis" ABSOLUTE)
+embedded_include_directories(PATH "${PLATFORM_DIR}/target/sse_200_mps2/cmsis_core" ABSOLUTE)
+embedded_include_directories(PATH "${PLATFORM_DIR}//target/sse_200_mps2/sse_200/retarget" ABSOLUTE)
+embedded_include_directories(PATH "${PLATFORM_DIR}/target/sse_200_mps2/mps2/mps2_board" ABSOLUTE)
+
+