diff --git a/CMakeLists.txt b/CMakeLists.txt index 24ed3fc450..fe0507795b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -421,19 +421,6 @@ if (OPENGL_GL) include_directories(${OPENGL_INCLUDE_DIR}) endif() -if(ENABLE_AO) - check_lib(AO ao ao QUIET) - if(AO_FOUND) - add_definitions(-DHAVE_AO=1) - message(STATUS "ao found, enabling ao sound backend") - else() - add_definitions(-DHAVE_AO=0) - message(STATUS "ao NOT found, disabling ao sound backend") - endif() -else() - message(STATUS "ao explicitly disabled, disabling ao sound backend") -endif() - if(ENABLE_BLUEZ) check_lib(BLUEZ bluez bluez QUIET) if(BLUEZ_FOUND) diff --git a/CMakeTests/FindAO.cmake b/CMakeTests/FindAO.cmake new file mode 100644 index 0000000000..e091eeb4dc --- /dev/null +++ b/CMakeTests/FindAO.cmake @@ -0,0 +1,42 @@ +# - Find AO library +# This module defines +# AO_INCLUDE_DIR +# AO_LIBRARIES +# AO_FOUND +# +# vim: expandtab sw=4 ts=4 sts=4: + +include(FindPkgConfig) +pkg_check_modules (AO_PKG QUIET ao) + +find_path(AO_INCLUDE_DIR NAMES ao/ao.h + PATHS + ${AO_PKG_INCLUDE_DIRS} + /usr/include/ao + /usr/include + /usr/local/include/ao + /usr/local/include +) + +find_library(AO_LIBRARIES NAMES ao + PATHS + ${AO_PKG_LIBRARY_DIRS} + /usr/lib + /usr/local/lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(AO + REQUIRED_VARS AO_LIBRARIES AO_INCLUDE_DIR) + +if(AO_FOUND) + if(NOT TARGET AO::AO) + add_library(AO::AO UNKNOWN IMPORTED) + set_target_properties(AO::AO PROPERTIES + IMPORTED_LOCATION ${AO_LIBRARIES} + INTERFACE_INCLUDE_DIRECTORIES ${AO_INCLUDE_DIR} + ) + endif() +endif() + +mark_as_advanced(AO_INCLUDE_DIR AO_LIBRARIES) diff --git a/Source/Core/AudioCommon/CMakeLists.txt b/Source/Core/AudioCommon/CMakeLists.txt index c5b58c23be..052ae2bf0e 100644 --- a/Source/Core/AudioCommon/CMakeLists.txt +++ b/Source/Core/AudioCommon/CMakeLists.txt @@ -29,9 +29,18 @@ else() message(STATUS "ALSA explicitly disabled, disabling ALSA sound backend") endif() -if(AO_FOUND) - target_sources(audiocommon PRIVATE AOSoundStream.cpp) - target_link_libraries(audiocommon PRIVATE ${AO_LIBRARIES}) +if(ENABLE_AO) + find_package(AO) + if(AO_FOUND) + message(STATUS "ao found, enabling ao sound backend") + target_sources(audiocommon PRIVATE AOSoundStream.cpp) + target_link_libraries(audiocommon PRIVATE AO::AO) + target_compile_definitions(audiocommon PRIVATE HAVE_AO=1) + else() + message(STATUS "ao NOT found, disabling ao sound backend") + endif() +else() + message(STATUS "ao explicitly disabled, disabling ao sound backend") endif() if(OPENAL_FOUND)