aom: cpu.cmake: Fix AArch64 compiler flag tests

From faab48a3ab2a6b0061ff98b175032532e413b8b2 Mon Sep 17 00:00:00 2001
From: George Steed <[EMAIL REDACTED]>
Date: Wed, 7 Feb 2024 15:35:27 +0000
Subject: [PATCH] cpu.cmake: Fix AArch64 compiler flag tests

The existing check_c_compiler_flag test uses a regex internally to match
against common error message strings in stderr from the compiler,
however this does not match the "invalid feature modifier" error that is
emitted by certain versions of GCC. This leads to the feature being
incorrectly enabled only to then fail to compile the library later.

To get around this, use the aom_check_source_compiles helper routine to
compile a trivial program with the flag instead since this does not
suffer the same problems and correctly identifies the features as being
not available.

Bug: aomedia:3543
Change-Id: I072281b2d3e986ee859ff8268bfad7a0fce3fd4c
 build/cmake/cpu.cmake | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/build/cmake/cpu.cmake b/build/cmake/cpu.cmake
index a9b7a67070..bd13d035d5 100644
--- a/build/cmake/cpu.cmake
+++ b/build/cmake/cpu.cmake
@@ -26,8 +26,19 @@ if("${AOM_TARGET_CPU}" STREQUAL "arm64")
   foreach(flavor ${ARM64_FLAVORS})
     if(ENABLE_${flavor} AND NOT DEFINED AOM_${flavor}_FLAG)
       set(AOM_${flavor}_FLAG "${AOM_${flavor}_DEFAULT_FLAG}")
+      string(TOLOWER "${flavor}" flavor_lower)
+      # Do not use check_c_compiler_flag here since the regex used to match
+      # against stderr does not recognise the "invalid feature modifier" error
+      # produced by certain versions of GCC, leading to the feature being
+      # incorrectly marked as available.
-      check_c_compiler_flag("${AOM_${flavor}_FLAG}" FLAG_SUPPORTED)
+      aom_check_source_compiles("arm_feature_flag_${flavor_lower}_available"
+                                "static void function(void) {}" FLAG_SUPPORTED)
       if(NOT ${FLAG_SUPPORTED})
         set(ENABLE_${flavor} 0)