diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5d20ddf7c..a8e43bcf3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -217,20 +217,10 @@ endif() if( NOT NO_OPENAL ) find_package( OpenAL ) mark_as_advanced(CLEAR OPENAL_INCLUDE_DIR) - if( NOT WIN32 ) - mark_as_advanced(CLEAR OPENAL_LIBRARY) - endif() - if( OPENAL_FOUND ) + if( OPENAL_INCLUDE_DIR ) include_directories( ${OPENAL_INCLUDE_DIR} ) - if( NOT WIN32 ) - set( ZDOOM_LIBS ${OPENAL_LIBRARY} ${ZDOOM_LIBS} ) - endif() else() - if ( NOT WIN32 ) - set( NO_OPENAL ON ) - else() - include_directories( ${OPENAL_INCLUDE_DIR} ) - endif() + set( NO_OPENAL ON ) endif() endif() diff --git a/src/sound/oalload.h b/src/sound/oalload.h index 7d4e62287..986131b2c 100644 --- a/src/sound/oalload.h +++ b/src/sound/oalload.h @@ -1,7 +1,11 @@ #ifndef OALDEF_H #define OALDEF_H -#if defined _WIN32 && !defined NO_OPENAL +#ifndef NO_OPENAL + +#ifndef _WIN32 +typedef void* FARPROC; +#endif #define DEFINE_ENTRY(type, name) static type p_##name; #include "oaldef.h" diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index a5ec97f97..6030c9142 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -36,6 +36,8 @@ #define WIN32_LEAN_AND_MEAN #include #define USE_WINDOWS_DWORD +#else +#include #endif #include "except.h" @@ -61,14 +63,23 @@ CVAR (Bool, snd_efx, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) #ifdef _WIN32 static HMODULE hmodOpenAL; +#define OPENALLIB "openal32.dll" +#else +static void* hmodOpenAL; +#ifdef __APPLE__ +#define OPENALLIB "OpenAL.framework/OpenAL" +#else +#define OPENALLIB "libopenal.so" +#endif +#define LoadLibrary(x) dlopen((x), RTLD_LAZY) +#define GetProcAddress(a,b) dlsym((a),(b)) +#define FreeLibrary(x) dlclose((x)) #endif bool IsOpenALPresent() { #ifdef NO_OPENAL return false; -#elif !defined _WIN32 - return true; #else static bool cached_result = false; static bool done = false; @@ -78,10 +89,10 @@ bool IsOpenALPresent() done = true; if (hmodOpenAL == NULL) { - hmodOpenAL = LoadLibrary(NicePath("$PROGDIR/openal32.dll")); + hmodOpenAL = LoadLibrary(NicePath("$PROGDIR/" OPENALLIB)); if (hmodOpenAL == NULL) { - hmodOpenAL = LoadLibrary("openal32.dll"); + hmodOpenAL = LoadLibrary(OPENALLIB); if (hmodOpenAL == NULL) { return false; @@ -90,7 +101,7 @@ bool IsOpenALPresent() for(int i = 0; oalfuncs[i].name != NULL; i++) { *oalfuncs[i].funcaddr = GetProcAddress(hmodOpenAL, oalfuncs[i].name); - if (oalfuncs[i].funcaddr == NULL) + if (*oalfuncs[i].funcaddr == NULL) { FreeLibrary(hmodOpenAL); hmodOpenAL = NULL;