foxygit / doom Log in
commit d6124484d7ff1c13189315603892cc6f8c0299d1
Author:     Turo Lamminen <turol@iki.fi>
AuthorDate: Tue Jul 12 20:48:51 2022 +0300
Commit:     Turo Lamminen <turol@iki.fi>
CommitDate: Tue Jul 12 21:09:37 2022 +0300

    Add option to disable SDL2_mixer
---
 CMakeLists.txt             |  8 ++++-
 configure.ac               |  9 ++++-
 opl/CMakeLists.txt         |  5 ++-
 opl/opl.c                  |  2 ++
 opl/opl_sdl.c              |  6 ++++
 pcsound/CMakeLists.txt     |  5 ++-
 pcsound/pcsound.c          |  2 ++
 pcsound/pcsound_sdl.c      |  6 ++++
 src/CMakeLists.txt         | 10 ++++--
 src/doom/CMakeLists.txt    |  5 ++-
 src/heretic/CMakeLists.txt |  5 ++-
 src/hexen/CMakeLists.txt   |  5 ++-
 src/i_musicpack.c          | 83 ++++++++++++++++++++++++++++++++++++++++++++++
 src/i_sdlmusic.c           |  5 +++
 src/i_sdlsound.c           |  5 +++
 src/i_sound.c              |  4 +++
 src/setup/CMakeLists.txt   |  5 ++-
 src/strife/CMakeLists.txt  |  5 ++-
 18 files changed, 164 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21b7d928..7f1eed09 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,9 +29,15 @@ else()
 endif()

 option(ENABLE_SDL2_NET "Enable SDL2_net" On)
+option(ENABLE_SDL2_MIXER "Enable SDL2_mixer" On)

 find_package(SDL2 2.0.7)
-find_package(SDL2_mixer 2.0.2)
+if(ENABLE_SDL2_MIXER)
+    find_package(SDL2_mixer 2.0.2)
+else()
+    add_compile_definitions(DISABLE_SDL2MIXER=1)
+endif()
+
 if(ENABLE_SDL2_NET)
     find_package(SDL2_net 2.0.0)
 else()
diff --git a/configure.ac b/configure.ac
index 3f3caa5c..fd5d8bce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,7 +32,14 @@ then
 fi

 PKG_CHECK_MODULES(SDL, [sdl2 >= 2.0.7])
-PKG_CHECK_MODULES(SDLMIXER, [SDL2_mixer >= 2.0.2])
+# Check for SDL2_mixer
+AC_ARG_ENABLE([sdl2mixer],
+AS_HELP_STRING([--disable-sdl2mixer], [Disable SDL2_mixer support])
+)
+AS_IF([test "x$enable_sdl2mixer" != xno], [
+    PKG_CHECK_MODULES(SDLMIXER, [SDL2_mixer >= 2.0.2])], [
+    AC_DEFINE([DISABLE_SDL2MIXER], [1], [SDL2_mixer disabled])
+])

 # Check for networking
 AC_ARG_ENABLE([sdl2net],
diff --git a/opl/CMakeLists.txt b/opl/CMakeLists.txt
index b109b3e7..151f7617 100644
--- a/opl/CMakeLists.txt
+++ b/opl/CMakeLists.txt
@@ -12,4 +12,7 @@ add_library(opl STATIC
 target_include_directories(opl
                            INTERFACE "."
                            PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
-target_link_libraries(opl SDL2::SDL2 SDL2::mixer)
+target_link_libraries(opl SDL2::SDL2)
+if(ENABLE_SDL2_mixer)
+    target_link_libraries(opl SDL2::mixer)
+endif()
diff --git a/opl/opl.c b/opl/opl.c
index a1aa1d95..8486dcab 100644
--- a/opl/opl.c
+++ b/opl/opl.c
@@ -50,7 +50,9 @@ static opl_driver_t *drivers[] =
 #ifdef _WIN32
     &opl_win32_driver,
 #endif
+#ifndef DISABLE_SDL2MIXER
     &opl_sdl_driver,
+#endif // DISABLE_SDL2MIXER
     NULL
 };

diff --git a/opl/opl_sdl.c b/opl/opl_sdl.c
index fc71be31..7d531ae4 100644
--- a/opl/opl_sdl.c
+++ b/opl/opl_sdl.c
@@ -33,6 +33,10 @@

 #include "opl_queue.h"

+
+#ifndef DISABLE_SDL2MIXER
+
+
 #define MAX_SOUND_SLICE_TIME 100 /* ms */

 typedef struct
@@ -511,3 +515,5 @@ opl_driver_t opl_sdl_driver =
     OPL_SDL_AdjustCallbacks,
 };

+
+#endif // DISABLE_SDL2MIXER
diff --git a/pcsound/CMakeLists.txt b/pcsound/CMakeLists.txt
index 06074430..9924263a 100644
--- a/pcsound/CMakeLists.txt
+++ b/pcsound/CMakeLists.txt
@@ -8,4 +8,7 @@ add_library(pcsound STATIC
 target_include_directories(pcsound
                            INTERFACE "."
                            PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
-target_link_libraries(pcsound SDL2::SDL2 SDL2::mixer)
+target_link_libraries(pcsound SDL2::SDL2)
+if(ENABLE_SDL2_mixer)
+    target_link_libraries(pcsound SDL2::mixer)
+endif()
diff --git a/pcsound/pcsound.c b/pcsound/pcsound.c
index c4dd9700..4695c378 100644
--- a/pcsound/pcsound.c
+++ b/pcsound/pcsound.c
@@ -56,7 +56,9 @@ static pcsound_driver_t *drivers[] =
 #ifdef _WIN32
     &pcsound_win32_driver,
 #endif
+#ifndef DISABLE_SDL2MIXER
     &pcsound_sdl_driver,
+#endif // DISABLE_SDL2MIXER
     NULL,
 };

diff --git a/pcsound/pcsound_sdl.c b/pcsound/pcsound_sdl.c
index c25ac7f9..4f413fed 100644
--- a/pcsound/pcsound_sdl.c
+++ b/pcsound/pcsound_sdl.c
@@ -24,6 +24,10 @@
 #include "pcsound.h"
 #include "pcsound_internal.h"

+
+#ifndef DISABLE_SDL2MIXER
+
+
 #define MAX_SOUND_SLICE_TIME 70 /* ms */
 #define SQUARE_WAVE_AMP 0x2000

@@ -248,3 +252,5 @@ pcsound_driver_t pcsound_sdl_driver =
     PCSound_SDL_Shutdown,
 };

+
+#endif // DISABLE_SDL2MIXER
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a78903c0..bbb87764 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -124,7 +124,10 @@ set(DEHACKED_SOURCE_FILES
 set(SOURCE_FILES ${COMMON_SOURCE_FILES} ${GAME_SOURCE_FILES})
 set(SOURCE_FILES_WITH_DEH ${SOURCE_FILES} ${DEHACKED_SOURCE_FILES})

-set(EXTRA_LIBS SDL2::SDL2main SDL2::SDL2 SDL2::mixer textscreen pcsound opl)
+set(EXTRA_LIBS SDL2::SDL2main SDL2::SDL2 textscreen pcsound opl)
+if(ENABLE_SDL2_MIXER)
+    list(APPEND EXTRA_LIBS SDL2::mixer)
+endif()
 if(ENABLE_SDL2_NET)
     list(APPEND EXTRA_LIBS SDL2::net)
 endif()
@@ -219,7 +222,10 @@ endif()

 target_include_directories("${PROGRAM_PREFIX}setup"
                            PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../")
-target_link_libraries("${PROGRAM_PREFIX}setup" SDL2::SDL2main SDL2::SDL2 SDL2::mixer setup textscreen)
+target_link_libraries("${PROGRAM_PREFIX}setup" SDL2::SDL2main SDL2::SDL2 setup textscreen)
+if(ENABLE_SDL2_mixer)
+    target_link_libraries("${PROGRAM_PREFIX}setup" SDL2::mixer)
+endif()
 if(ENABLE_SDL2_NET)
     target_link_libraries("${PROGRAM_PREFIX}setup" SDL2::net)
 endif()
diff --git a/src/doom/CMakeLists.txt b/src/doom/CMakeLists.txt
index 90f0d164..82b114b4 100644
--- a/src/doom/CMakeLists.txt
+++ b/src/doom/CMakeLists.txt
@@ -68,7 +68,10 @@ add_library(doom STATIC
             wi_stuff.c      wi_stuff.h)

 target_include_directories(doom PRIVATE "../" "${CMAKE_CURRENT_BINARY_DIR}/../../")
-target_link_libraries(doom SDL2::SDL2 SDL2::mixer)
+target_link_libraries(doom SDL2::SDL2)
+if(ENABLE_SDL2_mixer)
+    target_link_libraries(doom SDL2::mixer)
+endif()
 if(ENABLE_SDL2_NET)
     target_link_libraries(doom SDL2::net)
 endif()
diff --git a/src/heretic/CMakeLists.txt b/src/heretic/CMakeLists.txt
index 95942b5b..1ea060bf 100644
--- a/src/heretic/CMakeLists.txt
+++ b/src/heretic/CMakeLists.txt
@@ -54,7 +54,10 @@ add_library(heretic STATIC
             s_sound.c           s_sound.h)

 target_include_directories(heretic PRIVATE "../" "${CMAKE_CURRENT_BINARY_DIR}/../../")
-target_link_libraries(heretic textscreen SDL2::SDL2 SDL2::mixer)
+target_link_libraries(heretic textscreen SDL2::SDL2)
+if(ENABLE_SDL2_mixer)
+    target_link_libraries(heretic SDL2::mixer)
+endif()
 if(ENABLE_SDL2_NET)
     target_link_libraries(heretic SDL2::net)
 endif()
diff --git a/src/hexen/CMakeLists.txt b/src/hexen/CMakeLists.txt
index 03535e2e..0dbd170b 100644
--- a/src/hexen/CMakeLists.txt
+++ b/src/hexen/CMakeLists.txt
@@ -55,7 +55,10 @@ add_library(hexen STATIC
                                 xddefs.h)

 target_include_directories(hexen PRIVATE "../" "${CMAKE_CURRENT_BINARY_DIR}/../../")
-target_link_libraries(hexen SDL2::SDL2 SDL2::mixer)
+target_link_libraries(hexen SDL2::SDL2)
+if(ENABLE_SDL2_mixer)
+    target_link_libraries(hexen SDL2::mixer)
+endif()
 if(ENABLE_SDL2_NET)
     target_link_libraries(hexen SDL2::net)
 endif()
diff --git a/src/i_musicpack.c b/src/i_musicpack.c
index 2a3fd7c5..f2f62146 100644
--- a/src/i_musicpack.c
+++ b/src/i_musicpack.c
@@ -48,6 +48,9 @@
 char *music_pack_path = "";


+#ifndef DISABLE_SDL2MIXER
+
+
 #define MID_HEADER_MAGIC "MThd"
 #define MUS_HEADER_MAGIC "MUS\x1a"

@@ -1378,3 +1381,83 @@ music_module_t music_pack_module =
     I_MP_PollMusic,
 };

+
+#else // DISABLE_SDL2MIXER
+
+
+static boolean I_NULL_InitMusic(void)
+{
+    return false;
+}
+
+
+static void I_NULL_ShutdownMusic(void)
+{
+}
+
+
+static void I_NULL_SetMusicVolume(int volume)
+{
+}
+
+
+static void I_NULL_PauseSong(void)
+{
+}
+
+
+static void I_NULL_ResumeSong(void)
+{
+}
+
+
+static void *I_NULL_RegisterSong(void *data, int len)
+{
+    return NULL;
+}
+
+
+static void I_NULL_UnRegisterSong(void *handle)
+{
+}
+
+
+static void I_NULL_PlaySong(void *handle, boolean looping)
+{
+}
+
+
+static void I_NULL_StopSong(void)
+{
+}
+
+
+static boolean I_NULL_MusicIsPlaying(void)
+{
+    return false;
+}
+
+
+static void I_NULL_PollMusic(void)
+{
+}
+
+music_module_t music_pack_module =
+{
+    NULL,
+    0,
+    I_NULL_InitMusic,
+    I_NULL_ShutdownMusic,
+    I_NULL_SetMusicVolume,
+    I_NULL_PauseSong,
+    I_NULL_ResumeSong,
+    I_NULL_RegisterSong,
+    I_NULL_UnRegisterSong,
+    I_NULL_PlaySong,
+    I_NULL_StopSong,
+    I_NULL_MusicIsPlaying,
+    I_NULL_PollMusic,
+};
+
+
+#endif // DISABLE_SDL2MIXER
diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index 2e0647a6..d8407141 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -126,6 +126,9 @@ void I_InitTimidityConfig(void)
 }


+#ifndef DISABLE_SDL2MIXER
+
+
 #define MAXMIDLENGTH (96 * 1024)

 static boolean music_initialized = false;
@@ -591,3 +594,5 @@ music_module_t music_sdl_module =
     NULL,  // Poll
 };

+
+#endif // DISABLE_SDL2MIXER
diff --git a/src/i_sdlsound.c b/src/i_sdlsound.c
index 06697f2f..2d3186e8 100644
--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -53,6 +53,9 @@ int use_libsamplerate = 0;
 float libsamplerate_scale = 0.65f;


+#ifndef DISABLE_SDL2MIXER
+
+
 #define LOW_PASS_FILTER
 //#define DEBUG_DUMP_WAVS
 #define NUM_CHANNELS 16
@@ -1138,3 +1141,5 @@ sound_module_t sound_sdl_module =
     I_SDL_PrecacheSounds,
 };

+
+#endif // DISABLE_SDL2MIXER
diff --git a/src/i_sound.c b/src/i_sound.c
index 29f4f695..66fc39e8 100644
--- a/src/i_sound.c
+++ b/src/i_sound.c
@@ -99,7 +99,9 @@ static int snd_mport = 0;

 static sound_module_t *sound_modules[] =
 {
+#ifndef DISABLE_SDL2MIXER
     &sound_sdl_module,
+#endif // DISABLE_SDL2MIXER
     &sound_pcsound_module,
     NULL,
 };
@@ -108,7 +110,9 @@ static sound_module_t *sound_modules[] =

 static music_module_t *music_modules[] =
 {
+#ifndef DISABLE_SDL2MIXER
     &music_sdl_module,
+#endif // DISABLE_SDL2MIXER
     &music_opl_module,
     NULL,
 };
diff --git a/src/setup/CMakeLists.txt b/src/setup/CMakeLists.txt
index 4c27a07c..90df2114 100644
--- a/src/setup/CMakeLists.txt
+++ b/src/setup/CMakeLists.txt
@@ -15,4 +15,7 @@ add_library(setup STATIC
             txt_mouseinput.c    txt_mouseinput.h)

 target_include_directories(setup PRIVATE "../" "${CMAKE_CURRENT_BINARY_DIR}/../../")
-target_link_libraries(setup textscreen SDL2::SDL2 SDL2::mixer)
+target_link_libraries(setup textscreen SDL2::SDL2)
+if(ENABLE_SDL2_mixer)
+    target_link_libraries(setup SDL2::mixer)
+endif()
diff --git a/src/strife/CMakeLists.txt b/src/strife/CMakeLists.txt
index d7d03f44..37b17ade 100644
--- a/src/strife/CMakeLists.txt
+++ b/src/strife/CMakeLists.txt
@@ -70,7 +70,10 @@ set(STRIFE_SOURCES
 add_library(strife STATIC ${STRIFE_SOURCES})

 target_include_directories(strife PRIVATE "../" "../../win32/" "${CMAKE_CURRENT_BINARY_DIR}/../../")
-target_link_libraries(strife textscreen SDL2::SDL2 SDL2::mixer)
+target_link_libraries(strife textscreen SDL2::SDL2)
+if(ENABLE_SDL2_mixer)
+    target_link_libraries(strife SDL2::mixer)
+endif()
 if(ENABLE_SDL2_NET)
     target_link_libraries(strife SDL2::net)
 endif()