Fix: deployments fail to install to a single tree

File names of same deployment built for different environments collide
which results in overwrites.
This patch makes the install locations environment specific to avoid
this issue. This also makes the install tree less confusing.

Change-Id: I05e45f7cdc5d05b4a695334ba66a29aadac2f08e
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
diff --git a/deployments/component-test/component-test.cmake b/deployments/component-test/component-test.cmake
index 1dc0152..831e6ec 100644
--- a/deployments/component-test/component-test.cmake
+++ b/deployments/component-test/component-test.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -79,4 +79,4 @@
 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 component-test DESTINATION bin)
\ No newline at end of file
+install(TARGETS component-test DESTINATION ${TS_ENV}/bin)
diff --git a/deployments/crypto/opteesp/CMakeLists.txt b/deployments/crypto/opteesp/CMakeLists.txt
index 2631c00..fec7b69 100644
--- a/deployments/crypto/opteesp/CMakeLists.txt
+++ b/deployments/crypto/opteesp/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -112,14 +112,15 @@
 	set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE)
 endif()
 #TODO: api headers
+
 install(TARGETS crypto-sp
-			PUBLIC_HEADER DESTINATION include
-			RUNTIME DESTINATION bin
+			PUBLIC_HEADER DESTINATION ${TS_ENV}/include
+			RUNTIME DESTINATION ${TS_ENV}/bin
 		)
-install(FILES ${STRIPPED_ELF} DESTINATION bin)
+install(FILES ${STRIPPED_ELF} DESTINATION ${TS_ENV}/bin)
 
 get_property(_PROTO_FILES TARGET crypto-sp PROPERTY PROTOBUF_FILES)
-install(FILES ${_PROTO_FILES} DESTINATION lib/protobuf)
+install(FILES ${_PROTO_FILES} DESTINATION ${TS_ENV}/lib/protobuf)
 
 
 set(EXPORT_SP_NAME "crypto")
diff --git a/deployments/libsp/opteesp/CMakeLists.txt b/deployments/libsp/opteesp/CMakeLists.txt
index 00f10d5..f65713b 100644
--- a/deployments/libsp/opteesp/CMakeLists.txt
+++ b/deployments/libsp/opteesp/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -66,9 +66,9 @@
 	EXPORT
 		LibspTargets
 	ARCHIVE	DESTINATION
-		lib
+		${TS_ENV}/lib
 	PUBLIC_HEADER DESTINATION
-		include
+		${TS_ENV}/include
 	COMPONENT
 		libsp
 )
@@ -77,7 +77,7 @@
 #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)
+set(ConfigPackageLocation ${TS_ENV}/lib/cmake/libsp)
 
 include(CMakePackageConfigHelpers)
 write_basic_package_version_file(
diff --git a/deployments/libts/libts-import.cmake b/deployments/libts/libts-import.cmake
index 8b58ec9..42bc3aa 100644
--- a/deployments/libts/libts-import.cmake
+++ b/deployments/libts/libts-import.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -43,7 +43,7 @@
 endif()
 
 # Import the built library
-include(${LIBTS_INSTALL_PATH}/lib/cmake/libts_targets.cmake)
+include(${LIBTS_INSTALL_PATH}/${TS_ENV}/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}")
+set_property(TARGET libts PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${LIBTS_INSTALL_PATH}/${TS_ENV}/include")
+set_property(TARGET libts PROPERTY IMPORTED_LOCATION "${LIBTS_INSTALL_PATH}/${TS_ENV}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}ts${CMAKE_SHARED_LIBRARY_SUFFIX}")
diff --git a/deployments/secure-storage/opteesp/CMakeLists.txt b/deployments/secure-storage/opteesp/CMakeLists.txt
index 6394bfe..dc1aabf 100644
--- a/deployments/secure-storage/opteesp/CMakeLists.txt
+++ b/deployments/secure-storage/opteesp/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -90,10 +90,10 @@
 	set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE)
 endif()
 install(TARGETS secure-storage
-			PUBLIC_HEADER DESTINATION include
-			RUNTIME DESTINATION bin
+			PUBLIC_HEADER DESTINATION ${TS_ENV}/include
+			RUNTIME DESTINATION ${TS_ENV}/bin
 		)
-install(FILES ${STRIPPED_ELF} DESTINATION bin)
+install(FILES ${STRIPPED_ELF} DESTINATION ${TS_ENV}/bin)
 
 set(EXPORT_SP_NAME "secure-storage")
 set(EXPORT_SP_UUID ${SP_UUID})
diff --git a/deployments/sfs-demo/opteesp/CMakeLists.txt b/deployments/sfs-demo/opteesp/CMakeLists.txt
index d3a7d15..9f4dbae 100644
--- a/deployments/sfs-demo/opteesp/CMakeLists.txt
+++ b/deployments/sfs-demo/opteesp/CMakeLists.txt
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -88,5 +88,5 @@
 	set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE)
 endif()
 #TODO: API header, protobuf files?
-install(TARGETS sfs-demo DESTINATION bin)
-install(FILES ${STRIPPED_ELF} DESTINATION bin)
+install(TARGETS sfs-demo DESTINATION ${TS_ENV}/bin)
+install(FILES ${STRIPPED_ELF} DESTINATION ${TS_ENV}/bin)
diff --git a/deployments/ts-demo/ts-demo.cmake b/deployments/ts-demo/ts-demo.cmake
index 4c85a40..d6f1067 100644
--- a/deployments/ts-demo/ts-demo.cmake
+++ b/deployments/ts-demo/ts-demo.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -62,4 +62,4 @@
 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 ts-demo RUNTIME DESTINATION bin)
\ No newline at end of file
+install(TARGETS ts-demo RUNTIME DESTINATION ${TS_ENV}/bin)
diff --git a/deployments/ts-service-test/ts-service-test.cmake b/deployments/ts-service-test/ts-service-test.cmake
index 1593188..80bf6fd 100644
--- a/deployments/ts-service-test/ts-service-test.cmake
+++ b/deployments/ts-service-test/ts-service-test.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -59,4 +59,4 @@
 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 ts-service-test RUNTIME DESTINATION bin)
\ No newline at end of file
+install(TARGETS ts-service-test RUNTIME DESTINATION ${TS_ENV}/bin)
diff --git a/environments/opteesp/ExportSp.cmake b/environments/opteesp/ExportSp.cmake
index 3040bd0..b71a657 100644
--- a/environments/opteesp/ExportSp.cmake
+++ b/environments/opteesp/ExportSp.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -14,7 +14,7 @@
 endforeach()
 
 configure_file(${CMAKE_CURRENT_LIST_DIR}/sp.mk.in ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.mk @ONLY NEWLINE_STYLE UNIX)
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.mk DESTINATION lib/make)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_SP_NAME}.mk DESTINATION ${TS_ENV}/lib/make)
 
 unset(EXPORT_SP_NAME)
 unset(EXPORT_SP_UUID)
diff --git a/tools/cmake/common/ExportLibrary.cmake b/tools/cmake/common/ExportLibrary.cmake
index 670f318..fed4e75 100644
--- a/tools/cmake/common/ExportLibrary.cmake
+++ b/tools/cmake/common/ExportLibrary.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -48,17 +48,17 @@
 		TARGETS ${MY_PARAMS_TARGET}
 		EXPORT ${MY_PARAMS_LIB_NAME}_targets
 		ARCHIVE
-			DESTINATION lib
+			DESTINATION ${TS_ENV}/lib
 		LIBRARY
-			DESTINATION lib
+			DESTINATION ${TS_ENV}/lib
 		PUBLIC_HEADER
-			DESTINATION include
+			DESTINATION ${TS_ENV}/include
 	)
 
 	# Install library header files files
 	install(
 		FILES ${MY_PARAMS_INTERFACE_FILES}
-		DESTINATION include
+		DESTINATION ${TS_ENV}/include
 	)
 
 	# Install the export details
@@ -66,7 +66,7 @@
 		EXPORT ${MY_PARAMS_LIB_NAME}_targets
 		FILE ${MY_PARAMS_LIB_NAME}_targets.cmake
 		NAMESPACE ${MY_PARAMS_LIB_NAME}::
-		DESTINATION lib/cmake
+		DESTINATION ${TS_ENV}/lib/cmake
 		COMPONENT ${MY_PARAMS_LIB_NAME}
 	)
 endfunction()