Build: Enhance toolchain version check

Move toolchain version checks from check_config.cmake to dedicated
toolchain_XXX.cmake. Those checks are created specially for toolchain
limitations. They shall not be placed in TF-M functionality
configuration checks.

Make the valid version range more clear in toolchain_XXX.cmake.

Change-Id: I79fc1a7ae18dce6ffc98408c16ed7e3863bf0b9d
Signed-off-by: David Hu <david.hu@arm.com>
diff --git a/config/check_config.cmake b/config/check_config.cmake
index 0110c45..7fefce3 100644
--- a/config/check_config.cmake
+++ b/config/check_config.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
 # Copyright (c) 2021, Cypress Semiconductor Corporation. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
@@ -20,11 +20,6 @@
     endif()
 endfunction()
 
-tfm_invalid_config(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "7.3.1")
-
-# Incorrect behaviour of ArmClang v6.17 was identified during v1.5.0 release. The issue reported.
-tfm_invalid_config(CMAKE_C_COMPILER_ID STREQUAL "ARMClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "6.17.0")
-
 set (TFM_L3_PLATFORM_LISTS arm/mps2/an521 arm/musca_b1/sse_200 stm/stm32l562e_dk)
 set (VALID_ISOLATION_LEVELS 1 2 3)
 
diff --git a/toolchain_ARMCLANG.cmake b/toolchain_ARMCLANG.cmake
index 10eee26..2a97410 100644
--- a/toolchain_ARMCLANG.cmake
+++ b/toolchain_ARMCLANG.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -178,6 +178,16 @@
     include(Compiler/ARMCC-ASM)
     __compiler_armcc(ASM)
 
+    if (CMAKE_C_COMPILER_VERSION VERSION_LESS 6.10.1)
+        message(FATAL_ERROR "Please select newer Arm compiler version starting from 6.10.1.")
+    endif()
+
+    if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.15)
+        message(FATAL_ERROR "Armclang starting from v6.15 may cause MemManage fault."
+                            " The root cause is still under analysis by Armclang."
+                            " Please use lower Armclang versions instead.")
+    endif()
+
     # Cmake's armclang support will set either mcpu or march, but march gives
     # better code size so we manually set it.
     set(CMAKE_C_FLAGS   "-march=${CMAKE_SYSTEM_ARCH}")
diff --git a/toolchain_GNUARM.cmake b/toolchain_GNUARM.cmake
index 9cb741c..9c06868 100644
--- a/toolchain_GNUARM.cmake
+++ b/toolchain_GNUARM.cmake
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2020-2021, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -116,7 +116,14 @@
     tfm_toolchain_reset_compiler_flags()
     tfm_toolchain_reset_linker_flags()
 
-    if (CMAKE_C_COMPILER_VERSION VERSION_EQUAL 10.2.1)
+    # CMAKE_C_COMPILER_VERSION is not guaranteed to be defined.
+    EXECUTE_PROCESS( COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION )
+
+    if (GCC_VERSION VERSION_LESS 7.3.1)
+        message(FATAL_ERROR "Please use newer GNU Arm compiler version starting from 7.3.1.")
+    endif()
+
+    if (GCC_VERSION VERSION_EQUAL 10.2.1)
         message(FATAL_ERROR "GNU Arm compiler version 10-2020-q4-major has an issue in CMSE support."
                             " Select other GNU Arm compiler versions instead."
                             " See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99157 for the issue detail.")