mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 23:01:50 +00:00
- Added a dlopen() version of on-demand FluidSynth loading and exposed it
to CMake through the DYN_FLUIDSYNTH option. SVN r2558 (trunk)
This commit is contained in:
parent
f389cd8b0f
commit
a68e9c8fa6
3 changed files with 33 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -347,6 +347,8 @@ protected:
|
|||
|
||||
#ifdef _WIN32
|
||||
HMODULE FluidSynthDLL;
|
||||
#else
|
||||
void *FluidSynthSO;
|
||||
#endif
|
||||
bool LoadFluidSynth();
|
||||
void UnloadFluidSynth();
|
||||
|
|
|
@ -54,7 +54,9 @@
|
|||
#define FLUIDSYNTHLIB "fluidsynth64.dll"
|
||||
#endif
|
||||
#else
|
||||
#error "TODO: Write a dlopen() version of this code."
|
||||
#include <dlfcn.h>
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue