Add deployment for libts

Change-Id: Ic881a04799146f782e13e6df787ec3f3a935233b
Signed-off-by: Julian Hall <julian.hall@arm.com>
diff --git a/deployments/libts/arm-linux/CMakeLists.txt b/deployments/libts/arm-linux/CMakeLists.txt
new file mode 100644
index 0000000..ab512d6
--- /dev/null
+++ b/deployments/libts/arm-linux/CMakeLists.txt
@@ -0,0 +1,48 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.16)
+include(../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  The CMakeLists.txt for building the libts deployment for arm-linux
+#
+#  Used for building the libts library for the arm-linux enviroment.  Used for
+#  locating and accessing services from a Linux userspace client.  Service
+#  instances can be located in any supported secure processing enviroment.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/arm-linux/env_shared_lib.cmake)
+project(trusted-services LANGUAGES CXX C)
+add_library(ts SHARED)
+target_include_directories(ts PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+#-------------------------------------------------------------------------------
+#  Components that are specific to deployment in the arm-linux environment.
+#
+#-------------------------------------------------------------------------------
+add_components(
+	TARGET "ts"
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		"components/rpc/ffarpc/caller/linux"
+		"components/service/locator/linux"
+		"components/service/locator/linux/ffa"
+		"components/common/uuid"
+)
+
+#-------------------------------------------------------------------------------
+#  Extend with components that are common across all deployments of
+#  libts
+#
+#-------------------------------------------------------------------------------
+include(../libts.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  Define library options and dependencies.
+#
+#-------------------------------------------------------------------------------
+env_set_link_options(TGT ts)
+target_link_libraries(ts PRIVATE gcc)
\ No newline at end of file
diff --git a/deployments/libts/libts-import.cmake b/deployments/libts/libts-import.cmake
new file mode 100644
index 0000000..8b58ec9
--- /dev/null
+++ b/deployments/libts/libts-import.cmake
@@ -0,0 +1,49 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+# Import libts into a dependent in-tree deployment build.  Where another
+# deployment uses libts, including this file in the dependent deployment
+# CMake build file allows libts to be built and installed into the binary
+# directory of the dependent.
+#-------------------------------------------------------------------------------
+set(LIBTS_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/libts_install" CACHE PATH "libts installation directory")
+set(LIBTS_PACKAGE_PATH "${LIBTS_INSTALL_PATH}/lib/cmake" CACHE PATH "libts CMake package directory")
+set(LIBTS_SOURCE_DIR "${TS_ROOT}/deployments/libts/${TS_ENV}" CACHE PATH "libts source directory")
+set(LIBTS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/libts-build" CACHE PATH "libts binary directory")
+
+file(MAKE_DIRECTORY ${LIBTS_BINARY_DIR})
+
+#Configure the library
+execute_process(COMMAND
+	${CMAKE_COMMAND}
+		-DCMAKE_INSTALL_PREFIX=${LIBTS_INSTALL_PATH}
+		-GUnix\ Makefiles
+		${LIBTS_SOURCE_DIR}
+	WORKING_DIRECTORY
+		${LIBTS_BINARY_DIR}
+)
+
+if (_exec_error)
+	message(FATAL_ERROR "Configuration step of libts failed with ${_exec_error}.")
+endif()
+
+#Build the library
+execute_process(COMMAND
+	${CMAKE_COMMAND} --build ${LIBTS_BINARY_DIR} -- install -j8
+	RESULT_VARIABLE _exec_error
+)
+
+if (_exec_error)
+	message(FATAL_ERROR "Build step of libts failed with ${_exec_error}.")
+endif()
+
+# Import the built library
+include(${LIBTS_INSTALL_PATH}/lib/cmake/libts_targets.cmake)
+add_library(libts SHARED IMPORTED)
+set_property(TARGET libts PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${LIBTS_INSTALL_PATH}/include")
+set_property(TARGET libts PROPERTY IMPORTED_LOCATION "${LIBTS_INSTALL_PATH}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}ts${CMAKE_SHARED_LIBRARY_SUFFIX}")
diff --git a/deployments/libts/libts.cmake b/deployments/libts/libts.cmake
new file mode 100644
index 0000000..d07e25c
--- /dev/null
+++ b/deployments/libts/libts.cmake
@@ -0,0 +1,61 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+#  The base build file shared between deployments of 'libts' for
+#  different environments.  libts provides a client interface for locating
+#  service instances and establishing RPC sessions for using services.
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+#  Components that are common accross all deployments
+#
+#-------------------------------------------------------------------------------
+add_components(
+	TARGET "ts"
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		"components/rpc/common/caller"
+		"components/rpc/common/interface"
+		"components/service/locator"
+		"components/service/locator/interface"
+)
+
+#-------------------------------------------------------------------------------
+#  Define public interfaces for library
+#
+#-------------------------------------------------------------------------------
+
+# Enable exporting interface symbols for library public interface
+target_compile_definitions(ts PRIVATE
+	EXPORT_PUBLIC_INTERFACE_RPC_CALLER
+	EXPORT_PUBLIC_INTERFACE_SERVICE_LOCATOR
+)
+
+#-------------------------------------------------------------------------------
+#  Export the library and the corresponding public interface header files
+#
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/tools/cmake/common/ExportLibrary.cmake REQUIRED)
+
+# Select public header files to export
+get_property(_rpc_caller_public_header_files TARGET ts
+	PROPERTY RPC_CALLER_PUBLIC_HEADER_FILES
+)
+
+get_property(_service_locator_public_header_files TARGET ts
+	PROPERTY SERVICE_LOCATOR_PUBLIC_HEADER_FILES
+)
+
+# Exports library information in preparation for install
+export_library(
+	TARGET "ts"
+	LIB_NAME "libts"
+	INTERFACE_FILES
+		${_rpc_caller_public_header_files}
+		${_service_locator_public_header_files}
+)
diff --git a/deployments/libts/linux-pc/CMakeLists.txt b/deployments/libts/linux-pc/CMakeLists.txt
new file mode 100644
index 0000000..8de05fd
--- /dev/null
+++ b/deployments/libts/linux-pc/CMakeLists.txt
@@ -0,0 +1,105 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.16)
+include(../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  The CMakeLists.txt for building the libts deployment for linux-pc
+#
+#  Used for building the libts library for the linux-pc enviroment.  Also
+#  builds the libts-test executable that acts as a client for the services
+#  accessed via libts.  For the linux-pc deployment, libts contains
+#  standalone versions of a set of trusted services to support client
+#  application development in a native PC environment.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/linux-pc/env_shared_lib.cmake)
+project(trusted-services LANGUAGES CXX C)
+add_library(ts SHARED)
+target_include_directories(ts PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+#-------------------------------------------------------------------------------
+#  Components that are specific to deployment in the linux-pc environment.
+#
+#-------------------------------------------------------------------------------
+add_components(
+	TARGET "ts"
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		"components/rpc/direct"
+		"components/service/common"
+		"components/service/common/serializer/protobuf"
+		"components/service/common/provider"
+		"components/service/locator/standalone"
+		"components/service/locator/standalone/services/crypto"
+		"components/service/crypto/provider/mbedcrypto"
+		"components/service/crypto/provider/mbedcrypto/entropy_source/mock"
+		"components/service/crypto/provider/serializer/protobuf"
+		"components/service/secure_storage/client/psa"
+		"components/service/secure_storage/provider/secure_flash_store"
+		"components/service/secure_storage/provider/secure_flash_store/flash_fs"
+		"components/service/secure_storage/provider/secure_flash_store/flash"
+		"protocols/rpc/common/packed-c"
+		"protocols/service/crypto/packed-c"
+		"protocols/service/crypto/protobuf"
+		"protocols/service/secure_storage/packed-c"
+)
+
+#-------------------------------------------------------------------------------
+#  Extend with components that are common across all deployments of
+#  libts
+#
+#-------------------------------------------------------------------------------
+include(../libts.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  Components used by libts from external projects
+#
+#-------------------------------------------------------------------------------
+
+# Nanopb
+include(${TS_ROOT}/external/nanopb/nanopb.cmake)
+target_link_libraries(ts PRIVATE nanopb::protobuf-nanopb-static)
+protobuf_generate_all(TGT "ts" NAMESPACE "protobuf" BASE_DIR "${TS_ROOT}/protocols")
+
+# Mbedcrypto
+include(${TS_ROOT}/external/mbed-crypto/mbedcrypto.cmake)
+target_link_libraries(ts PRIVATE mbedcrypto)
+
+#-------------------------------------------------------------------------------
+#  Test executable (libts-test) for testing libts static library
+#
+#-------------------------------------------------------------------------------
+add_executable(libts-test)
+target_include_directories(libts-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+target_link_libraries(libts-test PRIVATE "-Wl,--whole-archive" ts "-Wl,--no-whole-archive")
+
+add_components(
+	TARGET "libts-test"
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		"components/app/test-runner"
+		"components/service/crypto/test/service"
+		"components/service/crypto/client/cpp"
+		"components/service/common/serializer/protobuf"
+		"protocols/service/crypto/protobuf"
+)
+
+#-------------------------------------------------------------------------------
+#  Components used by libts-test from external projects
+#
+#-------------------------------------------------------------------------------
+
+# CppUTest
+include(${TS_ROOT}/external/CppUTest/CppUTest.cmake)
+target_link_libraries(libts-test PRIVATE CppUTest)
+
+# Nanopb
+target_link_libraries(libts-test PRIVATE nanopb::protobuf-nanopb-static)
+protobuf_generate_all(TGT "libts-test" NAMESPACE "protobuf" BASE_DIR "${TS_ROOT}/protocols")
+
+# Mbedcrypto
+target_link_libraries(libts-test PRIVATE mbedcrypto)
diff --git a/tools/b-test/test_data.yaml b/tools/b-test/test_data.yaml
index 3c8c916..f21947e 100644
--- a/tools/b-test/test_data.yaml
+++ b/tools/b-test/test_data.yaml
@@ -11,3 +11,15 @@
       params:
             - "-GUnix Makefiles"
             - "-DSP_DEV_KIT_DIR=$SP_DEV_KIT_DIR"
+    - name: "libts-arm-linux"
+      src: "$TS_ROOT/deployments/libts/arm-linux"
+      os_id : "GNU/Linux"
+      params:
+            - "-GUnix Makefiles"
+            - "-DSP_DEV_KIT_DIR=$SP_DEV_KIT_DIR"
+    - name: "libts-pc-linux"
+      src: "$TS_ROOT/deployments/libts/linux-pc"
+      os_id : "GNU/Linux"
+      params:
+            - "-GUnix Makefiles"
+            - "-DSP_DEV_KIT_DIR=$SP_DEV_KIT_DIR"