diff --git a/README.md b/README.md index b5fa70d2..afdea4d4 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 64ccce78..8a2877df 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -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(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}") + set(samplerate_lib_name samplerate) + set(installed_prefix ${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows${arch_suffix}/${path_prefix}) + + 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() diff --git a/cmake/Options.cmake b/cmake/Options.cmake index 5b8acdd4..7d1101b9 100644 --- a/cmake/Options.cmake +++ b/cmake/Options.cmake @@ -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) diff --git a/cmake/Set-Toolchain-vcpkg.cmake b/cmake/Set-Toolchain-vcpkg.cmake index 83336273..79097cda 100644 --- a/cmake/Set-Toolchain-vcpkg.cmake +++ b/cmake/Set-Toolchain-vcpkg.cmake @@ -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) diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index 693e9a58..58cce9e9 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -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(OPENAL_STATIC) - _add_compile_definitions(AL_LIBTYPE_STATIC) + 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() + + _add_include_directories(${OPENAL_INCLUDE_DIR}) + _add_link_libraries(${OPENAL_LIBRARY}) endif() - _add_include_directories(${OPENAL_INCLUDE_DIR}) - _add_link_libraries(${OPENAL_LIBRARY}) # XAudio2. if(ENABLE_XAUDIO2) diff --git a/src/wx/audio/audio.cpp b/src/wx/audio/audio.cpp index 0444748d..42d5e75f 100644 --- a/src/wx/audio/audio.cpp +++ b/src/wx/audio/audio.cpp @@ -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,11 +27,13 @@ namespace audio { std::vector 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(); + case config::AudioApi::kSDL: + return audio::internal::GetSDLDevices(); #if defined(__WXMSW__) case config::AudioApi::kDirectSound: @@ -59,8 +64,10 @@ std::vector EnumerateAudioDevices(const config::AudioApi& audio_api std::unique_ptr 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(); diff --git a/src/wx/config/internal/option-internal.cpp b/src/wx/config/internal/option-internal.cpp index dd5ad7e9..c4a0c21f 100644 --- a/src/wx/config/internal/option-internal.cpp +++ b/src/wx/config/internal/option-internal.cpp @@ -87,7 +87,9 @@ static const std::array kRenderMethodStrings = { // Adding an option without adding to this array will result in a compiler // error since kNbAudioApis is automatically updated. static const std::array kAudioApiStrings = { +#if defined(VBAM_ENABLE_OPENAL) "openal", +#endif "sdl_audio", #if defined(__WXMSW__) "directsound", @@ -223,10 +225,16 @@ std::array& 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 diff --git a/src/wx/dialogs/sound-config.cpp b/src/wx/dialogs/sound-config.cpp index 159b19bc..2a6110a7 100644 --- a/src/wx/dialogs/sound-config.cpp +++ b/src/wx/dialogs/sound-config.cpp @@ -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)); diff --git a/src/wx/opts.cpp b/src/wx/opts.cpp index a5013666..ae54b4d6 100644 --- a/src/wx/opts.cpp +++ b/src/wx/opts.cpp @@ -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()) {