From cf474e99aa8d654053ab07460a78beb8b91b13d2 Mon Sep 17 00:00:00 2001 From: Martin Plicht Date: Sun, 21 Sep 2014 21:46:12 +0200 Subject: [PATCH] mac: Rearrange sound toolkit includes and FindAudio.cmake so that sound+music works for OSX --- CMakeLists.txt | 5 +++-- cmake/FindAudio.cmake | 34 ++++++++++++---------------- src/platform/C4MusicFile.h | 10 ++------- src/platform/C4MusicSystem.cpp | 13 ----------- src/platform/C4MusicSystem.h | 6 +---- src/platform/C4SoundIncludes.h | 40 +++++++++++++++++++++++++++++++++ src/platform/C4SoundLoaders.cpp | 14 ------------ src/platform/C4SoundLoaders.h | 5 ----- src/platform/C4SoundSystem.h | 13 +---------- 9 files changed, 61 insertions(+), 79 deletions(-) create mode 100644 src/platform/C4SoundIncludes.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ff19b4668..524f575bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -435,6 +435,7 @@ set(OC_CLONK_SOURCES src/platform/C4MusicSystem.h src/platform/C4SoundLoaders.cpp src/platform/C4SoundLoaders.h + src/platform/C4SoundIncludes.h src/platform/C4SoundSystem.cpp src/platform/C4SoundSystem.h src/platform/C4TimeMilliseconds.cpp @@ -1109,7 +1110,7 @@ if(UNIX AND NOT APPLE) endif() endif() set_property(TARGET openclonk APPEND PROPERTY COMPILE_DEFINITIONS GLEW_STATIC) -set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG) +#set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG) # This expands some variables in Info.plist as a side-effect. XCode might then # expand a second time, using the same syntax. Try not to get confused by this! @@ -1314,7 +1315,7 @@ if(USE_X11) ) endif() if(USE_COCOA) - TARGET_LINK_LIBRARIES(openclonk "-framework Cocoa -framework AppKit -framework Quartz") + TARGET_LINK_LIBRARIES(openclonk "-framework Cocoa -framework AppKit -framework Quartz -framework OpenAL -framework AudioToolBox") endif() if (WIN32) # CMake is too incompetent to check whether these libraries can be linked to diff --git a/cmake/FindAudio.cmake b/cmake/FindAudio.cmake index ed36907fc..56bc6d473 100644 --- a/cmake/FindAudio.cmake +++ b/cmake/FindAudio.cmake @@ -15,13 +15,13 @@ macro(__FINDAUDIO_FINDOPENAL) find_package(PkgConfig QUIET) - if(PKG_CONFIG_FOUND) + if(PKG_CONFIG_FOUND AND NOT(APPLE)) pkg_check_modules(OpenAL "openal>=1.15.1") pkg_check_modules(Alut "freealut>=1.1.0") pkg_check_modules(OggVorbis "vorbisfile>=1.3.2" "vorbis>=1.3.2" "ogg>=1.3.0") else() if(MSVC OR APPLE) - find_path(OpenAL_INCLUDE_DIRS al.h PATH_SUFFIXES include/AL include/OpenAL include) + find_path(OpenAL_INCLUDE_DIRS al.h PATH_SUFFIXES include/AL include/OpenAL include OpenAL) find_path(Vorbis_INCLUDE_DIRS vorbis/codec.h vorbis/vorbisfile.h PATH_SUFFIXES include) find_library(Ogg_LIBRARY NAMES libogg_static libogg ogg) find_library(Vorbis_LIBRARY NAMES libvorbis_static libvorbis vorbis) @@ -34,17 +34,17 @@ macro(__FINDAUDIO_FINDOPENAL) set(OggVorbis_LIBRARIES ${Vorbisfile_LIBRARY} ${Vorbis_LIBRARY} ${Ogg_LIBRARY}) set(OggVorbis_INCLUDE_DIRS(${Vorbis_INCLUDE_DIRS})) endif() - endif() - if(MSVC) find_path(Alut_INCLUDE_DIRS alut.h PATH_SUFFIXES include/AL include/OpenAL include) find_library(Alut_LIBRARY NAMES alut_static alut) - if(${FIND_LIBRARY_USE_LIB64_PATHS}) - find_library(OpenAL_LIBRARY NAMES OpenAL64) - else() - find_library(OpenAL_LIBRARY NAMES OpenAL32) - endif() - if(NOT OpenAL_LIBRARY) - set(OpenAL_FOUND FALSE) + if (MSVC) + if(${FIND_LIBRARY_USE_LIB64_PATHS}) + find_library(OpenAL_LIBRARY NAMES OpenAL64) + else() + find_library(OpenAL_LIBRARY NAMES OpenAL32) + endif() + if(NOT OpenAL_LIBRARY) + set(OpenAL_FOUND FALSE) + endif() endif() if(Alut_INCLUDE_DIRS AND Alut_LIBRARY) set(Alut_FOUND TRUE) @@ -73,7 +73,7 @@ else() __FINDAUDIO_FINDSDLMIXER() find_package("FMod") - if(OpenAL_FOUND AND (APPLE OR Alut_FOUND) AND OggVorbis_FOUND) + if(OpenAL_FOUND AND Alut_FOUND AND OggVorbis_FOUND) # Prefer OpenAL set(Audio_TK "OpenAL") elseif(SDLMixer_FOUND) @@ -92,14 +92,8 @@ if(Audio_TK STREQUAL "OpenAL") set(Audio_FOUND TRUE) set(Audio_LIBRARIES ${OpenAL_LIBRARIES} ${OggVorbis_LIBRARIES}) set(Audio_INCLUDE_DIRS ${OpenAL_INCLUDE_DIRS} ${OggVorbis_INCLUDE_DIRS}) - if (NOT APPLE) - # Apple doesn't need freealut - set(Audio_LIBRARIES ${Audio_LIBRARIES} ${Alut_LIBRARIES} ${OpenAL_LIBRARY}) - set(Audio_INCLUDE_DIRS ${Audio_INCLUDE_DIRS} ${Alut_INCLUDE_DIRS}) - else() - # but it uses the AudioToolBox framework - set(Audio_LIBRARIES ${Audio_LIBRARIES} "-framework OpenAL -framework AudioToolBox") - endif() + set(Audio_LIBRARIES ${Audio_LIBRARIES} ${Alut_LIBRARIES}) + set(Audio_INCLUDE_DIRS ${Audio_INCLUDE_DIRS} ${Alut_INCLUDE_DIRS}) endif() elseif(Audio_TK STREQUAL "SDL_Mixer") __FINDAUDIO_FINDSDLMIXER() diff --git a/src/platform/C4MusicFile.h b/src/platform/C4MusicFile.h index 23ff2e2e6..63ed327d8 100644 --- a/src/platform/C4MusicFile.h +++ b/src/platform/C4MusicFile.h @@ -18,15 +18,9 @@ #ifndef INC_C4MusicFile #define INC_C4MusicFile -#if AUDIO_TK == AUDIO_TK_FMOD -#include -#elif AUDIO_TK == AUDIO_TK_SDL_MIXER -#define USE_RWOPS -#include -#undef USE_RWOPS -#elif AUDIO_TK == AUDIO_TK_OPENAL +#include #include -#endif + /* Base class */ class C4MusicFile diff --git a/src/platform/C4MusicSystem.cpp b/src/platform/C4MusicSystem.cpp index 4d771ca72..aa8b5fc9d 100644 --- a/src/platform/C4MusicSystem.cpp +++ b/src/platform/C4MusicSystem.cpp @@ -28,19 +28,6 @@ #include #include -#if AUDIO_TK == AUDIO_TK_FMOD -#include -#elif AUDIO_TK == AUDIO_TK_SDL_MIXER -#include -#elif AUDIO_TK == AUDIO_TK_OPENAL && !defined(APPLE) -#ifdef _WIN32 -// This is an ugly hack to make FreeALUT not dllimport everything. -#define _XBOX -#endif -#include -#undef _XBOX -#endif - C4MusicSystem::C4MusicSystem(): Songs(NULL), SongCount(0), diff --git a/src/platform/C4MusicSystem.h b/src/platform/C4MusicSystem.h index a1125f114..136cf361d 100644 --- a/src/platform/C4MusicSystem.h +++ b/src/platform/C4MusicSystem.h @@ -21,11 +21,7 @@ #define INC_C4MusicSystem #include - -#if AUDIO_TK == AUDIO_TK_OPENAL -#include -#include -#endif +#include class C4MusicFileInfoNode; class C4MusicFile; diff --git a/src/platform/C4SoundIncludes.h b/src/platform/C4SoundIncludes.h new file mode 100644 index 000000000..42abb2c14 --- /dev/null +++ b/src/platform/C4SoundIncludes.h @@ -0,0 +1,40 @@ +// Put all the terrible walls of includes for sound toolkits here + +#ifndef INC_C4SoundIncludes +#define INC_C4SoundIncludes + +#if AUDIO_TK == AUDIO_TK_FMOD +# include + typedef FSOUND_SAMPLE* C4SoundHandle; +# include +#elif AUDIO_TK == AUDIO_TK_SDL_MIXER +# define USE_RWOPS +# include +# undef USE_RWOPS + typedef struct Mix_Chunk* C4SoundHandle; +# include +#elif AUDIO_TK == AUDIO_TK_OPENAL +# ifdef __APPLE__ +# include +# else +# include +# endif + typedef ALuint C4SoundHandle; +# ifdef _WIN32 + // This is an ugly hack to make FreeALUT not dllimport everything. +# define _XBOX +# endif +# include +# undef _XBOX +# if defined(__APPLE__) +# import +# import +# endif +# include +# include +# include +#else + typedef void* C4SoundHandle; +#endif + +#endif \ No newline at end of file diff --git a/src/platform/C4SoundLoaders.cpp b/src/platform/C4SoundLoaders.cpp index 387f94b79..b5bddb80e 100644 --- a/src/platform/C4SoundLoaders.cpp +++ b/src/platform/C4SoundLoaders.cpp @@ -19,20 +19,6 @@ #include -#if AUDIO_TK == AUDIO_TK_OPENAL -#if defined(__APPLE__) -#import -#import -#else -#ifdef _WIN32 -// This is an ugly hack to make FreeALUT not dllimport everything. -#define _XBOX -#endif -#include -#undef _XBOX -#endif -#endif - using namespace C4SoundLoaders; diff --git a/src/platform/C4SoundLoaders.h b/src/platform/C4SoundLoaders.h index 3d23a8f7e..408dce9ef 100644 --- a/src/platform/C4SoundLoaders.h +++ b/src/platform/C4SoundLoaders.h @@ -16,11 +16,6 @@ #ifndef INC_C4SoundLoaders #define INC_C4SoundLoaders -#if AUDIO_TK == AUDIO_TK_OPENAL -#include -#include -#endif - #include #include diff --git a/src/platform/C4SoundSystem.h b/src/platform/C4SoundSystem.h index 1460e918c..4be8c2b90 100644 --- a/src/platform/C4SoundSystem.h +++ b/src/platform/C4SoundSystem.h @@ -21,6 +21,7 @@ #define INC_C4SoundSystem #include +#include const int32_t C4MaxSoundName=100, @@ -31,18 +32,6 @@ const int32_t class C4Object; class C4SoundInstance; -#if AUDIO_TK == AUDIO_TK_FMOD -#include -typedef FSOUND_SAMPLE* C4SoundHandle; -#elif AUDIO_TK == AUDIO_TK_SDL_MIXER -typedef struct Mix_Chunk* C4SoundHandle; -#elif AUDIO_TK == AUDIO_TK_OPENAL -#include -typedef ALuint C4SoundHandle; -#else -typedef void* C4SoundHandle; -#endif - class C4SoundEffect { friend class C4SoundInstance;