From a6129947ee9645409898391b56aed8911da87040 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Sat, 8 Aug 2026 10:28:26 +0300
Subject: [PATCH 47/47] Do not include SDL2 headers when SDL3 audio enabled

Reported by Matt Jolly

See RM #2121

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-gtk-3.22/gui_main.c   | 4 ++--
 client/gui-gtk-4.0/gui_main.c    | 4 ++--
 client/gui-gtk-5.0/gui_main.c    | 4 ++--
 client/gui-qt/gui_main.cpp       | 4 ++--
 gen_headers/meson_fc_config.h.in | 5 ++++-
 m4/sound.m4                      | 2 ++
 meson.build                      | 1 +
 7 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c
index 835dfe757a..4bf4c43957 100644
--- a/client/gui-gtk-3.22/gui_main.c
+++ b/client/gui-gtk-3.22/gui_main.c
@@ -15,7 +15,7 @@
 #include <fc_config.h>
 #endif
 
-#ifdef AUDIO_SDL
+#ifdef AUDIO_SDL2
 /* Though it would happily compile without this include,
  * it is needed for sound to work.
  * It defines "main" macro to rename our main() so that
@@ -25,7 +25,7 @@
 #else  /* PLAIN_INCLUDE */
 #include <SDL2/SDL.h>
 #endif /* PLAIN_INCLUDE */
-#endif /* AUDIO_SDL */
+#endif /* AUDIO_SDL2 */
 
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
diff --git a/client/gui-gtk-4.0/gui_main.c b/client/gui-gtk-4.0/gui_main.c
index 4be6d72ea0..0bb114f548 100644
--- a/client/gui-gtk-4.0/gui_main.c
+++ b/client/gui-gtk-4.0/gui_main.c
@@ -15,7 +15,7 @@
 #include <fc_config.h>
 #endif
 
-#ifdef AUDIO_SDL
+#ifdef AUDIO_SDL2
 /* Though it would happily compile without this include,
  * it is needed for sound to work.
  * It defines "main" macro to rename our main() so that
@@ -25,7 +25,7 @@
 #else  /* PLAIN_INCLUDE */
 #include <SDL2/SDL.h>
 #endif /* PLAIN_INCLUDE */
-#endif /* AUDIO_SDL */
+#endif /* AUDIO_SDL2 */
 
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
diff --git a/client/gui-gtk-5.0/gui_main.c b/client/gui-gtk-5.0/gui_main.c
index 3d7139cd88..5f415229df 100644
--- a/client/gui-gtk-5.0/gui_main.c
+++ b/client/gui-gtk-5.0/gui_main.c
@@ -15,7 +15,7 @@
 #include <fc_config.h>
 #endif
 
-#ifdef AUDIO_SDL
+#ifdef AUDIO_SDL2
 /* Though it would happily compile without this include,
  * it is needed for sound to work.
  * It defines "main" macro to rename our main() so that
@@ -25,7 +25,7 @@
 #else  /* PLAIN_INCLUDE */
 #include <SDL2/SDL.h>
 #endif /* PLAIN_INCLUDE */
-#endif /* AUDIO_SDL */
+#endif /* AUDIO_SDL2 */
 
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
diff --git a/client/gui-qt/gui_main.cpp b/client/gui-qt/gui_main.cpp
index b148775bcc..1e8bcf0db8 100644
--- a/client/gui-qt/gui_main.cpp
+++ b/client/gui-qt/gui_main.cpp
@@ -15,7 +15,7 @@
 #include <fc_config.h>
 #endif
 
-#ifdef AUDIO_SDL
+#ifdef AUDIO_SDL2
 /* Though it would happily compile without this include,
  * it is needed for sound to work.
  * It defines "main" macro to rename our main() so that
@@ -25,7 +25,7 @@
 #else  // PLAIN_INCLUDE
 #include <SDL2/SDL.h>
 #endif // PLAIN_INCLUDE
-#endif // AUDIO_SDL
+#endif // AUDIO_SDL2
 
 #include <stdio.h>
 
diff --git a/gen_headers/meson_fc_config.h.in b/gen_headers/meson_fc_config.h.in
index c765da5786..d98074ea57 100644
--- a/gen_headers/meson_fc_config.h.in
+++ b/gen_headers/meson_fc_config.h.in
@@ -74,7 +74,10 @@
 /* Enable audio */
 #mesondefine AUDIO_SDL
 
-/* Use SDL3_mixer */
+/* Use SDL2_mixer */
+#mesondefine AUDIO_SDL2
+
+/* Use sdl3-mixer */
 #mesondefine AUDIO_SDL3
 
 /* Native language support enabled */
diff --git a/m4/sound.m4 b/m4/sound.m4
index b898170695..867ad68544 100644
--- a/m4/sound.m4
+++ b/m4/sound.m4
@@ -17,6 +17,7 @@ if test "x$USE_SOUND_SDL" != "xno" ; then
     SOUND_CFLAGS="$SOUND_CFLAGS $SDL2MIXER_CFLAGS"
     SOUND_LIBS="$SOUND_LIBS $SDL2MIXER_LIBS"
     AC_DEFINE([AUDIO_SDL], [1], [SDL Mixer support])
+    AC_DEFINE([AUDIO_SDL2], [1], [Use SDL2_Mixer])
     SDL_mixer=sdl2
     SOUND_SDL_OK=true
     if test x$sdl_headers_without_path != xyes ; then
@@ -43,6 +44,7 @@ sdl_headers_without_path=yes])
         SOUND_CFLAGS="$SOUND_CFLAGS $SDL2_CFLAGS"
         SOUND_LIBS="$SOUND_LIBS -lSDL2_mixer $SDL2_LIBS"
         AC_DEFINE([AUDIO_SDL], [1], [SDL Mixer support])
+        AC_DEFINE([AUDIO_SDL2], [1], [Use SDL2_Mixer])
         AC_MSG_RESULT([yes])
         SOUND_SDL_OK=true
       else
diff --git a/meson.build b/meson.build
index 00945c585c..0002888299 100644
--- a/meson.build
+++ b/meson.build
@@ -961,6 +961,7 @@ if get_option('audio') != 'none'
   else
     audio_sdl2_dep = dependency('SDL2_mixer')
     audio_dep = [sdl2main_dep, audio_sdl2_dep]
+    priv_conf_data.set('AUDIO_SDL2', 1)
   endif
 
   audio_sdl_src = 'client/audio_sdl.c'
-- 
2.53.0

