diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b8c4b1491..aa13fbafb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -440,19 +440,6 @@ else() message(STATUS "bluez explicitly disabled, disabling bluetooth support") endif() -if(ENABLE_PULSEAUDIO) - check_lib(PULSEAUDIO libpulse pulse QUIET) - if(PULSEAUDIO_FOUND) - add_definitions(-DHAVE_PULSEAUDIO=1) - message(STATUS "PulseAudio found, enabling PulseAudio sound backend") - else() - add_definitions(-DHAVE_PULSEAUDIO=0) - message(STATUS "PulseAudio NOT found, disabling PulseAudio sound backend") - endif() -else() - message(STATUS "PulseAudio explicitly disabled, disabling PulseAudio sound backend") -endif() - if(ENABLE_LLVM) find_package(LLVM) if (LLVM_FOUND) diff --git a/CMakeTests/FindPulseAudio.cmake b/CMakeTests/FindPulseAudio.cmake new file mode 100644 index 0000000000..6046898cc4 --- /dev/null +++ b/CMakeTests/FindPulseAudio.cmake @@ -0,0 +1,42 @@ +# - Find PulseAudio library +# This module defines +# PulseAudio_INCLUDE_DIR +# PulseAudio_LIBRARIES +# PulseAudio_FOUND +# +# vim: expandtab sw=4 ts=4 sts=4: + +include(FindPkgConfig) +pkg_check_modules (PulseAudio_PKG QUIET libpulse) + +find_path(PulseAudio_INCLUDE_DIR NAMES pulse/pulseaudio.h + PATHS + ${PulseAudio_PKG_INCLUDE_DIRS} + /usr/include/pulse + /usr/include + /usr/local/include/pulse + /usr/local/include +) + +find_library(PulseAudio_LIBRARIES NAMES pulse + PATHS + ${PulseAudio_PKG_LIBRARY_DIRS} + /usr/lib + /usr/local/lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PulseAudio + REQUIRED_VARS PulseAudio_LIBRARIES PulseAudio_INCLUDE_DIR) + +if(PulseAudio_FOUND) + if(NOT TARGET PulseAudio::PulseAudio) + add_library(PulseAudio::PulseAudio UNKNOWN IMPORTED) + set_target_properties(PulseAudio::PulseAudio PROPERTIES + IMPORTED_LOCATION ${PulseAudio_LIBRARIES} + INTERFACE_INCLUDE_DIRECTORIES ${PulseAudio_INCLUDE_DIR} + ) + endif() +endif() + +mark_as_advanced(PulseAudio_INCLUDE_DIR PulseAudio_LIBRARIES) diff --git a/Source/Core/AudioCommon/CMakeLists.txt b/Source/Core/AudioCommon/CMakeLists.txt index cfcd4be569..7c3fd3363a 100644 --- a/Source/Core/AudioCommon/CMakeLists.txt +++ b/Source/Core/AudioCommon/CMakeLists.txt @@ -60,9 +60,20 @@ else() message(STATUS "OpenAL explicitly disabled, disabling OpenAL sound backend") endif() -if(PULSEAUDIO_FOUND) - target_sources(audiocommon PRIVATE PulseAudioStream.cpp) - target_link_libraries(audiocommon PRIVATE ${PULSEAUDIO_LIBRARIES}) +if(ENABLE_PULSEAUDIO) + # PulseAudio ships with a PulseAudioConfig.cmake with no imported target + # So we use our own FindPulseAudio instead with "MODULE" + find_package(PulseAudio MODULE QUIET) + if(PULSEAUDIO_FOUND) + message(STATUS "PulseAudio found, enabling PulseAudio sound backend") + target_sources(audiocommon PRIVATE PulseAudioStream.cpp) + target_link_libraries(audiocommon PRIVATE PulseAudio::PulseAudio) + target_compile_definitions(audiocommon PRIVATE HAVE_PULSEAUDIO=1) + else() + message(STATUS "PulseAudio NOT found, disabling PulseAudio sound backend") + endif() +else() + message(STATUS "PulseAudio explicitly disabled, disabling PulseAudio sound backend") endif() if(WIN32)