SDL: cmake: add -Wformat when checking -Wformat-extra-args

From 1d60030e8443b0e62639b7c27e781a7c714e884f Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sat, 7 Jan 2023 22:25:09 +0100
Subject: [PATCH] cmake: add -Wformat when checking -Wformat-extra-args

The need for -Wformat when using -Wformat-extra-args was observed for
the msys2 mingw64 gcc toolchain.
---
 test/CMakeLists.txt | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 3736b32c750e..af2330456be6 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -208,8 +208,6 @@ add_sdl_test_executable(gamepadmap NEEDS_RESOURCES TESTUTILS gamepadmap.c)
 add_sdl_test_executable(testvulkan testvulkan.c)
 add_sdl_test_executable(testoffscreen testoffscreen.c)
 
-cmake_push_check_state()
-
 check_c_compiler_flag(-Wformat-overflow HAVE_WFORMAT_OVERFLOW)
 if(HAVE_WFORMAT_OVERFLOW)
     target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_OVERFLOW)
@@ -220,13 +218,17 @@ if(HAVE_WFORMAT)
     target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT)
 endif()
 
+cmake_push_check_state()
+if(HAVE_WFORMAT)
+    # Some compilers ignore -Wformat-extra-args without -Wformat
+    set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wformat")
+endif()
 check_c_compiler_flag(-Wformat-extra-args HAVE_WFORMAT_EXTRA_ARGS)
+cmake_pop_check_state()
 if(HAVE_WFORMAT_EXTRA_ARGS)
     target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_EXTRA_ARGS)
 endif()
 
-cmake_pop_check_state()
-
 if(SDL_DUMMYAUDIO)
   list(APPEND SDL_TESTS_NONINTERACTIVE
     testaudioinfo