build: make OpenAL-Soft optional again
Add the CMake option `ENABLE_OPENAL` which defaults to `ON` except for 32 bit Windows builds, because OpenAL-Soft uses `avrt.dll` which is not available on Windows XP. Update README.md. Fix linking `libsamplerate` for the `x86-mingw-static` triplet which we use for 32 bit Windows XP builds. Make some minor fixes to SDL3 detection and SDL2 fallback. Clean up the audio API selection code paths. Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
parent
fd2c767319
commit
8ced18c22f
|
@ -166,7 +166,7 @@ And the following development libraries:
|
|||
- [ffmpeg](https://ffmpeg.org/) (optional, at least version `4.0.4`, for game recording)
|
||||
- [gettext](https://www.gnu.org/software/gettext/) and gettext-tools
|
||||
- [SDL2](https://www.libsdl.org/) (required)
|
||||
- [openal-soft](https://kcat.strangesoft.net/openal.html) (required, a sound interface)
|
||||
- [openal-soft](https://kcat.strangesoft.net/openal.html) (optional, a sound interface)
|
||||
- [wxWidgets](https://wxwidgets.org/) (required for GUI, 2.8 and non-stl builds are no longer supported)
|
||||
|
||||
On Linux and similar, you also need the version of GTK your wxWidgets is linked
|
||||
|
@ -216,6 +216,7 @@ cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_LINK=NO -G Ninja
|
|||
| `ENABLE_ONLINEUPDATES` | Enable online update checks | ON |
|
||||
| `ENABLE_LTO` | Compile with Link Time Optimization (gcc and clang only) | ON for release build |
|
||||
| `ENABLE_GBA_LOGGING` | Enable extended GBA logging | ON |
|
||||
| `ENABLE_OPENAL` | Enable openal-soft sound output for wxWidgets | ON, not 32 bit Win |
|
||||
| `ENABLE_XAUDIO2` | Enable xaudio2 sound output for wxWidgets (Windows only) | ON |
|
||||
| `ENABLE_FAUDIO` | Enable faudio sound output for wxWidgets, | ON, not 32 bit Win |
|
||||
| `ENABLE_ASAN` | Enable libasan sanitizers (by default address, only in debug mode) | OFF |
|
||||
|
|
|
@ -32,9 +32,16 @@ if((NOT ENABLE_SDL3) AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
|
|||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(path_prefix debug)
|
||||
endif()
|
||||
|
||||
set(samplerate_lib_name samplerate)
|
||||
set(installed_prefix ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows${arch_suffix}/${path_prefix})
|
||||
|
||||
SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "${installed_prefix}/lib/samplerate${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
if(MINGW)
|
||||
set(installed_prefix ${_VCPKG_INSTALLED_DIR}/${WINARCH}-mingw${arch_suffix}/${path_prefix})
|
||||
set(samplerate_lib_name lib${samplerate_lib_name})
|
||||
endif()
|
||||
|
||||
SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} "${installed_prefix}/lib/${samplerate_lib_name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
else()
|
||||
SET(SDL_LIBRARY_TEMP ${SDL_LIBRARY_TEMP} -lsamplerate)
|
||||
endif()
|
||||
|
|
|
@ -14,31 +14,6 @@ if(WIN32 OR APPLE)
|
|||
set(ENABLE_SDL_DEFAULT OFF)
|
||||
endif()
|
||||
|
||||
find_package(SDL3 QUIET)
|
||||
|
||||
if (NOT ${SDL3_FOUND})
|
||||
find_package(SDL2 REQUIRED)
|
||||
endif()
|
||||
|
||||
option(ENABLE_SDL3 "Use SDL3" "${SDL3_FOUND}")
|
||||
|
||||
option(ENABLE_GENERIC_FILE_DIALOGS "Use generic file dialogs" OFF)
|
||||
option(DISABLE_OPENGL "Disable OpenGL" OFF)
|
||||
option(ENABLE_SDL "Build the SDL port" ${ENABLE_SDL_DEFAULT})
|
||||
option(ENABLE_WX "Build the wxWidgets port" ${BUILD_DEFAULT})
|
||||
option(ENABLE_DEBUGGER "Enable the debugger" ON)
|
||||
option(ENABLE_ASAN "Enable -fsanitize=address by default. Requires debug build with GCC/Clang" OFF)
|
||||
|
||||
if(ENABLE_SDL3)
|
||||
set(CMAKE_C_FLAGS "-DENABLE_SDL3 ${CMAKE_C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "-DENABLE_SDL3 ${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
|
||||
if(DISABLE_OPENGL)
|
||||
set(CMAKE_C_FLAGS "-DNO_OPENGL -DNO_OGL ${CMAKE_C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "-DNO_OPENGL -DNO_OGL ${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
|
||||
# Static linking
|
||||
set(VBAM_STATIC_DEFAULT OFF)
|
||||
if(VCPKG_TARGET_TRIPLET MATCHES -static OR CMAKE_TOOLCHAIN_FILE MATCHES "mxe|-static")
|
||||
|
@ -65,6 +40,33 @@ if(VBAM_STATIC)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
find_package(SDL3 QUIET)
|
||||
|
||||
option(ENABLE_SDL3 "Use SDL3" "${SDL3_FOUND}")
|
||||
|
||||
if(ENABLE_SDL3)
|
||||
find_package(SDL3 CONFIG REQUIRED)
|
||||
else()
|
||||
find_package(SDL2 CONFIG REQUIRED)
|
||||
endif()
|
||||
|
||||
option(ENABLE_GENERIC_FILE_DIALOGS "Use generic file dialogs" OFF)
|
||||
option(DISABLE_OPENGL "Disable OpenGL" OFF)
|
||||
option(ENABLE_SDL "Build the SDL port" ${ENABLE_SDL_DEFAULT})
|
||||
option(ENABLE_WX "Build the wxWidgets port" ${BUILD_DEFAULT})
|
||||
option(ENABLE_DEBUGGER "Enable the debugger" ON)
|
||||
option(ENABLE_ASAN "Enable -fsanitize=address by default. Requires debug build with GCC/Clang" OFF)
|
||||
|
||||
if(ENABLE_SDL3)
|
||||
set(CMAKE_C_FLAGS "-DENABLE_SDL3 ${CMAKE_C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "-DENABLE_SDL3 ${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
|
||||
if(DISABLE_OPENGL)
|
||||
set(CMAKE_C_FLAGS "-DNO_OPENGL -DNO_OGL ${CMAKE_C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "-DNO_OPENGL -DNO_OGL ${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
|
||||
option(ENABLE_ASM "Enable x86 ASM related options" OFF)
|
||||
|
||||
# The ARM ASM core seems to be very buggy, see #98 and #54. Default to it being
|
||||
|
@ -156,6 +158,17 @@ if(WIN32)
|
|||
option(ENABLE_XAUDIO2 "Enable xaudio2 sound output for the wxWidgets port" ${XAUDIO2_DEFAULT})
|
||||
endif()
|
||||
|
||||
find_package(OpenAL QUIET)
|
||||
|
||||
set(OPENAL_DEFAULT ${OpenAL_FOUND})
|
||||
|
||||
if(MINGW AND X86)
|
||||
# OpenAL-Soft uses avrt.dll which is not available on Windows XP.
|
||||
set(OPENAL_DEFAULT OFF)
|
||||
endif()
|
||||
|
||||
option(ENABLE_OPENAL "Enable OpenAL-Soft sound output for the wxWidgets port" ${OPENAL_DEFAULT})
|
||||
|
||||
set(ENABLE_FAUDIO_DEFAULT OFF)
|
||||
|
||||
find_package(FAudio QUIET)
|
||||
|
|
|
@ -474,6 +474,10 @@ function(vcpkg_set_toolchain)
|
|||
|
||||
foreach(pkg ${VCPKG_DEPS})
|
||||
list(APPEND VCPKG_DEPS_QUALIFIED ${pkg}:${VCPKG_TARGET_TRIPLET})
|
||||
|
||||
if(VCPKG_TARGET_TRIPLET STREQUAL "x86-mingw-static")
|
||||
list(APPEND VCPKG_DEPS_QUALIFIED libsamplerate:x86-mingw-static)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(WIN32)
|
||||
|
|
|
@ -11,8 +11,6 @@ set(VBAM_WX_COMMON
|
|||
audio/internal/coreaudio.cpp
|
||||
audio/internal/sdl.cpp
|
||||
audio/internal/sdl.h
|
||||
audio/internal/openal.cpp
|
||||
audio/internal/openal.h
|
||||
background-input.cpp
|
||||
background-input.h
|
||||
cmdevents.cpp
|
||||
|
@ -188,13 +186,15 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
|
|||
set(wxWidgets_LIB_DIR "${wxWidgets_LIB_DIR}" CACHE INTERNAL "wxWidgets library directory" FORCE)
|
||||
endif()
|
||||
|
||||
# Find OpenAL (required).
|
||||
find_package(OpenAL REQUIRED)
|
||||
if(ENABLE_OPENAL)
|
||||
find_package(OpenAL REQUIRED)
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
find_library(FMT_LIBRARY NAMES fmtd fmt)
|
||||
else()
|
||||
find_library(FMT_LIBRARY fmt)
|
||||
target_sources(visualboyadvance-m PRIVATE
|
||||
audio/internal/openal.cpp
|
||||
audio/internal/openal.h
|
||||
)
|
||||
|
||||
target_compile_definitions(visualboyadvance-m PRIVATE VBAM_ENABLE_OPENAL)
|
||||
endif()
|
||||
|
||||
# Workaround of static liblzma not being found on MSYS2.
|
||||
|
@ -288,19 +288,28 @@ function(configure_wx_target target)
|
|||
endif()
|
||||
|
||||
# OpenAL.
|
||||
if(ENABLE_OPENAL)
|
||||
if(OPENAL_STATIC)
|
||||
_add_compile_definitions(AL_LIBTYPE_STATIC)
|
||||
endif()
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
find_library(FMT_LIBRARY NAMES fmtd fmt)
|
||||
else()
|
||||
find_library(FMT_LIBRARY fmt)
|
||||
endif()
|
||||
|
||||
if(FMT_LIBRARY)
|
||||
list(APPEND OPENAL_LIBRARY ${FMT_LIBRARY} avrt)
|
||||
list(APPEND OPENAL_LIBRARY ${FMT_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND OPENAL_LIBRARY avrt)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
_add_include_directories(${OPENAL_INCLUDE_DIR})
|
||||
_add_link_libraries(${OPENAL_LIBRARY})
|
||||
endif()
|
||||
|
||||
# XAudio2.
|
||||
if(ENABLE_XAUDIO2)
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
#include "core/base/check.h"
|
||||
#include "wx/audio/internal/sdl.h"
|
||||
|
||||
#if defined(VBAM_ENABLE_OPENAL)
|
||||
#include "wx/audio/internal/openal.h"
|
||||
#endif
|
||||
|
||||
#if defined(__WXMSW__)
|
||||
#include "wx/audio/internal/dsound.h"
|
||||
|
@ -24,8 +27,10 @@ namespace audio {
|
|||
|
||||
std::vector<AudioDevice> EnumerateAudioDevices(const config::AudioApi& audio_api) {
|
||||
switch (audio_api) {
|
||||
#if defined(VBAM_ENABLE_OPENAL)
|
||||
case config::AudioApi::kOpenAL:
|
||||
return audio::internal::GetOpenALDevices();
|
||||
#endif
|
||||
|
||||
case config::AudioApi::kSDL:
|
||||
return audio::internal::GetSDLDevices();
|
||||
|
@ -59,8 +64,10 @@ std::vector<AudioDevice> EnumerateAudioDevices(const config::AudioApi& audio_api
|
|||
|
||||
std::unique_ptr<SoundDriver> CreateSoundDriver(const config::AudioApi& api) {
|
||||
switch (api) {
|
||||
#if defined(VBAM_ENABLE_OPENAL)
|
||||
case config::AudioApi::kOpenAL:
|
||||
return audio::internal::CreateOpenALDriver();
|
||||
#endif
|
||||
|
||||
case config::AudioApi::kSDL:
|
||||
return audio::internal::CreateSDLDriver();
|
||||
|
|
|
@ -87,7 +87,9 @@ static const std::array<wxString, kNbRenderMethods> kRenderMethodStrings = {
|
|||
// Adding an option without adding to this array will result in a compiler
|
||||
// error since kNbAudioApis is automatically updated.
|
||||
static const std::array<wxString, kNbAudioApis> kAudioApiStrings = {
|
||||
#if defined(VBAM_ENABLE_OPENAL)
|
||||
"openal",
|
||||
#endif
|
||||
"sdl_audio",
|
||||
#if defined(__WXMSW__)
|
||||
"directsound",
|
||||
|
@ -223,10 +225,16 @@ std::array<Option, kNbOptions>& Option::All() {
|
|||
bool allow_joystick_background_input = true;
|
||||
|
||||
/// Sound
|
||||
#if defined(VBAM_ENABLE_XAUDIO2)
|
||||
#if defined(__WXMAC__)
|
||||
AudioApi audio_api = AudioApi::kCoreAudio;
|
||||
#elif defined(VBAM_ENABLE_FAUDIO)
|
||||
AudioApi audio_api = AudioApi::kFAudio;
|
||||
#elif defined(VBAM_ENABLE_XAUDIO2)
|
||||
AudioApi audio_api = AudioApi::kXAudio2;
|
||||
#else
|
||||
#elif defined(VBAM_ENABLE_OPENAL)
|
||||
AudioApi audio_api = AudioApi::kOpenAL;
|
||||
#else
|
||||
AudioApi audio_api = AudioApi::kSDL;
|
||||
#endif
|
||||
wxString audio_dev;
|
||||
// 10 fixes stuttering on mac with openal, as opposed to 5
|
||||
|
|
|
@ -153,10 +153,14 @@ SoundConfig::SoundConfig(wxWindow* parent) : BaseDialog(parent, "SoundConfig") {
|
|||
|
||||
// Audio API selection.
|
||||
wxWindow* audio_api_button = GetValidatedChild("OpenAL");
|
||||
#if defined(VBAM_ENABLE_OPENAL)
|
||||
audio_api_button->SetValidator(AudioApiValidator(config::AudioApi::kOpenAL));
|
||||
audio_api_button->Bind(wxEVT_RADIOBUTTON,
|
||||
std::bind(&SoundConfig::OnAudioApiChanged, this, std::placeholders::_1,
|
||||
config::AudioApi::kOpenAL));
|
||||
#else
|
||||
audio_api_button->Hide();
|
||||
#endif
|
||||
|
||||
audio_api_button = GetValidatedChild("SDL");
|
||||
audio_api_button->SetValidator(AudioApiValidator(config::AudioApi::kSDL));
|
||||
|
|
|
@ -251,19 +251,6 @@ void load_opts(bool first_time_launch) {
|
|||
// config file will be updated with unset options
|
||||
cfg->SetRecordDefaults();
|
||||
|
||||
// Deprecated / moved options handling.
|
||||
{
|
||||
// The SDL audio API is no longer supported.
|
||||
wxString temp;
|
||||
if (cfg->Read("Sound/AudioAPI", &temp) && temp == "sdl") {
|
||||
#if defined(VBAM_ENABLE_XAUDIO2)
|
||||
cfg->Write("Sound/AudioAPI", "xaudio2");
|
||||
#else
|
||||
cfg->Write("Sound/AudioAPI", "openal");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// First access here will also initialize translations.
|
||||
for (config::Option& opt : config::Option::All()) {
|
||||
switch (opt.type()) {
|
||||
|
|
Loading…
Reference in New Issue