Build: Adjust configuration order

Reorder the configuration steps, to provide more intuitive
configuration. Invert the current order, and remove the use of FORCE to
create a configuration additively instead of using overriding. Allows
cmake command-line variables to override all other options as is
expected.

Change-Id: I64730b7db230cdaf2f86f1d27d882dc9111607be
Signed-off-by: Tamas Ban <tamas.ban@arm.com>
Signed-off-by: Raef Coles <raef.coles@arm.com>
diff --git a/config/set_config.cmake b/config/set_config.cmake
index 82ebe41..3a67162 100644
--- a/config/set_config.cmake
+++ b/config/set_config.cmake
@@ -9,42 +9,43 @@
 # docs/getting_started/tfm_build_instructions.rst under Cmake Configuration. If
 # the sequence is updated here the docs must also be updated.
 
-# First load defaults.
-include(${CMAKE_SOURCE_DIR}/config/config_default.cmake)
+# Load extra config
+if (TFM_EXTRA_CONFIG_PATH)
+    include(${TFM_EXTRA_CONFIG_PATH})
+endif()
 
-# Then load the build type config, overriding defaults and command line.
+# Load PSA config, setting options not already set
+if (TEST_PSA_API)
+    include(config/tests/config_test_psa_api.cmake)
+endif()
+
+# Load build type config, setting options not already set
 string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWERCASE)
 if (EXISTS ${CMAKE_SOURCE_DIR}/config/build_type/${CMAKE_BUILD_TYPE_LOWERCASE}.cmake)
     include(${CMAKE_SOURCE_DIR}/config/build_type/${CMAKE_BUILD_TYPE_LOWERCASE}.cmake)
 endif()
 
-# If configured for tests, load config specific to tests overriding defaults.
-if (TEST_PSA_API)
-    include(${CMAKE_SOURCE_DIR}/config/tests/config_test_psa_api.cmake)
+# Load platform config, setting options not already set
+if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/config.cmake)
+    include(platform/ext/target/${TFM_PLATFORM}/config.cmake)
 endif()
 
-# Then load the profile, overriding build type config, defaults and command
-# line.
+# Load accelerator config, setting options not already set
+if (CRYPTO_HW_ACCELERATOR)
+    if (EXISTS ${CMAKE_SOURCE_DIR}/platform/ext/accelerator/${CRYPTO_HW_ACCELERATOR_TYPE}/config.cmake)
+        include(${CMAKE_SOURCE_DIR}/platform/ext/accelerator/${CRYPTO_HW_ACCELERATOR_TYPE}/config.cmake)
+    endif()
+endif()
+
+# Load profile config, setting options not already set
 if (TFM_PROFILE)
-    include(${CMAKE_SOURCE_DIR}/config/profile/${TFM_PROFILE}.cmake)
+    include(config/profile/${TFM_PROFILE}.cmake)
 endif()
 
-# Then load the platform options, overriding profile, build type config,
-# defaults and command line.
-if (EXISTS ${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/config.cmake)
-    include(${CMAKE_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/config.cmake)
-endif()
+# Load defaults, setting options not already set
+include(config/config_default.cmake)
 
-# If CRYPTO_HW_ACCELERATOR is enabled by the platform, then load the
-# corresponding config if it exists
-if (CRYPTO_HW_ACCELERATOR AND EXISTS ${CMAKE_SOURCE_DIR}/platform/ext/accelerator/${CRYPTO_HW_ACCELERATOR_TYPE}/config.cmake)
-    include(${CMAKE_SOURCE_DIR}/platform/ext/accelerator/${CRYPTO_HW_ACCELERATOR_TYPE}/config.cmake)
-endif()
 
-# Optionally load extra config, overriding platform options, overriding profile,
-# build type config, defaults and command line.
-if (TFM_EXTRA_CONFIG_PATH)
-    include(${TFM_EXTRA_CONFIG_PATH})
-endif()
+############################ Sanity Check ######################################
 
 include(${CMAKE_SOURCE_DIR}/config/check_config.cmake)