Skip to content

Commit

Permalink
audio: add build options for audio backend support
Browse files Browse the repository at this point in the history
The added build options USE_ALSA, USE_LIBAO, USE_OSS and USE_PULSEAUDIO allow to
enable/disable specific audio backends in the build. This provides more control
over the used dependencies.

The OSS backend wasn't enabled in the previous build configuration, consequently
the build option USE_OSS is set to OFF by default.
  • Loading branch information
bsdcode authored and flyinghead committed Nov 14, 2024
1 parent 42ad553 commit e2f8de3
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ option(USE_DX11 "Build with Direct3D 11 support" ON)
option(LIBRETRO "Build libretro core" OFF)
option(USE_OPENGL "Use OpenGL API" ON)
option(USE_VIDEOCORE "RPI: use the legacy Broadcom GLES libraries" OFF)
option(USE_ALSA "Build with ALSA support" ON)
option(USE_LIBAO "Build with AO support" ON)
option(USE_OSS "Build with OSS support" OFF)
option(USE_PULSEAUDIO "Build with PulseAudio support" ON)
option(USE_BREAKPAD "Build and link with breakpad library" ON)
option(ENABLE_GDB_SERVER "Build with GDB debugging support" OFF)
option(ENABLE_DC_PROFILER "Build with support for target machine (SH4) profiler" OFF)
Expand Down Expand Up @@ -411,11 +415,17 @@ if(USE_VULKAN)
endif()

if(NOT LIBRETRO)
find_package(ALSA)
if(ALSA_FOUND AND NOT ANDROID)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_ALSA)
target_include_directories(${PROJECT_NAME} PRIVATE ${ALSA_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${ALSA_LIBRARIES})
if(USE_OSS)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_OSS)
endif()

if(USE_ALSA)
find_package(ALSA)
if(ALSA_FOUND AND NOT ANDROID)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_ALSA)
target_include_directories(${PROJECT_NAME} PRIVATE ${ALSA_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${ALSA_LIBRARIES})
endif()
endif()

if(MINGW)
Expand Down Expand Up @@ -489,10 +499,12 @@ endif()

find_package(PkgConfig)
if(PKG_CONFIG_FOUND AND NOT ANDROID AND NOT APPLE AND NOT LIBRETRO)
pkg_check_modules(AO IMPORTED_TARGET ao)
if(AO_FOUND)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_LIBAO)
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::AO)
if(USE_LIBAO)
pkg_check_modules(AO IMPORTED_TARGET ao)
if(AO_FOUND)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_LIBAO)
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::AO)
endif()
endif()

if(NOT SDL2_FOUND)
Expand All @@ -509,10 +521,12 @@ if(PKG_CONFIG_FOUND AND NOT ANDROID AND NOT APPLE AND NOT LIBRETRO)
endif()
endif()

pkg_check_modules(LIBPULSE IMPORTED_TARGET libpulse)
if(LIBPULSE_FOUND)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_PULSEAUDIO)
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::LIBPULSE)
if(USE_PULSEAUDIO)
pkg_check_modules(LIBPULSE IMPORTED_TARGET libpulse)
if(LIBPULSE_FOUND)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_PULSEAUDIO)
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::LIBPULSE)
endif()
endif()

if(USE_HOST_LIBZIP)
Expand Down

2 comments on commit e2f8de3

@crashGG
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, could add xaudio,wasapi to windows build? On Windows 10/11, wasapi has the lowest latency and the smallest system overhead.

@flyinghead
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just build options for existing audio backends. I don't plan on supporting additional ones. The default is to use SDL, which is supposed to select the best underlying backend on a given platform.

Please sign in to comment.