diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f8ebfa9f2e..281be10b92 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,6 +19,8 @@ if( CMAKE_COMPILER_IS_GNUCXX ) endif( APPLE ) endif( CMAKE_COMPILER_IS_GNUCXX ) +option( DYN_FLUIDSYNTH "Dynamically load fluidsynth" ) + if( CMAKE_SIZEOF_VOID_P MATCHES "8" ) set( X64 64 ) endif( CMAKE_SIZEOF_VOID_P MATCHES "8" ) @@ -490,8 +492,10 @@ set( ZDOOM_LIBS ${ZDOOM_LIBS} "${ZLIB_LIBRARIES}" "${JPEG_LIBRARIES}" "${BZIP2_L include_directories( "${ZLIB_INCLUDE_DIR}" "${FMOD_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" ) if( FLUIDSYNTH_FOUND ) + if( NOT DYN_FLUIDSYNTH) set( ZDOOM_LIBS ${ZDOOM_LIBS} "${FLUIDSYNTH_LIBRARIES}" ) include_directories( "${FLUIDSYNTH_INCLUDE_DIR}" ) + endif( NOT DYN_FLUIDSYNTH ) endif( FLUIDSYNTH_FOUND ) # Start defining source files for ZDoom @@ -587,9 +591,11 @@ else( SSE_MATTERS ) set( X86_SOURCES ) endif( SSE_MATTERS ) -if( FLUIDSYNTH_FOUND ) +if( DYN_FLUIDSYNTH ) + add_definitions( -DHAVE_FLUIDSYNTH -DDYN_FLUIDSYNTH ) +elseif( FLUIDSYNTH_FOUND ) add_definitions( -DHAVE_FLUIDSYNTH ) -endif( FLUIDSYNTH_FOUND ) +endif( DYN_FLUIDSYNTH ) add_executable( zdoom WIN32 autostart.cpp diff --git a/src/sound/i_musicinterns.h b/src/sound/i_musicinterns.h index 041e3db00e..18b6937dfc 100644 --- a/src/sound/i_musicinterns.h +++ b/src/sound/i_musicinterns.h @@ -347,6 +347,8 @@ protected: #ifdef _WIN32 HMODULE FluidSynthDLL; +#else + void *FluidSynthSO; #endif bool LoadFluidSynth(); void UnloadFluidSynth(); diff --git a/src/sound/music_fluidsynth_mididevice.cpp b/src/sound/music_fluidsynth_mididevice.cpp index 6cb576b187..fb573f2fb9 100644 --- a/src/sound/music_fluidsynth_mididevice.cpp +++ b/src/sound/music_fluidsynth_mididevice.cpp @@ -54,7 +54,9 @@ #define FLUIDSYNTHLIB "fluidsynth64.dll" #endif #else -#error "TODO: Write a dlopen() version of this code." +#include + +#define FLUIDSYNTHLIB "libfluidsynth.so.1" #endif #endif @@ -892,24 +894,33 @@ bool FluidSynthMIDIDevice::LoadFluidSynth() #ifdef _WIN32 FluidSynthDLL = LoadLibrary(FLUIDSYNTHLIB); -#endif if (FluidSynthDLL == NULL) { Printf(TEXTCOLOR_RED"Could not load " FLUIDSYNTHLIB "\n"); return false; } +#else + FluidSynthSO = dlopen(FLUIDSYNTHLIB, RTLD_LAZY); + if (FluidSynthSO == NULL) + { + Printf(TEXTCOLOR_RED"Could not load " FLUIDSYNTHLIB ": %s\n", dlerror()); + return false; + } +#endif for (int i = 0; i < countof(imports); ++i) { #ifdef _WIN32 FARPROC proc = GetProcAddress(FluidSynthDLL, imports[i].FuncName); +#else + void *proc = dlsym(FluidSynthSO, imports[i].FuncName); +#endif if (proc == NULL) { Printf(TEXTCOLOR_RED"Failed to find %s in %s\n", imports[i].FuncName, FLUIDSYNTHLIB); fail++; } *imports[i].FuncPointer = proc; -#endif } if (fail == 0) { @@ -920,6 +931,9 @@ bool FluidSynthMIDIDevice::LoadFluidSynth() #ifdef _WIN32 FreeLibrary(FluidSynthDLL); FluidSynthDLL = NULL; +#else + dlclose(FluidSynthSO); + FluidSynthSO = NULL; #endif return false; } @@ -940,6 +954,12 @@ void FluidSynthMIDIDevice::UnloadFluidSynth() FreeLibrary(FluidSynthDLL); FluidSynthDLL = NULL; } +#else + if (FluidSynthSO != NULL) + { + dlclose(FluidSynthSO); + FluidSynthSO = NULL; + } #endif }