build: Use backup variable when modifying C/CXX flag

Some components like CppUTest and MbedTLS need different
CXX and C Flags and this patch ensures that when these flags are
modified, the global settings are not changed. This is done
by using a backup variable when the flags are modified and
restoring them afterwards.

Signed-off-by: Soby Mathew <soby.mathew@arm.com>
Change-Id: Ic7f7eec104e2d43ee1bd2ea1f56c08758f93b494
diff --git a/cmake/BuildCppUTest.cmake b/cmake/BuildCppUTest.cmake
index df87e3c..5333b7e 100644
--- a/cmake/BuildCppUTest.cmake
+++ b/cmake/BuildCppUTest.cmake
@@ -5,9 +5,10 @@
 
 #
 # Remove Werror from CXXFLAGS else CppUTest compiler checks will fail.
-# This will affect CMAKE_CXX_FLAG in the current scope and parent scope
-# is unaffected.
+# Ensure that CMAKE_CXX_FLAG is changed only for the current scope and
+# parent scope is unaffected.
 #
+set(BACKUP_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
 string(REPLACE "-Werror" " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
 
 # Additional CXXFLAGS to get CppUTest to compile.
@@ -15,3 +16,5 @@
 
 add_subdirectory("ext/cpputest")
 
+# Restore the original CXX flags.
+set(CMAKE_CXX_FLAGS "${BACKUP_CXX_FLAGS}")