Set CMAKE_INSTALL_PREFIX to TFM_INSTALL_PATH

The change allows CMAKE_INSTALL_PREFIX dependent installations
to use the same destination as TFM_INSTALL_PATH.

Change-Id: Ib3913316d474158bc0cbf2a8e4670b72db593c51
Signed-off-by: Raef Coles <raef.coles@arm.com>
Signed-off-by: Satish Kumar <satish.kumar01@arm.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 162db66..1aa8046 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -71,6 +71,15 @@
 project("Trusted Firmware M" VERSION ${TFM_VERSION} LANGUAGES C ASM)
 tfm_toolchain_reload_compiler()
 
+# Synchronise the install path variables. If CMAKE_INSTALL_PREFIX is manually
+# set then set both to the value of that, else set both to the value of
+# TFM_INSTALL_PATH. This has to be done after the call to `project()`.
+if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+    set(CMAKE_INSTALL_PREFIX  ${TFM_INSTALL_PATH} CACHE PATH  "" FORCE)
+else()
+    set(TFM_INSTALL_PATH  ${CMAKE_INSTALL_PREFIX} CACHE PATH  "Path to which to install TF-M files" FORCE)
+endif()
+
 ############################ Config Check ######################################
 
 include(${CMAKE_SOURCE_DIR}/config/check_config.cmake)