SDL: cmake: don't check c++ compiler flags for asan when CXX is not enabled (a4a8a)

From a4a8a2907519dd76a2c2463c6b2380e4b6dfa144 Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Sat, 21 Sep 2024 12:14:53 -0500
Subject: [PATCH] cmake: don't check c++ compiler flags for asan when CXX is
 not enabled

Backport of fd2b9c060291af8ba3388f18b3b0000e81e41643 to SDL2
---
 CMakeLists.txt | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 514bd1192ffce..0a9269a7e1399 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3210,9 +3210,11 @@ macro(check_add_debug_flag FLAG SUFFIX)
         set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
     endif()
 
-    check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
-    if (HAS_CXX_${SUFFIX})
-        set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
+    if(CMAKE_CXX_COMPILER)
+      check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
+      if (HAS_CXX_${SUFFIX})
+          set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
+      endif()
     endif()
 endmacro()
 
@@ -3231,18 +3233,20 @@ macro(asan_check_add_debug_flag2 ASAN_FLAG)
 
     set (STORED_REQLIBS ${CMAKE_REQUIRED_LIBRARIES})
     set (CMAKE_REQUIRED_LIBRARIES "${FLAG};asan")
-    check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG})
-    check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG})
-    set (CMAKE_REQUIRED_LIBRARIES ${STORED_REQLIBS})
 
+    check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG})
     if (HAS_C_FLAG_${ASAN_FLAG})
         set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
     endif()
 
-    if (HAS_CXX_${ASAN_FLAG})
-        set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
+    if(CMAKE_CXX_COMPILER)
+      check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG})
+      if (HAS_CXX_${ASAN_FLAG})
+          set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
+      endif()
     endif()
 
+    set (CMAKE_REQUIRED_LIBRARIES ${STORED_REQLIBS})
     if(HAS_C_${ASAN_FLAG} OR HAS_CXX_${ASAN_FLAG})
       set(HAVE_ASAN ON)
     endif()