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

From fd2b9c060291af8ba3388f18b3b0000e81e41643 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sat, 1 Jun 2024 10:18:15 +0200
Subject: [PATCH] cmake: don't check c++ compiler flags for asan when CXX is
 not enabled

---
 CMakeLists.txt | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 09456ae554a3c..35d95ce0efba5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3054,9 +3054,11 @@ macro(check_add_debug_flag FLAG SUFFIX)
     string(APPEND CMAKE_C_FLAGS_DEBUG " ${FLAG}")
   endif()
 
-  check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
-  if(HAS_CXX_${SUFFIX})
-    string(APPEND CMAKE_CXX_FLAGS_DEBUG " ${FLAG}")
+  if(CMAKE_CXX_COMPILER)
+    check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
+    if(HAS_CXX_${SUFFIX})
+      string(APPEND CMAKE_CXX_FLAGS_DEBUG " ${FLAG}")
+    endif()
   endif()
 endmacro()
 
@@ -3075,18 +3077,20 @@ macro(asan_check_add_debug_flag2 ASAN_FLAG)
 
   cmake_push_check_state()
   list(APPEND 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})
-  cmake_pop_check_state()
 
+  check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG})
   if (HAS_C_FLAG_${ASAN_FLAG})
     string(APPEND CMAKE_C_FLAGS_DEBUG " ${FLAG}")
   endif()
 
-  if (HAS_CXX_${ASAN_FLAG})
-    string(APPEND CMAKE_CXX_FLAGS_DEBUG " ${FLAG}")
+  if(CMAKE_CXX_COMPILER)
+    check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG})
+    if (HAS_CXX_${ASAN_FLAG})
+      string(APPEND CMAKE_CXX_FLAGS_DEBUG " ${FLAG}")
+    endif()
   endif()
 
+  cmake_pop_check_state()
   if(HAS_C_${ASAN_FLAG} OR HAS_CXX_${ASAN_FLAG})
     set(HAVE_ASAN ON)
   endif()