Fix: incorrect platform path lowercase conversion

TS has a naming convention which requires directory names being
lowercase. AddPlatform.cmake::add_platform() enforces this and converts
the path constructed from TS_PLATFORM variable to lower case. This was
done incorrectly as TS_ROOT was converted to. This made it impossible to
build TS from any location which had capital letters in any directory
name above TS_ROOT.
This change fixes the conversion and limits the effect to paths under
TS_ROOT.

Signed-off-by: Vishnu Banavath <vishnu.banavath@arm.com>
Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
Signed-off-by: György Szing <gyorgy.szing@arm.com>
Change-Id: Icf14b6a78d01878e7a4c9b53f3ec429944e16225
diff --git a/tools/cmake/common/AddPlatform.cmake b/tools/cmake/common/AddPlatform.cmake
index ae34c6e..37efdf2 100644
--- a/tools/cmake/common/AddPlatform.cmake
+++ b/tools/cmake/common/AddPlatform.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -24,6 +24,10 @@
 	``TARGET``
 	The name of an already defined target to add platform components to.
 
+	``TS_PLATFORM``
+	This global variable is used to construct a path to the platform specific cmake file.
+	:variable:TS_PLATFORM can be set from the command line and the value must be lower case.
+
 #]===]
 function(add_platform)
 	set(options  )
@@ -34,12 +38,12 @@
 		message(FATAL_ERROR "add_platform: mandatory parameter TARGET not defined!")
 	endif()
 
-	set(TGT ${MY_PARAMS_TARGET} CACHE STRING "")
-
 	# Ensure file path conforms to lowercase project convention
-	string(TOLOWER "${TS_PLATFORM_ROOT}/${TS_PLATFORM}/platform.cmake" _platdef)
-	include(${_platdef})
-	set(CMAKE_CONFIGURE_DEPENDS ${_platdef})
-
-	unset(TGT CACHE)
+	string(TOLOWER "${TS_PLATFORM}" _tmp)
+	if (NOT "${TS_PLATFORM}" STREQUAL "${_tmp}")
+			message(FATAL_ERROR "Value of TS_PLATFORM may only use lowercase letters. The current value"
+								" \"${TS_PLATFORM}\" violates this.")
+	endif()
+	set(TGT ${MY_PARAMS_TARGET})
+	include(${TS_PLATFORM_ROOT}/${TS_PLATFORM}/platform.cmake)
 endfunction()