Build: Refactor toolchain files

Change from a CMAKE toolchain file to a TFM toolchain file, avoiding
some abuses of the CMAKE_TOOLCHAIN_FILE that were used as a workaround
for compiler setup. Also add the CROSS_COMPILE variable. Bump cmake
required version to 3.15.

Change-Id: I0948033045e2d2f34beffa807925fc7375098335
Signed-off-by: Raef Coles <raef.coles@arm.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fdd8446..5368f8e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,33 +5,9 @@
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 
-project("Trusted Firmware M" VERSION 1.1.0 LANGUAGES C ASM)
-set(TFM_VERSION ${PROJECT_VERSION})
-
-if(NOT TFM_CMAKE_TOOLCHAIN_FILE_LOADED)
-    Message(FATAL_ERROR "Cmake toolchain file not set.")
-endif()
-
-if(NOT ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles" AND
-   NOT ${CMAKE_GENERATOR} STREQUAL "Ninja")
-    Message(FATAL_ERROR "Unsupported generator ${CMAKE_GENERATOR}. Hint: Try -G\"Unix Makefiles\"")
-endif()
-
-# Some compiler flags depend on the CPU / platform config. This include should
-# be run before anything else so the compiler can be configured properly.
-if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload.cmake)
-    Message(FATAL_ERROR "Unsupported TFM_PLATFORM ${TFM_PLATFORM}")
-else()
-    include(platform/ext/target/${TFM_PLATFORM}/preload.cmake)
-endif()
-
-# The default build type is release. If debug symbols are needed then
-# -DCMAKE_BUILD_TYPE=debug should be used (likewise with other build types)
-if (NOT CMAKE_BUILD_TYPE)
-    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type: [Debug, Release, RelWithDebInfo, MinSizeRel]" FORCE)
-endif()
+set(TFM_VERSION 1.1.0)
 
 ############################ CONFIGURATION #####################################
 
@@ -77,6 +53,43 @@
 
 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
 
+if(NOT ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles" AND
+   NOT ${CMAKE_GENERATOR} STREQUAL "Ninja")
+    Message(FATAL_ERROR "Unsupported generator ${CMAKE_GENERATOR}. Hint: Try -G\"Unix Makefiles\"")
+endif()
+
+# The default build type is release. If debug symbols are needed then
+# -DCMAKE_BUILD_TYPE=debug should be used (likewise with other build types)
+if (NOT CMAKE_BUILD_TYPE)
+    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type: [Debug, Release, RelWithDebInfo, MinSizeRel]" FORCE)
+endif()
+
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
+
+############################### Compiler configuration #########################
+
+# Some compiler flags depend on the CPU / platform config. This include should
+# be run before the toolchain file so the compiler can be configured properly.
+if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/platform/ext/target/${TFM_PLATFORM}/preload.cmake)
+    Message(FATAL_ERROR "Unsupported TFM_PLATFORM ${TFM_PLATFORM}")
+else()
+    include(platform/ext/target/${TFM_PLATFORM}/preload.cmake)
+endif()
+
+#Legacy compat option - load CMAKE_TOOLCHAIN_FILE as a TFM_TOOLCHAIN_FILE
+if (CMAKE_TOOLCHAIN_FILE)
+    message(DEPRECATION "SETTING CMAKE_TOOLCHAIN_FILE is deprecated. It has been replaced with TFM_TOOLCHAIN_FILE.")
+    message(DEPRECATION "INTERPRETING -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} as -DTFM_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
+    set(TFM_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE})
+    unset(CMAKE_TOOLCHAIN_FILE)
+endif()
+
+include(${TFM_TOOLCHAIN_FILE})
+set(CMAKE_PROJECT_INCLUDE_BEFORE ${CMAKE_SOURCE_DIR}/cmake/disable_compiler_detection.cmake)
+
+project("Trusted Firmware M" VERSION ${TFM_VERSION} LANGUAGES C ASM)
+tfm_toolchain_reload_compiler()
+
 ################################################################################
 
 add_subdirectory(lib/ext)
diff --git a/bl2/CMakeLists.txt b/bl2/CMakeLists.txt
index 9d069c2..1496a19 100644
--- a/bl2/CMakeLists.txt
+++ b/bl2/CMakeLists.txt
@@ -5,7 +5,7 @@
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 
 project("Bootloader" VERSION 0.1.0 LANGUAGES C ASM)
 
diff --git a/bl2/ext/mcuboot/CMakeLists.txt b/bl2/ext/mcuboot/CMakeLists.txt
index 7b056e7..ef8afe8 100644
--- a/bl2/ext/mcuboot/CMakeLists.txt
+++ b/bl2/ext/mcuboot/CMakeLists.txt
@@ -5,7 +5,7 @@
 #
 #------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 cmake_policy(SET CMP0079 NEW)
 
 set(MCUBOOT_KEY_ENC "${MCUBOOT_PATH}/enc-rsa2048-pub.pem" CACHE FILEPATH "Path to key with which to encrypt binary")
diff --git a/cmake/disable_compiler_detection.cmake b/cmake/disable_compiler_detection.cmake
new file mode 100644
index 0000000..ebafca0
--- /dev/null
+++ b/cmake/disable_compiler_detection.cmake
@@ -0,0 +1,9 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#Stop cmake running compiler tests.
+set (CMAKE_C_COMPILER_FORCED true)
diff --git a/config/config_default.cmake b/config/config_default.cmake
index 017e36e..b795b43 100644
--- a/config/config_default.cmake
+++ b/config/config_default.cmake
@@ -5,6 +5,10 @@
 #
 #-------------------------------------------------------------------------------
 
+set(TFM_TOOLCHAIN_FILE                  ${CMAKE_SOURCE_DIR}/toolchain_GNUARM.cmake CACHE FILEPATH    "Path to TFM compiler toolchain file")
+set(TFM_PLATFORM                        ""          CACHE STRING    "Platform to build TF-M for")
+set(CROSS_COMPILE                       arm-none-eabi CACHE STRING  "Cross-compilation triplet")
+
 set(BL2                                 ON          CACHE BOOL      "Whether to build BL2")
 set(NS                                  ON          CACHE BOOL      "Whether to build NS app")
 
diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt
index f227c6e..85f63f0 100644
--- a/docs/CMakeLists.txt
+++ b/docs/CMakeLists.txt
@@ -5,7 +5,7 @@
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 
 add_custom_target(docs)
 
diff --git a/docs/design_documents/profiles/tfm_profile_medium.rst b/docs/design_documents/profiles/tfm_profile_medium.rst
index cb744d4..8413635 100644
--- a/docs/design_documents/profiles/tfm_profile_medium.rst
+++ b/docs/design_documents/profiles/tfm_profile_medium.rst
@@ -419,7 +419,7 @@
    cd <TFM root dir>
    mkdir build && cd build
    cmake -DTFM_PLATFORM=mps2/an521 \
-         -DCMAKE_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
+         -DTFM_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
          -DTFM_PROFILE=profile_medium \
          -DCMAKE_BUILD_TYPE=MinSizeRel \
          ../
@@ -433,7 +433,7 @@
    cd <TFM root dir>
    mkdir build && cd build
    cmake -DTFM_PLATFORM=mps2/an521 \
-         -DCMAKE_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
+         -DTFM_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
          -DTFM_PROFILE=profile_medium \
          -DCMAKE_BUILD_TYPE=MinSizeRel \
          -DTEST_S=ON -DTEST_NS=ON \
diff --git a/docs/design_documents/profiles/tfm_profile_small.rst b/docs/design_documents/profiles/tfm_profile_small.rst
index c500f50..abd49c8 100644
--- a/docs/design_documents/profiles/tfm_profile_small.rst
+++ b/docs/design_documents/profiles/tfm_profile_small.rst
@@ -583,7 +583,7 @@
    cd <TFM root dir>
    mkdir build && cd build
    cmake -DTFM_PLATFORM=mps2/an521 \
-         -DCMAKE_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
+         -DTFM_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
          -DTFM_PROFILE=profile_small \
          -DCMAKE_BUILD_TYPE=MinSizeRel \
          ../
@@ -597,7 +597,7 @@
    cd <TFM root dir>
    mkdir build && cd build
    cmake -DTFM_PLATFORM=mps2/an521 \
-         -DCMAKE_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
+         -DTFM_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
          -DTFM_PROFILE=profile_small \
          -DCMAKE_BUILD_TYPE=MinSizeRel \
          -DTEST_S=ON -DTEST_NS=ON \
diff --git a/docs/getting_started/tfm_build_instruction.rst b/docs/getting_started/tfm_build_instruction.rst
index a2d4ad4..7e92be1 100644
--- a/docs/getting_started/tfm_build_instruction.rst
+++ b/docs/getting_started/tfm_build_instruction.rst
@@ -10,8 +10,7 @@
 TF-M uses `cmake <https://cmake.org/overview/>`__ to provide an out-of-source
 build environment. The instructions are below.
 
-Cmake version ``3.13.0`` or higher is supported, but version ``3.15.0`` or
-higher is required for ARMclang support.
+Cmake version ``3.15.0`` or higher is required.
 
 Getting the source-code
 =======================
@@ -72,7 +71,7 @@
 | TFM_PLATFORM         | The target platform as a path from the base directory |
 |                      | ``/platform/ext/target``                              |
 +----------------------+-------------------------------------------------------+
-| CMAKE_TOOLCHAIN_FILE | The path to the toolchain file that corresponds to    |
+| TFM_TOOLCHAIN_FILE   | The path to the toolchain file that corresponds to    |
 |                      | the desired compiler.                                 |
 +----------------------+-------------------------------------------------------+
 
@@ -260,7 +259,7 @@
 
     cd <base folder>
     cd trusted-firmware-m
-    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=toolchain_GNUARM.cmake
+    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake
     cmake --build cmake_build -- install
 
 Alternately using traditional cmake syntax
@@ -271,7 +270,7 @@
     cd trusted-firmware-m
     mkdir cmake_build
     cd cmake_build
-    cmake .. -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake
+    cmake .. -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake
     make install
 
 .. Note::
@@ -295,7 +294,7 @@
 
     cd <base folder>
     cd trusted-firmware-m
-    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DTEST_S=ON -DTEST_NS=ON
+    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DTEST_S=ON -DTEST_NS=ON
     cmake --build cmake_build -- install
 
 Alternately using traditional cmake syntax
@@ -306,7 +305,7 @@
     cd trusted-firmware-m
     mkdir cmake_build
     cd cmake_build
-    cmake .. -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DTEST_S=ON -DTEST_NS=ON
+    cmake .. -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DTEST_S=ON -DTEST_NS=ON
     make install
 
 Build for PSA Functional API compliance tests
@@ -333,7 +332,7 @@
 
     cd <base folder>
     cd trusted-firmware-m
-    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DTEST_PSA_API=CRYPTO
+    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DTEST_PSA_API=CRYPTO
     cmake --build cmake_build -- install
 
 Alternately using traditional cmake syntax
@@ -344,7 +343,7 @@
     cd trusted-firmware-m
     mkdir cmake_build
     cd cmake_build
-    cmake .. -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DTEST_PSA_API=CRYPTO
+    cmake .. -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DTEST_PSA_API=CRYPTO
     make install
 
 Build for PSA FF (IPC) compliance tests
@@ -361,7 +360,7 @@
 
     cd <base folder>
     cd trusted-firmware-m
-    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DTEST_PSA_API=IPC -DTFM_PSA_API=ON
+    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DTEST_PSA_API=IPC -DTFM_PSA_API=ON
     cmake --build cmake_build -- install
 
 Alternately using traditional cmake syntax
@@ -372,7 +371,7 @@
     cd trusted-firmware-m
     mkdir cmake_build
     cd cmake_build
-    cmake .. -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DTEST_PSA_API=IPC -DTFM_PSA_API=ON
+    cmake .. -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DTEST_PSA_API=IPC -DTFM_PSA_API=ON
     make install
 
 Location of build artifacts
@@ -413,7 +412,7 @@
 .. code-block:: bash
 
     cd <TF-M base folder>
-    cmake -S . -B cmake_doc -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=toolchain_GNUARM.cmake
+    cmake -S . -B cmake_doc -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake
     cmake --build cmake_doc -- tfm_docs_refman_html tfm_docs_refman_pdf
 
 The documentation files will be available under the directory::
@@ -425,7 +424,7 @@
 .. code-block:: bash
 
     cd <TF-M base folder>
-    cmake -S . -B cmake_doc -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=toolchain_GNUARM.cmake
+    cmake -S . -B cmake_doc -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake
     cmake --build cmake_doc -- tfm_docs_userguide_html tfm_docs_userguide_pdf
 
 The documentation files will be available under the directory::
@@ -524,7 +523,7 @@
 
     cd <base folder>
     cd trusted-firmware-m
-    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
+    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_GNUARM.cmake -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
     cmake --build cmake_build -- install
 
 Alternately using traditional cmake syntax
@@ -535,7 +534,7 @@
     cd trusted-firmware-m
     mkdir cmake_build
     cd cmake_build
-    cmake .. -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
+    cmake .. -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DMBEDCRYPTO_PATH=<Mbed Crypto base folder>/mbedtls
     make install
 
 --------------
diff --git a/docs/getting_started/tfm_build_instruction_iar.rst b/docs/getting_started/tfm_build_instruction_iar.rst
index 8df576f..8a6e007 100644
--- a/docs/getting_started/tfm_build_instruction_iar.rst
+++ b/docs/getting_started/tfm_build_instruction_iar.rst
@@ -3,7 +3,7 @@
 ###################################################
 
 Follow the instructions in
-:doc:`software requirements <tfm_build_instruction>`, but replace the -DCMAKE_TOOLCHAIN_FILE setting with toolchain_IARARM.cmake.
+:doc:`software requirements <tfm_build_instruction>`, but replace the -DTFM_TOOLCHAIN_FILE setting with toolchain_IARARM.cmake.
 
 
 Notes for building with IARARM
@@ -29,7 +29,7 @@
 
     cd <base folder>
     cd trusted-firmware-m
-    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=toolchain_IARARM.cmake
+    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_IARARM.cmake
     cmake --build cmake_build -- install
 
 Alternately using traditional cmake syntax
@@ -40,7 +40,7 @@
     cd trusted-firmware-m
     mkdir cmake_build
     cd cmake_build
-    cmake .. -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=../toolchain_IARARM.cmake
+    cmake .. -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_IARARM.cmake
     make install
 
 Regression Tests for the AN521 target platform
@@ -50,7 +50,7 @@
 
     cd <base folder>
     cd trusted-firmware-m
-    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=toolchain_IARARM.cmake -DTEST_S=ON -DTEST_NS=ON
+    cmake -S . -B cmake_build -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=toolchain_IARARM.cmake -DTEST_S=ON -DTEST_NS=ON
     cmake --build cmake_build -- install
 
 Alternately using traditional cmake syntax
@@ -61,7 +61,7 @@
     cd trusted-firmware-m
     mkdir cmake_build
     cd cmake_build
-    cmake .. -DTFM_PLATFORM=mps2/an521 -DCMAKE_TOOLCHAIN_FILE=../toolchain_IARARM.cmake -DTEST_S=ON -DTEST_NS=ON
+    cmake .. -DTFM_PLATFORM=mps2/an521 -DTFM_TOOLCHAIN_FILE=../toolchain_IARARM.cmake -DTEST_S=ON -DTEST_NS=ON
     make install
 
  *Copyright (c) 2020, Arm Limited. All rights reserved.*
diff --git a/docs/getting_started/tfm_secure_boot.rst b/docs/getting_started/tfm_secure_boot.rst
index f9f4599..61be329 100644
--- a/docs/getting_started/tfm_secure_boot.rst
+++ b/docs/getting_started/tfm_secure_boot.rst
@@ -309,7 +309,7 @@
 
 Example of how to provide the secure image minimum version::
 
-    cmake -DTFM_PLATFORM=musca_b1 -DCMAKE_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DMCUBOOT_S_IMAGE_MIN_VER=1.2.3+4 ..
+    cmake -DTFM_PLATFORM=musca_b1 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DMCUBOOT_S_IMAGE_MIN_VER=1.2.3+4 ..
 
 ********************
 Signature algorithms
@@ -428,7 +428,7 @@
 The version number of the image (single image boot) can manually be passed in
 through the command line in the cmake configuration step::
 
-    cmake -DTFM_PLATFORM=musca_b1 -DCMAKE_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DIMAGE_VERSION_S=1.2.3+4 ..
+    cmake -DTFM_PLATFORM=musca_b1 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DIMAGE_VERSION_S=1.2.3+4 ..
 
 Alternatively, the version number can be less specific (e.g 1, 1.2, or 1.2.3),
 where the missing numbers are automatically set to zero. The image version
@@ -462,7 +462,7 @@
 current image version. The value of the security counter (single image boot) can
 be specified at build time in the cmake configuration step::
 
-    cmake -DTFM_PLATFORM=musca_b1 -DCMAKE_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DSECURITY_COUNTER_S=42 ../
+    cmake -DTFM_PLATFORM=musca_b1 -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DSECURITY_COUNTER_S=42 ../
 
 The security counter can be independent from the image version, but not
 necessarily. Alternatively, if it is not specified at build time with the
diff --git a/docs/getting_started/tfm_sw_requirement.rst b/docs/getting_started/tfm_sw_requirement.rst
index 24d42aa..9e83d23 100644
--- a/docs/getting_started/tfm_sw_requirement.rst
+++ b/docs/getting_started/tfm_sw_requirement.rst
@@ -81,12 +81,7 @@
 
 The build-system is CMake based and supports the following versions:
 
-    - 3.13
-    - 3.14
-    - 3.15
-    - 3.16
-    - 3.17
-    - 3.18
+The build-system is CMake based and supports the versions 3.15 or higher.
 
 .. Note::
     - IAR requires version 3.14 or later.
diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt
index 00e0fbb..1ddcb94 100644
--- a/interface/CMakeLists.txt
+++ b/interface/CMakeLists.txt
@@ -5,7 +5,7 @@
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 cmake_policy(SET CMP0076 NEW)
 cmake_policy(SET CMP0079 NEW)
 
diff --git a/lib/ext/cryptocell-312-runtime/CMakeLists.txt b/lib/ext/cryptocell-312-runtime/CMakeLists.txt
index 46f6c84..18f1c70 100644
--- a/lib/ext/cryptocell-312-runtime/CMakeLists.txt
+++ b/lib/ext/cryptocell-312-runtime/CMakeLists.txt
@@ -5,7 +5,7 @@
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 
 project("CC312 Runtime Library" LANGUAGES C ASM)
 
diff --git a/lib/ext/qcbor/CMakeLists.txt b/lib/ext/qcbor/CMakeLists.txt
index 106406e..d0c92fd 100644
--- a/lib/ext/qcbor/CMakeLists.txt
+++ b/lib/ext/qcbor/CMakeLists.txt
@@ -5,7 +5,7 @@
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 
 add_library(tfm_qcbor STATIC)
 
diff --git a/lib/ext/t_cose/CMakeLists.txt b/lib/ext/t_cose/CMakeLists.txt
index 68f2658..d06fc76 100644
--- a/lib/ext/t_cose/CMakeLists.txt
+++ b/lib/ext/t_cose/CMakeLists.txt
@@ -5,7 +5,7 @@
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 
 add_library(tfm_t_cose STATIC)
 
diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt
index 04b6e1f..f73bd9d 100755
--- a/platform/CMakeLists.txt
+++ b/platform/CMakeLists.txt
@@ -4,7 +4,7 @@
 # SPDX-License-Identifier: BSD-3-Clause
 #
 #-------------------------------------------------------------------------------
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 cmake_policy(SET CMP0076 NEW)
 cmake_policy(SET CMP0079 NEW)
 
diff --git a/platform/ext/target/cypress/psoc64/cypress_psoc64_spec.rst b/platform/ext/target/cypress/psoc64/cypress_psoc64_spec.rst
index 0e6e9ea..0ae2dd9 100644
--- a/platform/ext/target/cypress/psoc64/cypress_psoc64_spec.rst
+++ b/platform/ext/target/cypress/psoc64/cypress_psoc64_spec.rst
@@ -50,7 +50,7 @@
    * - -DTFM_PLATFORM=cypress/psoc64
      - Specifies target platform name ``psoc64``
 
-   * - -DCMAKE_TOOLCHAIN_FILE=<path to toolchain file>
+   * - -DTFM_TOOLCHAIN_FILE=<path to toolchain file>
      - Specifies the compiler toolchain
        The possible values are:
 
@@ -77,7 +77,7 @@
     mkdir <build folder>
     pushd <build folder>
     cmake -DTFM_PLATFORM=cypress/psoc64 \
-          -DCMAKE_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
+          -DTFM_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
           ../
     popd
     cmake --build <build folder> -- -j VERBOSE=1
@@ -95,7 +95,7 @@
     mkdir <build folder>
     pushd <build folder>
     cmake -DTFM_PLATFORM=cypress/psoc64 \
-          -DCMAKE_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
+          -DTFM_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
           -DTEST_S=ON -DTEST_NS=ON \
           ../
     popd
@@ -114,7 +114,7 @@
     mkdir <build folder>
     pushd <build folder>
     cmake -DTFM_PLATFORM=cypress/psoc64 \
-          -DCMAKE_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
+          -DTFM_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
           -DTEST_PSA_API=INITIAL_ATTESTATION \
           ../
     popd
@@ -133,7 +133,7 @@
     mkdir <build folder>
     pushd <build folder>
     cmake -DTFM_PLATFORM=cypress/psoc64 \
-          -DCMAKE_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
+          -DTFM_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
           -DTFM_ISOLATION_LEVEL=2 \
           ../
     popd
@@ -152,7 +152,7 @@
     mkdir <build folder>
     pushd <build folder>
     cmake -DTFM_PLATFORM=cypress/psoc64 \
-          -DCMAKE_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
+          -DTFM_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
           -DTFM_ISOLATION_LEVEL=2 \
           -DTEST_S=ON -DTEST_NS=ON \
           ../
@@ -172,7 +172,7 @@
     mkdir <build folder>
     pushd <build folder>
     cmake -DTFM_PLATFORM=cypress/psoc64 \
-          -DCMAKE_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
+          -DTFM_TOOLCHAIN_FILE=../toolchain_ARMCLANG.cmake \
           -DTFM_ISOLATION_LEVEL=2 \
           -DTEST_PSA_API=PROTECTED_STORAGE \
           ../
diff --git a/platform/ext/target/cypress/psoc64/preload.cmake b/platform/ext/target/cypress/psoc64/preload.cmake
index 2661a22..90198cb 100644
--- a/platform/ext/target/cypress/psoc64/preload.cmake
+++ b/platform/ext/target/cypress/psoc64/preload.cmake
@@ -15,6 +15,3 @@
 set(TFM_SYSTEM_ARCHITECTURE armv6-m)
 
 add_definitions(-DCYB0644ABZI_S2D44)
-
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
diff --git a/platform/ext/target/cypress/psoc64/preload_ns.cmake b/platform/ext/target/cypress/psoc64/preload_ns.cmake
index 4e8f2b6..69f82c3 100644
--- a/platform/ext/target/cypress/psoc64/preload_ns.cmake
+++ b/platform/ext/target/cypress/psoc64/preload_ns.cmake
@@ -15,6 +15,3 @@
 set(TFM_SYSTEM_ARCHITECTURE armv7-m)
 
 add_definitions(-DCYB0644ABZI_S2D44)
-
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
diff --git a/platform/ext/target/mps2/an519/preload.cmake b/platform/ext/target/mps2/an519/preload.cmake
index 0cc3ca9..31d5c74 100644
--- a/platform/ext/target/mps2/an519/preload.cmake
+++ b/platform/ext/target/mps2/an519/preload.cmake
@@ -13,6 +13,3 @@
 # Set architecture and CPU
 set(TFM_SYSTEM_PROCESSOR cortex-m23)
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.base)
-
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
diff --git a/platform/ext/target/mps2/an521/preload.cmake b/platform/ext/target/mps2/an521/preload.cmake
index db0a473..436fed7 100644
--- a/platform/ext/target/mps2/an521/preload.cmake
+++ b/platform/ext/target/mps2/an521/preload.cmake
@@ -14,6 +14,3 @@
 set(TFM_SYSTEM_PROCESSOR cortex-m33)
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.main)
 set(TFM_SYSTEM_DSP OFF)
-
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
diff --git a/platform/ext/target/mps2/an539/preload.cmake b/platform/ext/target/mps2/an539/preload.cmake
index 0cc3ca9..31d5c74 100644
--- a/platform/ext/target/mps2/an539/preload.cmake
+++ b/platform/ext/target/mps2/an539/preload.cmake
@@ -13,6 +13,3 @@
 # Set architecture and CPU
 set(TFM_SYSTEM_PROCESSOR cortex-m23)
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.base)
-
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
diff --git a/platform/ext/target/mps2/fvp_sse300/preload.cmake b/platform/ext/target/mps2/fvp_sse300/preload.cmake
index c739c25..531e6e4 100644
--- a/platform/ext/target/mps2/fvp_sse300/preload.cmake
+++ b/platform/ext/target/mps2/fvp_sse300/preload.cmake
@@ -14,6 +14,3 @@
 set(TFM_SYSTEM_PROCESSOR cortex-m55)
 set(TFM_SYSTEM_ARCHITECTURE armv8.1-m.main)
 set(TFM_SYSTEM_DSP OFF)
-
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
diff --git a/platform/ext/target/mps2/sse-200_aws/preload.cmake b/platform/ext/target/mps2/sse-200_aws/preload.cmake
index 7565958..641e6f1 100644
--- a/platform/ext/target/mps2/sse-200_aws/preload.cmake
+++ b/platform/ext/target/mps2/sse-200_aws/preload.cmake
@@ -13,6 +13,3 @@
 # Set architecture and CPU
 set(TFM_SYSTEM_PROCESSOR cortex-m33)
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.main)
-
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
diff --git a/platform/ext/target/mps3/an524/preload.cmake b/platform/ext/target/mps3/an524/preload.cmake
index db0a473..436fed7 100644
--- a/platform/ext/target/mps3/an524/preload.cmake
+++ b/platform/ext/target/mps3/an524/preload.cmake
@@ -14,6 +14,3 @@
 set(TFM_SYSTEM_PROCESSOR cortex-m33)
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.main)
 set(TFM_SYSTEM_DSP OFF)
-
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
diff --git a/platform/ext/target/musca_a/preload.cmake b/platform/ext/target/musca_a/preload.cmake
index db0a473..436fed7 100644
--- a/platform/ext/target/musca_a/preload.cmake
+++ b/platform/ext/target/musca_a/preload.cmake
@@ -14,6 +14,3 @@
 set(TFM_SYSTEM_PROCESSOR cortex-m33)
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.main)
 set(TFM_SYSTEM_DSP OFF)
-
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
diff --git a/platform/ext/target/musca_b1/preload.cmake b/platform/ext/target/musca_b1/preload.cmake
index 9e21945..0eb0c46 100644
--- a/platform/ext/target/musca_b1/preload.cmake
+++ b/platform/ext/target/musca_b1/preload.cmake
@@ -14,8 +14,6 @@
 set(TFM_SYSTEM_PROCESSOR cortex-m33)
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.main)
 
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
 
 # The MUSCA_S1 has a CryptoCell-312 as an accelerator.
 set(CRYPTO_HW_ACCELERATOR_TYPE cc312)
diff --git a/platform/ext/target/musca_s1/preload.cmake b/platform/ext/target/musca_s1/preload.cmake
index 9e21945..0eb0c46 100644
--- a/platform/ext/target/musca_s1/preload.cmake
+++ b/platform/ext/target/musca_s1/preload.cmake
@@ -14,8 +14,6 @@
 set(TFM_SYSTEM_PROCESSOR cortex-m33)
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.main)
 
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
 
 # The MUSCA_S1 has a CryptoCell-312 as an accelerator.
 set(CRYPTO_HW_ACCELERATOR_TYPE cc312)
diff --git a/platform/ext/target/nordic_nrf/common/nrf5340/preload.cmake b/platform/ext/target/nordic_nrf/common/nrf5340/preload.cmake
index 6294961..3622515 100644
--- a/platform/ext/target/nordic_nrf/common/nrf5340/preload.cmake
+++ b/platform/ext/target/nordic_nrf/common/nrf5340/preload.cmake
@@ -1,5 +1,6 @@
 #-------------------------------------------------------------------------------
 # Copyright (c) 2020, Nordic Semiconductor ASA.
+# Copyright (c) 2020, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -15,6 +16,3 @@
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.main)
 set(TFM_SYSTEM_DSP OFF)
 set(SECURE_UART1 ON)
-
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
diff --git a/platform/ext/target/nordic_nrf/common/nrf9160/preload.cmake b/platform/ext/target/nordic_nrf/common/nrf9160/preload.cmake
index 6294961..3622515 100644
--- a/platform/ext/target/nordic_nrf/common/nrf9160/preload.cmake
+++ b/platform/ext/target/nordic_nrf/common/nrf9160/preload.cmake
@@ -1,5 +1,6 @@
 #-------------------------------------------------------------------------------
 # Copyright (c) 2020, Nordic Semiconductor ASA.
+# Copyright (c) 2020, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -15,6 +16,3 @@
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.main)
 set(TFM_SYSTEM_DSP OFF)
 set(SECURE_UART1 ON)
-
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
diff --git a/platform/ext/target/nordic_nrf/nrf5340pdk_nrf5340_cpuapp/README.rst b/platform/ext/target/nordic_nrf/nrf5340pdk_nrf5340_cpuapp/README.rst
index 5f7b7b3..64b8765 100644
--- a/platform/ext/target/nordic_nrf/nrf5340pdk_nrf5340_cpuapp/README.rst
+++ b/platform/ext/target/nordic_nrf/nrf5340pdk_nrf5340_cpuapp/README.rst
@@ -38,7 +38,7 @@
 
     $ mkdir build && cd build
     $ cmake -DTFM_PLATFORM=nordic_nrf/nrf5340pdk_nrf5340_cpuapp \
-            -DCMAKE_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake \
+            -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake \
             ../
     $ make install
 
@@ -134,4 +134,5 @@
 
 --------------
 
+*Copyright (c) 2020, Arm Limited. All rights reserved.*
 *Copyright (c) 2020, Nordic Semiconductor. All rights reserved.*
diff --git a/platform/ext/target/nordic_nrf/nrf9160dk_nrf9160/README.rst b/platform/ext/target/nordic_nrf/nrf9160dk_nrf9160/README.rst
index 19bfce1..224006a 100644
--- a/platform/ext/target/nordic_nrf/nrf9160dk_nrf9160/README.rst
+++ b/platform/ext/target/nordic_nrf/nrf9160dk_nrf9160/README.rst
@@ -31,7 +31,7 @@
 
     $ mkdir build && cd build
     $ cmake -DTFM_PLATFORM=nordic_nrf/nrf9160dk_nrf9160 \
-            -DCMAKE_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake \
+            -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake \
             ../
     $ make install
 
@@ -125,4 +125,5 @@
 
 --------------
 
+*Copyright (c) 2020, Arm Limited. All rights reserved.*
 *Copyright (c) 2020, Nordic Semiconductor. All rights reserved.*
diff --git a/platform/ext/target/nuvoton/m2351/preload.cmake b/platform/ext/target/nuvoton/m2351/preload.cmake
index 4802adf..31d5c74 100644
--- a/platform/ext/target/nuvoton/m2351/preload.cmake
+++ b/platform/ext/target/nuvoton/m2351/preload.cmake
@@ -13,7 +13,3 @@
 # Set architecture and CPU
 set(TFM_SYSTEM_PROCESSOR cortex-m23)
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.base)
-
-
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
diff --git a/platform/ext/target/nxp/lpcxpresso55s69/README.rst b/platform/ext/target/nxp/lpcxpresso55s69/README.rst
index 21adaf3..16f82a6 100644
--- a/platform/ext/target/nxp/lpcxpresso55s69/README.rst
+++ b/platform/ext/target/nxp/lpcxpresso55s69/README.rst
@@ -37,7 +37,9 @@
 
     $ mkdir build && cd build
     $ cmake -DTFM_PLATFORM=nxp/lpcxpresso55s69 \
-            -DCMAKE_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake -DBL2=OFF ../
+            -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake \
+            -DBL2=OFF \
+            ../
     $ make install
 
 Flashing and debugging with Segger J-Link
diff --git a/platform/ext/target/nxp/lpcxpresso55s69/preload.cmake b/platform/ext/target/nxp/lpcxpresso55s69/preload.cmake
index 7b6ec27..2701b93 100644
--- a/platform/ext/target/nxp/lpcxpresso55s69/preload.cmake
+++ b/platform/ext/target/nxp/lpcxpresso55s69/preload.cmake
@@ -14,8 +14,6 @@
 set(TFM_SYSTEM_PROCESSOR cortex-m33)
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.main)
 
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
 
 # Set processor type for NXP SDK
 add_definitions(-DCPU_LPC55S69JBD100_cm33_core0)
diff --git a/platform/ext/target/nxp/lpcxpresso55s69/scripts/build.sh b/platform/ext/target/nxp/lpcxpresso55s69/scripts/build.sh
index c9df15c..dd0d489 100644
--- a/platform/ext/target/nxp/lpcxpresso55s69/scripts/build.sh
+++ b/platform/ext/target/nxp/lpcxpresso55s69/scripts/build.sh
@@ -9,18 +9,9 @@
 # Cleanup previous build artifacts
 rm -rf app bin bl2 CMakeFiles generated install interface platform secure_fw tools cmake_install.cmake CMakeCache.txt
 
-# Set the readlink binary name:
-if [ "$(uname)" == "Darwin" ]; then
-    # For OS X this should be be 'greadlink' (brew install coreutils)
-    readlink=greadlink
-else
-    # For Linux this should be 'readlink'
-    readlink=readlink
-fi
-
 # Generate the S and NS makefiles
 cmake -DTFM_PLATFORM=nxp/lpcxpresso55s69 \
-      -DCMAKE_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake \
+      -DTFM_TOOLCHAIN_FILE=../toolchain_GNUARM.cmake \
       -DCMAKE_BUILD_TYPE=Relwithdebinfo \
       -DTFM_PROFILE=profile_medium ../
 
diff --git a/platform/ext/target/stm/nucleo_l552ze_q/preload.cmake b/platform/ext/target/stm/nucleo_l552ze_q/preload.cmake
index a263f9c..96b919a 100644
--- a/platform/ext/target/stm/nucleo_l552ze_q/preload.cmake
+++ b/platform/ext/target/stm/nucleo_l552ze_q/preload.cmake
@@ -14,8 +14,6 @@
 set(TFM_SYSTEM_PROCESSOR cortex-m33)
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.main)
 
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
 
 add_compile_definitions(
     STM32L552xx
diff --git a/platform/ext/target/stm/stm32l562e_dk/preload.cmake b/platform/ext/target/stm/stm32l562e_dk/preload.cmake
index 83247d0..591c49b 100644
--- a/platform/ext/target/stm/stm32l562e_dk/preload.cmake
+++ b/platform/ext/target/stm/stm32l562e_dk/preload.cmake
@@ -14,8 +14,6 @@
 set(TFM_SYSTEM_PROCESSOR cortex-m33)
 set(TFM_SYSTEM_ARCHITECTURE armv8-m.main)
 
-# Reload compiler to generate options from the CPU and architecture
-_compiler_reload()
 
 add_compile_definitions(
     STM32L562xx
diff --git a/secure_fw/CMakeLists.txt b/secure_fw/CMakeLists.txt
index 9c19faf..49f5dff 100644
--- a/secure_fw/CMakeLists.txt
+++ b/secure_fw/CMakeLists.txt
@@ -5,7 +5,7 @@
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 
 add_executable(tfm_s)
 add_library(secure_fw INTERFACE)
diff --git a/secure_fw/partitions/audit_logging/CMakeLists.txt b/secure_fw/partitions/audit_logging/CMakeLists.txt
index b847e4b..62d7126 100644
--- a/secure_fw/partitions/audit_logging/CMakeLists.txt
+++ b/secure_fw/partitions/audit_logging/CMakeLists.txt
@@ -14,7 +14,7 @@
     return()
 endif()
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 cmake_policy(SET CMP0079 NEW)
 
 add_library(tfm_partition_audit STATIC)
diff --git a/secure_fw/partitions/crypto/CMakeLists.txt b/secure_fw/partitions/crypto/CMakeLists.txt
index 506ee0a..c7ea1ac 100644
--- a/secure_fw/partitions/crypto/CMakeLists.txt
+++ b/secure_fw/partitions/crypto/CMakeLists.txt
@@ -9,7 +9,7 @@
     return()
 endif()
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 cmake_policy(SET CMP0079 NEW)
 
 add_library(tfm_partition_crypto STATIC)
diff --git a/secure_fw/partitions/initial_attestation/CMakeLists.txt b/secure_fw/partitions/initial_attestation/CMakeLists.txt
index 1e24558..e066326 100644
--- a/secure_fw/partitions/initial_attestation/CMakeLists.txt
+++ b/secure_fw/partitions/initial_attestation/CMakeLists.txt
@@ -9,7 +9,7 @@
     return()
 endif()
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 cmake_policy(SET CMP0079 NEW)
 
 add_library(tfm_partition_attestation STATIC)
diff --git a/secure_fw/partitions/internal_trusted_storage/CMakeLists.txt b/secure_fw/partitions/internal_trusted_storage/CMakeLists.txt
index b527c51..9e904c2 100644
--- a/secure_fw/partitions/internal_trusted_storage/CMakeLists.txt
+++ b/secure_fw/partitions/internal_trusted_storage/CMakeLists.txt
@@ -9,7 +9,7 @@
     return()
 endif()
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 cmake_policy(SET CMP0079 NEW)
 
 add_library(tfm_partition_its STATIC)
diff --git a/secure_fw/partitions/lib/sprt/CMakeLists.txt b/secure_fw/partitions/lib/sprt/CMakeLists.txt
index 626559f..66a92f2 100644
--- a/secure_fw/partitions/lib/sprt/CMakeLists.txt
+++ b/secure_fw/partitions/lib/sprt/CMakeLists.txt
@@ -5,7 +5,7 @@
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 
 add_library(tfm_sprt STATIC)
 
diff --git a/secure_fw/partitions/platform/CMakeLists.txt b/secure_fw/partitions/platform/CMakeLists.txt
index 3bd727d..ecad419 100644
--- a/secure_fw/partitions/platform/CMakeLists.txt
+++ b/secure_fw/partitions/platform/CMakeLists.txt
@@ -9,7 +9,7 @@
     return()
 endif()
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 cmake_policy(SET CMP0079 NEW)
 
 add_library(tfm_partition_platform STATIC
diff --git a/secure_fw/partitions/protected_storage/CMakeLists.txt b/secure_fw/partitions/protected_storage/CMakeLists.txt
index 2335f86..8a27f4b 100644
--- a/secure_fw/partitions/protected_storage/CMakeLists.txt
+++ b/secure_fw/partitions/protected_storage/CMakeLists.txt
@@ -9,7 +9,7 @@
     return()
 endif()
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 cmake_policy(SET CMP0079 NEW)
 
 add_library(tfm_partition_ps STATIC)
diff --git a/secure_fw/spm/CMakeLists.txt b/secure_fw/spm/CMakeLists.txt
index 098e6bd..15661a8 100755
--- a/secure_fw/spm/CMakeLists.txt
+++ b/secure_fw/spm/CMakeLists.txt
@@ -5,7 +5,7 @@
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 
 add_library(tfm_spm STATIC)
 add_library(tfm_boot_status INTERFACE)
diff --git a/toolchain_ARMCLANG.cmake b/toolchain_ARMCLANG.cmake
index f6ddaa5..9e8faf0 100644
--- a/toolchain_ARMCLANG.cmake
+++ b/toolchain_ARMCLANG.cmake
@@ -4,21 +4,21 @@
 # SPDX-License-Identifier: BSD-3-Clause
 #
 #-------------------------------------------------------------------------------
-
 cmake_minimum_required(VERSION 3.15)
 
-set(TFM_CMAKE_TOOLCHAIN_FILE_LOADED YES)
+# Don't load this file if it is specified as a cmake toolchain file
+if(NOT TFM_TOOLCHAIN_FILE)
+    message(DEPRECATION "SETTING CMAKE_TOOLCHAIN_FILE is deprecated. It has been replaced with TFM_TOOLCHAIN_FILE.")
+    return()
+endif()
 
 SET(CMAKE_SYSTEM_NAME Generic)
-# This setting is overridden in ${TFM_PLATFORM}/preload.cmake. It can be set to
-# any value here.
-set(CMAKE_SYSTEM_PROCESSOR cortex-m23)
 
 set(CMAKE_C_COMPILER armclang)
-set(CMAKE_ASM_COMPILER armclang)
+set(CMAKE_ASM_COMPILER armasm)
 
 set(LINKER_VENEER_OUTPUT_FLAG --import_cmse_lib_out=)
-set(COMPILER_CMSE_FLAG -mcmse)
+set(COMPILER_CMSE_FLAG $<$<COMPILE_LANGUAGE:C>:-mcmse>)
 
 # This variable name is a bit of a misnomer. The file it is set to is included
 # at a particular step in the compiler initialisation. It is used here to
@@ -26,61 +26,35 @@
 # with the Ninja generator.
 set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_LIST_DIR}/cmake/set_extensions.cmake)
 
-# Cmake makes it _really_ hard to dynamically set the cmake_system_processor
-# (used for setting mcpu flags etc). Instead we load
-# platform/ext/target/${TFM_PLATFORM}/preload.cmake, which should run this macro
-# to reload the compiler autoconfig. Note that it can't be loaded in this file
-# as cmake does not allow the use of command-line defined variables in toolchain
-# files and the path is platform dependent.
-macro(_compiler_reload)
-    set(CMAKE_SYSTEM_PROCESSOR ${TFM_SYSTEM_PROCESSOR})
-    set(CMAKE_SYSTEM_ARCHITECTURE ${TFM_SYSTEM_ARCHITECTURE})
-
+macro(tfm_toolchain_reset_compiler_flags)
     set_property(DIRECTORY PROPERTY COMPILE_OPTIONS "")
+    string(REGEX REPLACE "\\+nodsp" ".no_dsp" CMAKE_ASM_CPU_FLAG "${CMAKE_SYSTEM_PROCESSOR}")
+
+    add_compile_options(
+        $<$<COMPILE_LANGUAGE:C>:-Wno-ignored-optimization-argument>
+        $<$<COMPILE_LANGUAGE:C>:-Wno-unused-command-line-argument>
+        $<$<COMPILE_LANGUAGE:C>:-Wall>
+        # Don't error when the MBEDTLS_NULL_ENTROPY warning is shown
+        $<$<COMPILE_LANGUAGE:C>:-Wno-error=cpp>
+        $<$<COMPILE_LANGUAGE:C>:-c>
+        $<$<COMPILE_LANGUAGE:C>:-fdata-sections>
+        $<$<COMPILE_LANGUAGE:C>:-ffunction-sections>
+        $<$<COMPILE_LANGUAGE:C>:-fno-builtin>
+        $<$<COMPILE_LANGUAGE:C>:-fshort-enums>
+        $<$<COMPILE_LANGUAGE:C>:-fshort-wchar>
+        $<$<COMPILE_LANGUAGE:C>:-funsigned-char>
+        $<$<COMPILE_LANGUAGE:C>:-masm=auto>
+        $<$<COMPILE_LANGUAGE:C>:-nostdlib>
+        $<$<COMPILE_LANGUAGE:C>:-std=c99>
+        $<$<AND:$<COMPILE_LANGUAGE:C>,$<NOT:$<BOOL:${TFM_SYSTEM_FP}>>>:-mfpu=none>
+        $<$<AND:$<COMPILE_LANGUAGE:ASM>,$<NOT:$<BOOL:${TFM_SYSTEM_FP}>>>:--fpu=none>
+        $<$<COMPILE_LANGUAGE:ASM>:--cpu=${CMAKE_ASM_CPU_FLAG}>
+    )
+endmacro()
+
+macro(tfm_toolchain_reset_linker_flags)
     set_property(DIRECTORY PROPERTY LINK_OPTIONS "")
-    if(${CMAKE_C_COMPILER_VERSION} VERSION_GREATER_EQUAL "6.11")
-        add_compile_options(
-            --target=arm-arm-none-eabi
-            -Wno-ignored-optimization-argument
-            -Wno-unused-command-line-argument
-            -c
-            -fdata-sections
-            -ffunction-sections
-            -fno-builtin
-            -fshort-enums
-            -fshort-wchar
-            -funsigned-char
-            -masm=auto
-            -nostdlib
-            -std=c99
-            $<$<NOT:$<BOOL:${TFM_SYSTEM_FP}>>:-mfpu=none>
-        )
-    else()
-        # Compile options for legacy compiler 6.10.1. To be removed as soon that
-        # that compiler can be deprecated.
-        add_compile_options(
-            $<$<COMPILE_LANGUAGE:C>:--target=arm-arm-none-eabi>
-            $<$<COMPILE_LANGUAGE:C>:-Wno-ignored-optimization-argument>
-            $<$<COMPILE_LANGUAGE:C>:-Wno-unused-command-line-argument>
-            $<$<COMPILE_LANGUAGE:C>:-Wall>
-            # Don't error when the MBEDTLS_NULL_ENTROPY warning is shown
-            $<$<COMPILE_LANGUAGE:C>:-Wno-error=cpp>
-            $<$<COMPILE_LANGUAGE:C>:-c>
-            $<$<COMPILE_LANGUAGE:C>:-fdata-sections>
-            $<$<COMPILE_LANGUAGE:C>:-ffunction-sections>
-            $<$<COMPILE_LANGUAGE:C>:-fno-builtin>
-            $<$<COMPILE_LANGUAGE:C>:-fshort-enums>
-            $<$<COMPILE_LANGUAGE:C>:-fshort-wchar>
-            $<$<COMPILE_LANGUAGE:C>:-funsigned-char>
-            $<$<COMPILE_LANGUAGE:C>:-masm=auto>
-            $<$<COMPILE_LANGUAGE:C>:-nostdlib>
-            $<$<COMPILE_LANGUAGE:C>:-std=c99>
-            $<$<AND:$<COMPILE_LANGUAGE:C>,$<NOT:$<BOOL:${TFM_SYSTEM_FP}>>>:-mfpu=none>
-            $<$<COMPILE_LANGUAGE:ASM>:--cpu=${CMAKE_SYSTEM_PROCESSOR}>
-            $<$<AND:$<COMPILE_LANGUAGE:ASM>,$<NOT:$<BOOL:${TFM_SYSTEM_FP}>>>:--fpu=none>
-        )
-        set(COMPILER_CMSE_FLAG $<$<COMPILE_LANGUAGE:C>:-mcmse>)
-    endif()
+
     add_link_options(
         --info=summarysizes,sizes,totals,unused,veneers
         --strict
@@ -97,32 +71,40 @@
         --diag_suppress=6304
         $<$<NOT:$<BOOL:${TFM_SYSTEM_FP}>>:--fpu=softvfp>
     )
+endmacro()
 
-    if (DEFINED TFM_SYSTEM_FP)
-        if(TFM_SYSTEM_FP)
-            # TODO Whether a system requires these extensions appears to depend
-            # on the system in question, with no real rule. Since adding +fp
-            # will cause compile failures on systems that already have fp
-            # enabled, this is commented out for now to avoid those failures. In
-            # future, better handling should be implemented.
-            # string(APPEND CMAKE_SYSTEM_PROCESSOR "+fp")
-        else()
-            string(APPEND CMAKE_SYSTEM_PROCESSOR "+nofp")
-        endif()
-    endif()
+macro(tfm_toolchain_set_processor_arch)
+    set(CMAKE_SYSTEM_PROCESSOR       ${TFM_SYSTEM_PROCESSOR})
+    set(CMAKE_SYSTEM_ARCHITECTURE    ${TFM_SYSTEM_ARCHITECTURE})
+
+    set(CMAKE_C_COMPILER_TARGET      arm-${CROSS_COMPILE})
+    set(CMAKE_ASM_COMPILER_TARGET    arm-${CROSS_COMPILE})
 
     if (DEFINED TFM_SYSTEM_DSP)
-        if(TFM_SYSTEM_DSP)
-            # TODO Whether a system requires these extensions appears to depend
-            # on the system in question, with no real rule. Since adding +dsp
-            # will cause compile failures on systems that already have dsp
-            # enabled, this is commented out for now to avoid those failures. In
-            # future, better handling should be implemented.
-            # string(APPEND CMAKE_SYSTEM_PROCESSOR "+dsp")
-        else()
+        if(NOT TFM_SYSTEM_DSP)
             string(APPEND CMAKE_SYSTEM_PROCESSOR "+nodsp")
         endif()
+
+    include(Compiler/ARMClang)
+    # cmake does not allow the use of +dsp / +nofpu syntax. An override is added
+    # here to enable it. First reset the supported CPU list in case this has
+    # already been run.
+    __armclang_set_processor_list(C CMAKE_C_COMPILER_PROCESSOR_LIST)
+    __armclang_set_processor_list(ASM CMAKE_ASM_COMPILER_PROCESSOR_LIST)
+    # Then use regex to add +dsp +nodsp +fpu and +nofp options
+    # TODO generate this combinatorially
+    list(TRANSFORM CMAKE_C_COMPILER_PROCESSOR_LIST REPLACE "^(.+)$" "\\1;\\1+fp;\\1+nofp")
+    list(TRANSFORM CMAKE_C_COMPILER_PROCESSOR_LIST REPLACE "^(.+)$" "\\1;\\1+dsp;\\1+nodsp")
+    list(TRANSFORM CMAKE_ASM_COMPILER_PROCESSOR_LIST REPLACE "^(.+)$" "\\1;\\1+fp;\\1+nofp")
+    list(TRANSFORM CMAKE_ASM_COMPILER_PROCESSOR_LIST REPLACE "^(.+)$" "\\1;\\1+dsp;\\1+nodsp")
+    set(CMAKE_C_COMPILER_PROCESSOR_LIST ${CMAKE_C_COMPILER_PROCESSOR_LIST} CACHE INTERNAL "" FORCE)
     endif()
+endmacro()
+
+macro(tfm_toolchain_reload_compiler)
+    tfm_toolchain_set_processor_arch()
+    tfm_toolchain_reset_compiler_flags()
+    tfm_toolchain_reset_linker_flags()
 
     unset(CMAKE_C_FLAGS_INIT)
     unset(CMAKE_C_LINK_FLAGS)
@@ -131,44 +113,32 @@
     unset(__mcpu_flag_set)
     unset(__march_flag_set)
 
-    # cmake does not allow the use of +dsp / +nofpu syntax. An override is added
-    # here to enable it. First reset the supported CPU list in case this has
-    # already been run.
-    __armclang_set_processor_list(C CMAKE_C_COMPILER_PROCESSOR_LIST)
-    __armclang_set_processor_list(ASM CMAKE_ASM_COMPILER_PROCESSOR_LIST)
-    # Then use regex to add +dsp +nodsp +fpu and +nofp options
-    # TODO generate this combinatorially
-    list(TRANSFORM CMAKE_C_COMPILER_PROCESSOR_LIST REPLACE "^(.+)$" "\\1;\\1+fp;\\1+nofp;")
-    list(TRANSFORM CMAKE_C_COMPILER_PROCESSOR_LIST REPLACE "^(.+)$" "\\1;\\1+dsp;\\1+nodsp;")
-    list(TRANSFORM CMAKE_ASM_COMPILER_PROCESSOR_LIST REPLACE "^(.+)$" "\\1;\\1+fp;\\1+nofp;")
-    list(TRANSFORM CMAKE_ASM_COMPILER_PROCESSOR_LIST REPLACE "^(.+)$" "\\1;\\1+dsp;\\1+nodsp;")
-
+    include(Compiler/ARMClang)
     __compiler_armclang(C)
-
-    if(${CMAKE_C_COMPILER_VERSION} VERSION_GREATER_EQUAL "6.11")
-        __compiler_armclang(ASM)
-    else()
-        # Because armclang<6.11 does not have an integrated assembler that
-        # supports the ASM syntax used by the CMSIS startup files, it is
-        # required to manuall invoke armasm. CMake does not support that when
-        # using armclang as the declared compiler, so instead we use some of the
-        # internals from ArmCC which uses armasm by default.
-        find_program(ARMASM_PATH armasm HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}")
-        set(CMAKE_ASM_COMPILER ${ARMASM_PATH})
-        include(${CMAKE_ROOT}/Modules/Compiler/ARMCC.cmake)
-        include(${CMAKE_ROOT}/Modules/Compiler/ARMCC-ASM.cmake)
-        __compiler_armcc(ASM)
-    endif()
+    include(Compiler/ARMCC)
+    __compiler_armcc(ASM)
 
     set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_INIT})
     set(CMAKE_ASM_FLAGS ${CMAKE_ASM_FLAGS_INIT})
 
     # But armlink doesn't support this +dsp syntax, so take the cpu flag and
     # throw away the plus and everything after.
-    string(REGEX REPLACE "(--cpu=.*)\\+[a-z\\+]*[ ]?" "\\1" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
-    string(REGEX REPLACE "(--cpu=.*)\\+[a-z\\+]*[ ]?" "\\1" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
+    string(REGEX REPLACE "\\+nodsp" ".no_dsp" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
+    string(REGEX REPLACE "\\+nodsp" ".no_dsp" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
+
+    # Workaround for issues with --depend-single-line with armasm and Ninja
+    if (CMAKE_GENERATOR STREQUAL "Ninja")
+        set( CMAKE_DEPFILE_FLAGS_ASM "--depend=<OBJECT>.d")
+    endif()
 endmacro()
 
+# Configure environment for the compiler setup run by cmake at the first
+# `project` call in <tfm_root>/CMakeLists.txt. After this mandatory setup is
+# done, all further compiler setup is done via tfm_toolchain_reload_compiler()
+tfm_toolchain_set_processor_arch()
+tfm_toolchain_reset_compiler_flags()
+tfm_toolchain_reset_linker_flags()
+
 # Behaviour for handling scatter files is so wildly divergent between compilers
 # that this macro is required.
 macro(target_add_scatter_file target)
diff --git a/toolchain_GNUARM.cmake b/toolchain_GNUARM.cmake
index dfce66f..e530bf7 100644
--- a/toolchain_GNUARM.cmake
+++ b/toolchain_GNUARM.cmake
@@ -5,16 +5,19 @@
 #
 #-------------------------------------------------------------------------------
 
-set(TFM_CMAKE_TOOLCHAIN_FILE_LOADED YES)
+# Don't load this file if it is specified as a cmake toolchain file
+if(NOT TFM_TOOLCHAIN_FILE)
+    message(DEPRECATION "SETTING CMAKE_TOOLCHAIN_FILE is deprecated. It has been replaced with TFM_TOOLCHAIN_FILE.")
+    return()
+endif()
 
 set(CMAKE_SYSTEM_NAME Generic)
-set(CMAKE_SYSTEM_PROCESSOR arm)
 
-set(CMAKE_C_COMPILER arm-none-eabi-gcc)
-set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
+set(CMAKE_C_COMPILER ${CROSS_COMPILE}-gcc)
+set(CMAKE_ASM_COMPILER ${CROSS_COMPILE}-gcc)
 
-# Tell CMake not to try to link executables during its checks
-set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+set(LINKER_VENEER_OUTPUT_FLAG -Wl,--cmse-implib,--out-implib=)
+set(COMPILER_CMSE_FLAG -mcmse)
 
 # This variable name is a bit of a misnomer. The file it is set to is included
 # at a particular step in the compiler initialisation. It is used here to
@@ -22,44 +25,9 @@
 # with the Ninja generator.
 set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_LIST_DIR}/cmake/set_extensions.cmake)
 
-# Cmake makes it _really_ hard to dynamically set the cmake_system_processor
-# (used for setting mcpu flags etc). Instead we load
-# platform/ext/target/${TFM_PLATFORM}/preload.cmake, which should run this macro
-# to reload the compiler autoconfig. Note that it can't be loaded in this file
-# as cmake does not allow the use of command-line defined variables in toolchain
-# files and the path is platform dependent.
-macro(_compiler_reload)
-    set(CMAKE_SYSTEM_PROCESSOR ${TFM_SYSTEM_PROCESSOR})
-    set(CMAKE_SYSTEM_ARCHITECTURE ${TFM_SYSTEM_ARCHITECTURE})
-
-    if (DEFINED TFM_SYSTEM_FP)
-        if(TFM_SYSTEM_FP)
-            # TODO Whether a system requires these extensions appears to depend
-            # on the system in question, with no real rule. Since adding +fp
-            # will cause compile failures on systems that already have fp
-            # enabled, this is commented out for now to avoid those failures. In
-            # future, better handling should be implemented.
-            # string(APPEND CMAKE_SYSTEM_PROCESSOR "+fp")
-        else()
-            string(APPEND CMAKE_SYSTEM_PROCESSOR "+nofp")
-        endif()
-    endif()
-
-    if (DEFINED TFM_SYSTEM_DSP)
-        if(TFM_SYSTEM_DSP)
-            # TODO Whether a system requires these extensions appears to depend
-            # on the system in question, with no real rule. Since adding +dsp
-            # will cause compile failures on systems that already have dsp
-            # enabled, this is commented out for now to avoid those failures. In
-            # future, better handling should be implemented.
-            # string(APPEND CMAKE_SYSTEM_PROCESSOR "+dsp")
-        else()
-            string(APPEND CMAKE_SYSTEM_PROCESSOR "+nodsp")
-        endif()
-    endif()
-
+macro(tfm_toolchain_reset_compiler_flags)
     set_property(DIRECTORY PROPERTY COMPILE_OPTIONS "")
-    set_property(DIRECTORY PROPERTY LINK_OPTIONS "")
+
     add_compile_options(
         --specs=nano.specs
         -Wall
@@ -77,6 +45,11 @@
         -std=c99
         $<$<NOT:$<BOOL:${TFM_SYSTEM_FP}>>:-msoft-float>
     )
+endmacro()
+
+macro(tfm_toolchain_reset_linker_flags)
+    set_property(DIRECTORY PROPERTY LINK_OPTIONS "")
+
     add_link_options(
         --entry=Reset_Handler
         --specs=nano.specs
@@ -86,6 +59,23 @@
         LINKER:--no-wchar-size-warning
         LINKER:--print-memory-usage
     )
+endmacro()
+
+macro(tfm_toolchain_set_processor_arch)
+    set(CMAKE_SYSTEM_PROCESSOR ${TFM_SYSTEM_PROCESSOR})
+    set(CMAKE_SYSTEM_ARCHITECTURE ${TFM_SYSTEM_ARCHITECTURE})
+
+    if (DEFINED TFM_SYSTEM_DSP)
+        if(NOT TFM_SYSTEM_DSP)
+            string(APPEND CMAKE_SYSTEM_PROCESSOR "+nodsp")
+        endif()
+    endif()
+endmacro()
+
+macro(tfm_toolchain_reload_compiler)
+    tfm_toolchain_set_processor_arch()
+    tfm_toolchain_reset_compiler_flags()
+    tfm_toolchain_reset_linker_flags()
 
     unset(CMAKE_C_FLAGS_INIT)
     unset(CMAKE_ASM_FLAGS_INIT)
@@ -99,8 +89,10 @@
     set(CMAKE_ASM_FLAGS ${CMAKE_ASM_FLAGS_INIT})
 endmacro()
 
-set(LINKER_VENEER_OUTPUT_FLAG -Wl,--cmse-implib,--out-implib=)
-set(COMPILER_CMSE_FLAG -mcmse)
+# Configure environment for the compiler setup run by cmake at the first
+# `project` call in <tfm_root>/CMakeLists.txt. After this mandatory setup is
+# done, all further compiler setup is done via tfm_toolchain_reload_compiler()
+tfm_toolchain_reload_compiler()
 
 macro(target_add_scatter_file target)
     target_link_options(${target}
diff --git a/toolchain_IARARM.cmake b/toolchain_IARARM.cmake
index b08a28e..9430e78 100644
--- a/toolchain_IARARM.cmake
+++ b/toolchain_IARARM.cmake
@@ -6,20 +6,31 @@
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.14)
+cmake_minimum_required(VERSION 3.15)
 
-set(TFM_CMAKE_TOOLCHAIN_FILE_LOADED YES)
+# Don't load this file if it is specified as a cmake toolchain file
+if(NOT TFM_TOOLCHAIN_FILE)
+    message(DEPRECATION "SETTING CMAKE_TOOLCHAIN_FILE is deprecated. It has been replaced with TFM_TOOLCHAIN_FILE.")
+    return()
+endif()
 
 SET(CMAKE_SYSTEM_NAME Generic)
-# This setting is overridden in ${TFM_PLATFORM}/preload.cmake. It can be set to
-# any value here.
-set(CMAKE_SYSTEM_PROCESSOR cortex-m23)
+set(CMAKE_SYSTEM_PROCESSOR       ${TFM_SYSTEM_PROCESSOR})
+set(CMAKE_SYSTEM_ARCHITECTURE    ${TFM_SYSTEM_ARCHITECTURE})
+
+if(CROSS_COMPILE)
+    set(CMAKE_C_COMPILER_TARGET      arm-${CROSS_COMPILE})
+    set(CMAKE_ASM_COMPILER_TARGET    arm-${CROSS_COMPILE})
+else()
+    set(CMAKE_C_COMPILER_TARGET      arm-arm-none-eabi)
+    set(CMAKE_ASM_COMPILER_TARGET    arm-arm-none-eabi)
+endif()
 
 set(CMAKE_C_COMPILER iccarm)
 set(CMAKE_ASM_COMPILER iasmarm)
 
-set(COMPILER_CMSE_FLAG --cmse)
 set(LINKER_VENEER_OUTPUT_FLAG --import_cmse_lib_out= )
+set(COMPILER_CMSE_FLAG --cmse)
 
 # This variable name is a bit of a misnomer. The file it is set to is included
 # at a particular step in the compiler initialisation. It is used here to
@@ -27,46 +38,9 @@
 # with the Ninja generator.
 set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_LIST_DIR}/cmake/set_extensions.cmake)
 
-# Cmake makes it _really_ hard to dynamically set the cmake_system_processor
-# (used for setting mcpu flags etc). Instead we load
-# platform/ext/target/${TFM_PLATFORM}/preload.cmake, which should run this macro
-# to reload the compiler autoconfig. Note that it can't be loaded in this file
-# as cmake does not allow the use of command-line defined variables in toolchain
-# files and the path is platform dependent.
-macro(_compiler_reload)
-    if(${TFM_SYSTEM_PROCESSOR} STREQUAL "cortex-m0plus")
-      set(CMAKE_SYSTEM_PROCESSOR Cortex-M0+)
-    else()
-      set(CMAKE_SYSTEM_PROCESSOR ${TFM_SYSTEM_PROCESSOR})
-    endif()
-    set(CMAKE_SYSTEM_ARCHITECTURE ${TFM_SYSTEM_ARCHITECTURE})
-
-    if (DEFINED TFM_SYSTEM_FP)
-        if(TFM_SYSTEM_FP)
-            # TODO Whether a system requires these extensions appears to depend
-            # on the system in question, with no real rule. Since adding .fp
-            # will cause compile failures on systems that already have fp
-            # enabled, this is commented out for now to avoid those failures. In
-            # future, better handling should be implemented.
-            # string(APPEND CMAKE_SYSTEM_PROCESSOR ".fp")
-        endif()
-    endif()
-
-    if (DEFINED TFM_SYSTEM_DSP)
-        if(TFM_SYSTEM_DSP)
-            # TODO Whether a system requires these extensions appears to depend
-            # on the system in question, with no real rule. Since adding .dsp
-            # will cause compile failures on systems that already have dsp
-            # enabled, this is commented out for now to avoid those failures. In
-            # future, better handling should be implemented.
-            # string(APPEND CMAKE_SYSTEM_PROCESSOR ".dsp")
-        else()
-            string(APPEND CMAKE_SYSTEM_PROCESSOR ".no_dsp")
-        endif()
-    endif()
-
+macro(tfm_toolchain_reset_compiler_flags)
     set_property(DIRECTORY PROPERTY COMPILE_OPTIONS "")
-    set_property(DIRECTORY PROPERTY LINK_OPTIONS "")
+
     add_compile_options(
         $<$<COMPILE_LANGUAGE:C,CXX>:-e>
         $<$<COMPILE_LANGUAGE:C,CXX>:--dlib_config=full>
@@ -76,12 +50,34 @@
         $<$<COMPILE_LANGUAGE:C,CXX>:-D_NO_DEFINITIONS_IN_HEADER_FILES>
         $<$<COMPILE_LANGUAGE:C,CXX>:--diag_suppress=Pe546,Pe940,Pa082,Pa084>
     )
+endmacro()
+
+macro(tfm_toolchain_reset_linker_flags)
+    set_property(DIRECTORY PROPERTY LINK_OPTIONS "")
+
     add_link_options(
       --silent
       --semihosting
       --redirect __write=__write_buffered
     )
+endmacro()
 
+macro(tfm_toolchain_set_processor_arch)
+    if(${TFM_SYSTEM_PROCESSOR} STREQUAL "cortex-m0plus")
+      set(CMAKE_SYSTEM_PROCESSOR Cortex-M0+)
+    else()
+      set(CMAKE_SYSTEM_PROCESSOR ${TFM_SYSTEM_PROCESSOR})
+    endif()
+    set(CMAKE_SYSTEM_ARCHITECTURE ${TFM_SYSTEM_ARCHITECTURE})
+
+    if (DEFINED TFM_SYSTEM_DSP)
+        if(NOT TFM_SYSTEM_DSP)
+            string(APPEND CMAKE_SYSTEM_PROCESSOR ".no_dsp")
+        endif()
+    endif()
+endmacro()
+
+macro(tfm_toolchain_reload_compiler)
     unset(CMAKE_C_FLAGS_INIT)
     unset(CMAKE_C_LINK_FLAGS)
     unset(CMAKE_ASM_FLAGS_INIT)
@@ -94,9 +90,13 @@
 
     set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_INIT})
     set(CMAKE_ASM_FLAGS ${CMAKE_ASM_FLAGS_INIT})
-
 endmacro()
 
+# Configure environment for the compiler setup run by cmake at the first
+# `project` call in <tfm_root>/CMakeLists.txt. After this mandatory setup is
+# done, all further compiler setup is done via tfm_toolchain_reload_compiler()
+tfm_toolchain_reload_compiler()
+
 # Behaviour for handling scatter files is so wildly divergent between compilers
 # that this macro is required.
 macro(target_add_scatter_file target)
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 89cf027..381a9f1 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -5,7 +5,7 @@
 #
 #-------------------------------------------------------------------------------
 
-cmake_minimum_required(VERSION 3.13)
+cmake_minimum_required(VERSION 3.15)
 find_package(Python3)
 
 ############################### Manifest declaration ###########################