libsp: Add build system files.

- Add opteesp deployment.
    This deployment builds libsp as a static library targeting aarch64
    SPs running under OP-TEE.
- Add inport and export interfaces for OP TEE-OS.
- Add opteesp environment files.
- Add shared CMake scripts including GCC compiler support.

Change-Id: Ie8643756d45d0d96822fd98c4c37e7264a7378a1
Signed-off-by: Gyorgy Szing <gyorgy.szing@arm.com>
diff --git a/deployments/deployment.cmake b/deployments/deployment.cmake
new file mode 100644
index 0000000..6543318
--- /dev/null
+++ b/deployments/deployment.cmake
@@ -0,0 +1,33 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#[===[.rst:
+  The base deployment CMake file
+  ------------------------------
+
+  Contains common CMake definitions that are used by concrete deployments.
+  This file should be included first by a concrete deployment's CMakeLists.txt.
+#]===]
+
+# Sets TS-ROOT which is used as the reference directory for everything contained within the project
+get_filename_component(TS_ROOT "${CMAKE_CURRENT_LIST_DIR}/../" ABSOLUTE CACHE PATH "Trusted Services root directory.")
+
+# Replicate TS_ROOT as environment variable to allow access from child CMake contexts
+set(ENV{TS_ROOT} "${TS_ROOT}")
+
+# Common utilities used by the build system
+include(${TS_ROOT}/tools/cmake/common/Utils.cmake REQUIRED)
+include(${TS_ROOT}/tools/cmake/common/AddComponents.cmake REQUIRED)
+
+# Check build environment requirements are met
+ts_verify_build_env()
+
+# Project wide include directories
+set(TOP_LEVEL_INCLUDE_DIRS
+  "${TS_ROOT}"
+  "${TS_ROOT}/components"
+  )
diff --git a/deployments/libsp/opteesp/CMakeLists.txt b/deployments/libsp/opteesp/CMakeLists.txt
new file mode 100644
index 0000000..00f10d5
--- /dev/null
+++ b/deployments/libsp/opteesp/CMakeLists.txt
@@ -0,0 +1,132 @@
+#-------------------------------------------------------------------------------
+# 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 libsp deployment for opteesp
+#
+#  Used for building the libsp library that provides FFA related functons
+#  for applications deployed in a secure partition.
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/opteesp/env.cmake)
+
+file(READ "${CMAKE_CURRENT_LIST_DIR}/version.txt" LIBSP_VERSION)
+project(trusted-services
+			VERSION
+				${LIBSP_VERSION}
+			 LANGUAGES
+				C ASM
+		)
+
+add_library(sp STATIC)
+
+# Include SP DEV KIT interface
+set(SP_DEV_KIT_INC_DIR ${CMAKE_CURRENT_LIST_DIR})
+list(APPEND CMAKE_MODULE_PATH "${TS_ROOT}/external/Spdevkit")
+find_package(Spdevkit COMPONENTS interface)
+
+target_link_libraries(sp PUBLIC ${SP_DEV_KIT_LIBRARIES})
+
+
+add_components(TARGET "sp"
+	BASE_DIR ${TS_ROOT}
+	COMPONENTS
+		components/messaging/ffa/libsp
+		components/common/utils
+)
+
+target_compile_definitions("sp" PRIVATE
+	ARM64=1
+)
+
+if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+	target_compile_options("sp" PRIVATE
+		-fdiagnostics-show-option
+		-fpic
+		-gdwarf-2
+		-mstrict-align
+		-O0
+		-std=gnu99
+	)
+endif()
+
+######################################## install
+if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+	set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE)
+endif()
+
+install(
+	TARGETS
+		sp
+	EXPORT
+		LibspTargets
+	ARCHIVE	DESTINATION
+		lib
+	PUBLIC_HEADER DESTINATION
+		include
+	COMPONENT
+		libsp
+)
+
+#These would install the spdevkit content.
+#install(FILES $<TARGET_PROPERTY:sp_devkit_ifc,INTERFACE_LINK_LIBRARIES> DESTINATION lib)
+#install(FILES $<TARGET_PROPERTY:sp_devkit_ifc,INTERFACE_INCLUDE_DIRECTORIES>/ DESTINATION include)
+### Create a config file package.
+set(ConfigPackageLocation lib/cmake/libsp)
+
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file(
+	"${CMAKE_CURRENT_BINARY_DIR}/LibspConfigVersion.cmake"
+	VERSION "1.0.0"
+	COMPATIBILITY SameMajorVersion
+)
+
+# Create targets file.
+export(
+	EXPORT
+		LibspTargets
+	FILE
+		"${CMAKE_CURRENT_BINARY_DIR}/LibspTargets.cmake"
+	NAMESPACE
+		libsp::
+)
+
+# Finalize config file.
+configure_package_config_file(
+		LibspConfig.cmake.in
+		"${CMAKE_CURRENT_BINARY_DIR}/LibspConfig.cmake"
+	PATH_VARS
+
+	INSTALL_DESTINATION
+		${ConfigPackageLocation}
+)
+
+install(
+	EXPORT
+		LibspTargets
+	FILE
+		LibspTargets.cmake
+	NAMESPACE
+		libsp::
+	DESTINATION
+		${ConfigPackageLocation}
+	COMPONENT
+		libsp
+)
+
+# install config and version files
+install(
+	FILES
+		"${CMAKE_CURRENT_BINARY_DIR}/LibspConfig.cmake"
+		"${CMAKE_CURRENT_BINARY_DIR}/LibspConfigVersion.cmake"
+		"${TS_ROOT}/external/Spdevkit/FindSpdevkit.cmake"
+	DESTINATION
+		${ConfigPackageLocation}
+	COMPONENT
+		libsp
+)
diff --git a/deployments/libsp/opteesp/LibspConfig.cmake.in b/deployments/libsp/opteesp/LibspConfig.cmake.in
new file mode 100644
index 0000000..cd8d0d6
--- /dev/null
+++ b/deployments/libsp/opteesp/LibspConfig.cmake.in
@@ -0,0 +1,16 @@
+#
+# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+@PACKAGE_INIT@
+
+# Any user of the lib will depend on spdevkit. Use our find module to get access to it.
+find_package(Spdevkit
+	 COMPONENTS LIBUTIL
+	 PATHS ${CMAKE_CURRENT_LIST_DIR}
+	 NO_DEFAULT_PATH
+	 REQUIRED)
+
+include("${CMAKE_CURRENT_LIST_DIR}/LibspTargets.cmake")
diff --git a/deployments/libsp/opteesp/version.txt b/deployments/libsp/opteesp/version.txt
new file mode 100644
index 0000000..afaf360
--- /dev/null
+++ b/deployments/libsp/opteesp/version.txt
@@ -0,0 +1 @@
+1.0.0
\ No newline at end of file