Rename libpsa to libpsats

Instead of using a generic name for the library, give it a TS specific
name to avoid possible naming collisions with other psa libraries in
the future.

Change-Id: Icea9be4d836f7d22300b20c8d6a5f8bd8fae1133
Signed-off-by: Gabor Toth <gabor.toth2@arm.com>
diff --git a/deployments/libpsats/arm-linux/CMakeLists.txt b/deployments/libpsats/arm-linux/CMakeLists.txt
new file mode 100644
index 0000000..20e4f1b
--- /dev/null
+++ b/deployments/libpsats/arm-linux/CMakeLists.txt
@@ -0,0 +1,44 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
+include(../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  Options and variables
+#-------------------------------------------------------------------------------
+set(BUILD_SHARED_LIBS On CACHE BOOL "Determine if a shared library is being built.")
+if(NOT BUILD_SHARED_LIBS)
+	message(FATAL_ERROR "Building static library is not yet supported. Call cmake with -DBUILD_SHARED_LIBS=1")
+endif()
+
+#-------------------------------------------------------------------------------
+#  The CMakeLists.txt for building the libpsats deployment for arm-linux
+#
+#  Used for building the libpsats library for the arm-linux environment. Used for
+#  locating and accessing services from a Linux userspace client. Service
+#  instances can be located in any supported secure processing environment.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/arm-linux/env_shared_lib.cmake)
+project(psats LANGUAGES CXX C)
+
+add_library(psats)
+
+target_include_directories(psats PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+#-------------------------------------------------------------------------------
+#  For user-specific tracing set to TRACE_LEVEL_NONE and implement:
+#  void trace_puts(const char *str)
+#-------------------------------------------------------------------------------
+
+set(TRACE_PREFIX "LIBPSATS" CACHE STRING "Trace prefix")
+set(TRACE_LEVEL "TRACE_LEVEL_DEBUG" CACHE STRING "Trace level")
+#-------------------------------------------------------------------------------
+#  Extend with components that are common across all deployments of
+#  libpsats
+#
+#-------------------------------------------------------------------------------
+include(../libpsats.cmake REQUIRED)
diff --git a/deployments/libpsats/libpsats-import.cmake b/deployments/libpsats/libpsats-import.cmake
new file mode 100644
index 0000000..9c44ca7
--- /dev/null
+++ b/deployments/libpsats/libpsats-import.cmake
@@ -0,0 +1,114 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+# Import libpsats into a dependent in-tree deployment build.  Where another
+# deployment uses libpsats, including this file in the dependent deployment
+# CMake build file allows libpsats to be built and installed into the binary
+# directory of the dependent.
+#-------------------------------------------------------------------------------
+option(CFG_FORCE_PREBUILT_LIBPSATS Off)
+# Try to find a pre-build package.
+version_semver_read(FILE "${CMAKE_CURRENT_LIST_DIR}/version.txt" MAJOR _major MINOR _minor PATCH _patch)
+set(_verstring "${_major}.${_minor}.${_patch}")
+
+if (COVERAGE)
+	set(LIBPSATS_BUILD_TYPE "DebugCoverage" CACHE STRING "Build type." FORCE)
+endif()
+
+find_package(libpsats "${_verstring}" QUIET PATHS ${CMAKE_CURRENT_BINARY_DIR}/libpsats_install/${TS_ENV}/lib/cmake/libpsats)
+if(NOT libpsats_FOUND)
+	if (CFG_FORCE_PREBUILT_LIBPSATS)
+		string(CONCAT _msg "find_package() failed to find the \"libpsats\" package. Please pass -Dlibpsats_ROOT=<full path>"
+							" to cmake, where <full path> is the directory of the libpsatsConfig.cmake file, or "
+							" pass -DCMAKE_FIND_ROOT_PATH=<path>, where <path> is the INSTALL_PREFIX used"
+							" when building libpsats. libpsats_ROOT can be set in the environment too."
+						   "If you wish to debug the search process pass -DCMAKE_FIND_DEBUG_MODE=ON to cmake.")
+		message(FATAL_ERROR ${_msg})
+	endif()
+	# Set build type, if a specific value is required. This leaves the default value in the hands of the
+	# libpsats deployment being built.
+	if (DEFINED LIBPSATS_BUILD_TYPE)
+		set(_libpsats_build_type_arg "-DCMAKE_BUILD_TYPE=${LIBPSATS_BUILD_TYPE}")
+	endif()
+
+	# If not successful, build libpsats as a sub-project.
+	execute_process(COMMAND
+		${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}"
+		${CMAKE_COMMAND}
+			${_libpsats_build_type_arg}
+			-S ${TS_ROOT}/deployments/libpsats/${TS_ENV}
+			-B ${CMAKE_CURRENT_BINARY_DIR}/libpsats
+		RESULT_VARIABLE
+			_exec_error
+		)
+	unset(_libpsats_build_type_arg)
+	if (NOT _exec_error EQUAL 0)
+		message(FATAL_ERROR "Configuring libpsats failed. ${_exec_error}")
+	endif()
+	execute_process(COMMAND
+		${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}"
+		${CMAKE_COMMAND}
+			--build ${CMAKE_CURRENT_BINARY_DIR}/libpsats
+			--parallel ${PROCESSOR_COUNT}
+		RESULT_VARIABLE
+			_exec_error
+		)
+	if (NOT _exec_error EQUAL 0)
+		message(FATAL_ERROR "Installing libpsats failed. ${_exec_error}")
+	endif()
+	execute_process(COMMAND
+		${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}"
+		${CMAKE_COMMAND}
+			--install ${CMAKE_CURRENT_BINARY_DIR}/libpsats
+			--prefix ${CMAKE_CURRENT_BINARY_DIR}/libpsats_install
+		RESULT_VARIABLE
+			_exec_error
+		)
+	if (NOT _exec_error EQUAL 0)
+		message(FATAL_ERROR "Installing libpsats failed. ${_exec_error}")
+	endif()
+
+	install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/libpsats/cmake_install.cmake)
+
+	find_package(libpsats "${_verstring}" QUIET REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/libpsats_install/${TS_ENV}/lib/cmake/libpsats)
+else()
+	message(STATUS "Using prebuilt libpsats from ${libpsats_DIR}")
+endif()
+
+# Cmake will use the same build type of the imported target as used by the main project. If no mapping is configured and
+# the matching build type is not found, cmake will fall back to any build type. Details of the fall back mechanism are not
+# documented.
+# If a mapping is defined, and the imported target does not define the mapped build type, cmake will treat the library
+# as not found.
+#
+# If LIBPSATS_BUILD_TYPE is set and the main project wants to use a specific build type, configure build type mapping to
+# only allow using the requested build type.
+if (DEFINED LIBPSATS_BUILD_TYPE)
+	set_target_properties(libpsats::psats PROPERTIES
+		MAP_IMPORTED_CONFIG_DEBUG				${LIBPSATS_BUILD_TYPE}
+		MAP_IMPORTED_CONFIG_MINSIZEREL			${LIBPSATS_BUILD_TYPE}
+		MAP_IMPORTED_CONFIG_MINSIZWITHDEBINFO	${LIBPSATS_BUILD_TYPE}
+		MAP_IMPORTED_CONFIG_RELEASE				${LIBPSATS_BUILD_TYPE}
+		MAP_IMPORTED_CONFIG_RELWITHDEBINFO		${LIBPSATS_BUILD_TYPE}
+		MAP_IMPORTED_CONFIG_DEBUGCOVERAGE		${LIBPSATS_BUILD_TYPE}
+	)
+
+	# Do a manual check and issue a better message than the default one.
+	get_property(_libpsats_build_type TARGET libpsats::psats PROPERTY IMPORTED_CONFIGURATIONS)
+	string(TOUPPER ${LIBPSATS_BUILD_TYPE} _uc_libpsats_build_type)
+	if(${_uc_libpsats_build_type} IN_LIST _libpsats_build_type)
+	else()
+		message(FATAL_ERROR "Installed libpsats package does not supports required build type ${LIBPSATS_BUILD_TYPE}.")
+	endif()
+	unset(_libpsats_build_type)
+	unset(_uc_libpsats_build_type)
+endif()
+
+# libpsats can not be used without libts, so add the needed dependency.
+include(${TS_ROOT}/deployments/libts/libts-import.cmake)
+target_link_libraries(libpsats::psats INTERFACE libts::ts)
diff --git a/deployments/libpsats/libpsats.cmake b/deployments/libpsats/libpsats.cmake
new file mode 100644
index 0000000..9ce0039
--- /dev/null
+++ b/deployments/libpsats/libpsats.cmake
@@ -0,0 +1,107 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+#  The base build file shared between deployments of 'libpsats' for different
+#  environments.  libpsats provides an interface for accessing PSA API-s.
+#  Building with each build type results in different postfix for the library.
+#  For details, please refer to deployment.cmake.
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+#  Common API version implemented by all libpsats deployments
+#-------------------------------------------------------------------------------
+version_semver_read(FILE "${CMAKE_CURRENT_LIST_DIR}/version.txt"
+					MAJOR _major MINOR _minor PATCH _patch)
+set_target_properties(psats PROPERTIES VERSION "${_major}.${_minor}.${_patch}")
+set_target_properties(psats PROPERTIES SOVERSION "${_major}")
+unset(_major)
+unset(_minor)
+unset(_patch)
+
+add_library(libpsats::psats ALIAS psats)
+
+if (COVERAGE)
+	set(LIBPSATS_BUILD_TYPE "DebugCoverage" CACHE STRING "Build type." FORCE)
+endif()
+
+#-------------------------------------------------------------------------------
+#  Use libts for locating and accessing services. An appropriate version of
+#  libts will be imported for the environment in which service tests are
+#  deployed.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/deployments/libts/libts-import.cmake)
+target_link_libraries(psats PUBLIC libts::ts)
+
+#-------------------------------------------------------------------------------
+#  Components that are common across all deployments
+#
+#-------------------------------------------------------------------------------
+
+add_components(
+	TARGET "psats"
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		"environments/${TS_ENV}"
+		"components/common/utils"
+		"components/common/trace"
+		"components/common/libpsats"
+		"components/common/tlv"
+		"components/service/common/include"
+		"components/service/common/client"
+		"components/service/crypto/include"
+		"components/service/crypto/client/psa"
+		"components/service/attestation/include"
+		"components/service/attestation/client/psa"
+		"components/service/attestation/client/provision"
+		"components/service/secure_storage/include"
+		"components/service/secure_storage/frontend/psa/its"
+		"components/service/secure_storage/frontend/psa/ps"
+		"components/service/secure_storage/backend/secure_storage_client"
+)
+
+#-------------------------------------------------------------------------------
+#  Define public interfaces for library
+#
+#-------------------------------------------------------------------------------
+
+# Enable exporting interface symbols for library public interface
+target_compile_definitions(psats PRIVATE
+	EXPORT_PUBLIC_INTERFACE_LIBPSATS
+	EXPORT_PUBLIC_INTERFACE_PSA_CRYPTO
+	EXPORT_PUBLIC_INTERFACE_PSA_ATTEST
+	EXPORT_PUBLIC_INTERFACE_PSA_ITS
+	EXPORT_PUBLIC_INTERFACE_PSA_PS
+)
+
+#-------------------------------------------------------------------------------
+#  Export the library and the corresponding public interface header files
+#
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/tools/cmake/common/ExportLibrary.cmake REQUIRED)
+
+# Exports library information in preparation for install
+export_library(
+	TARGET "psats"
+	LIB_NAME "libpsats"
+	PKG_CONFIG_FILE "${CMAKE_CURRENT_LIST_DIR}/libpsatsConfig.cmake.in"
+)
+
+install(DIRECTORY "${TS_ROOT}/components/service/crypto/include"
+		DIRECTORY "${TS_ROOT}/components/service/attestation/include"
+		DIRECTORY "${TS_ROOT}/components/service/secure_storage/include"
+		DESTINATION "${TS_ENV}"
+		FILES_MATCHING PATTERN "*.h"
+)
+
+install(FILES "${TS_ROOT}/components/service/common/include/psa/error.h"
+		DESTINATION ${TS_ENV}/include/psa
+)
+
+install(FILES "${TS_ROOT}/components/common/libpsats/libpsats.h"
+		DESTINATION ${TS_ENV}/include
+)
diff --git a/deployments/libpsats/libpsatsConfig.cmake.in b/deployments/libpsats/libpsatsConfig.cmake.in
new file mode 100644
index 0000000..f23ed8d
--- /dev/null
+++ b/deployments/libpsats/libpsatsConfig.cmake.in
@@ -0,0 +1,9 @@
+#
+# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+@PACKAGE_INIT@
+
+include("${CMAKE_CURRENT_LIST_DIR}/libpsatsTargets.cmake")
diff --git a/deployments/libpsats/linux-pc/CMakeLists.txt b/deployments/libpsats/linux-pc/CMakeLists.txt
new file mode 100644
index 0000000..1d3696b
--- /dev/null
+++ b/deployments/libpsats/linux-pc/CMakeLists.txt
@@ -0,0 +1,44 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
+include(../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+#  Options and variables
+#-------------------------------------------------------------------------------
+set(BUILD_SHARED_LIBS On CACHE BOOL "Determine if a shared library is being built.")
+if(NOT BUILD_SHARED_LIBS)
+	message(FATAL_ERROR "Building static library is not yet supported. Call cmake with -DBUILD_SHARED_LIBS=1")
+endif()
+
+#-------------------------------------------------------------------------------
+#  The CMakeLists.txt for building the libpsats deployment for arm-linux
+#
+#  Used for building the libpsats library for the arm-linux environment. Used for
+#  locating and accessing services from a Linux userspace client. Service
+#  instances can be located in any supported secure processing environment.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/linux-pc/env_shared_lib.cmake)
+project(psats LANGUAGES CXX C)
+
+add_library(psats)
+
+target_include_directories(psats PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+#-------------------------------------------------------------------------------
+#  For user-specific tracing set to TRACE_LEVEL_NONE and implement:
+#  void trace_puts(const char *str)
+#-------------------------------------------------------------------------------
+
+set(TRACE_PREFIX "LIBPSATS" CACHE STRING "Trace prefix")
+set(TRACE_LEVEL "TRACE_LEVEL_DEBUG" CACHE STRING "Trace level")
+#-------------------------------------------------------------------------------
+#  Extend with components that are common across all deployments of
+#  libpsats
+#
+#-------------------------------------------------------------------------------
+include(../libpsats.cmake REQUIRED)
diff --git a/deployments/libpsats/version.txt b/deployments/libpsats/version.txt
new file mode 100644
index 0000000..afaf360
--- /dev/null
+++ b/deployments/libpsats/version.txt
@@ -0,0 +1 @@
+1.0.0
\ No newline at end of file