From 80ac6c03b55949a53104cc5d1fdb58eabd2e5bcd Mon Sep 17 00:00:00 2001 From: Castor215 <132155746+Castor215@users.noreply.github.com> Date: Fri, 10 Nov 2023 21:15:02 +0000 Subject: [PATCH] externals: allow user to use system openal (#7145) --- externals/CMakeLists.txt | 24 ++++++++----- .../cmake-modules/CitraHandleSystemLibs.cmake | 3 ++ externals/cmake-modules/FindOpenAL.cmake | 36 +++++++++++++++++++ 3 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 externals/cmake-modules/FindOpenAL.cmake diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index a9b44e623f..48afa0e1ff 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -344,15 +344,21 @@ endif() # OpenAL Soft if (ENABLE_OPENAL) - set(ALSOFT_EMBED_HRTF_DATA OFF CACHE BOOL "") - set(ALSOFT_EXAMPLES OFF CACHE BOOL "") - set(ALSOFT_INSTALL OFF CACHE BOOL "") - set(ALSOFT_INSTALL_CONFIG OFF CACHE BOOL "") - set(ALSOFT_INSTALL_HRTF_DATA OFF CACHE BOOL "") - set(ALSOFT_INSTALL_AMBDEC_PRESETS OFF CACHE BOOL "") - set(ALSOFT_UTILS OFF CACHE BOOL "") - set(LIBTYPE "STATIC" CACHE STRING "") - add_subdirectory(openal-soft EXCLUDE_FROM_ALL) + if(USE_SYSTEM_OPENAL) + add_library(OpenAL INTERFACE) + find_package(OpenAL REQUIRED) + target_link_libraries(OpenAL INTERFACE OpenAL::OpenAL) + else() + set(ALSOFT_EMBED_HRTF_DATA OFF CACHE BOOL "") + set(ALSOFT_EXAMPLES OFF CACHE BOOL "") + set(ALSOFT_INSTALL OFF CACHE BOOL "") + set(ALSOFT_INSTALL_CONFIG OFF CACHE BOOL "") + set(ALSOFT_INSTALL_HRTF_DATA OFF CACHE BOOL "") + set(ALSOFT_INSTALL_AMBDEC_PRESETS OFF CACHE BOOL "") + set(ALSOFT_UTILS OFF CACHE BOOL "") + set(LIBTYPE "STATIC" CACHE STRING "") + add_subdirectory(openal-soft EXCLUDE_FROM_ALL) + endif() endif() # VMA diff --git a/externals/cmake-modules/CitraHandleSystemLibs.cmake b/externals/cmake-modules/CitraHandleSystemLibs.cmake index 28a1097f20..471301c73e 100644 --- a/externals/cmake-modules/CitraHandleSystemLibs.cmake +++ b/externals/cmake-modules/CitraHandleSystemLibs.cmake @@ -22,6 +22,7 @@ option(USE_SYSTEM_ENET "Use the system libenet (instead of the bundled one)" OFF option(USE_SYSTEM_CRYPTOPP "Use the system cryptopp (instead of the bundled one)" OFF) option(USE_SYSTEM_CUBEB "Use the system cubeb (instead of the bundled one)" OFF) option(USE_SYSTEM_LODEPNG "Use the system lodepng (instead of the bundled one)" OFF) +option(USE_SYSTEM_OPENAL "Use the system OpenAL (instead of the bundled one)" OFF) # Qt and MoltenVK are handled separately CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_SDL2 "Disable system SDL2" OFF "USE_SYSTEM_LIBS" OFF) @@ -43,6 +44,7 @@ CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_ENET "Disable system libenet" OFF "USE_SYS CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_CRYPTOPP "Disable system cryptopp" OFF "USE_SYSTEM_LIBS" OFF) CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_CUBEB "Disable system cubeb" OFF "USE_SYSTEM_LIBS" OFF) CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_LODEPNG "Disable system lodepng" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_OPENAL "Disable system OpenAL" OFF "USE_SYSTEM_LIBS" OFF) set(LIB_VAR_LIST SDL2 @@ -64,6 +66,7 @@ set(LIB_VAR_LIST CRYPTOPP CUBEB LODEPNG + OPENAL ) # First, check that USE_SYSTEM_XXX is not used with USE_SYSTEM_LIBS diff --git a/externals/cmake-modules/FindOpenAL.cmake b/externals/cmake-modules/FindOpenAL.cmake new file mode 100644 index 0000000000..1a778febb0 --- /dev/null +++ b/externals/cmake-modules/FindOpenAL.cmake @@ -0,0 +1,36 @@ +if(NOT OPENAL_FOUND) + pkg_check_modules(OOPENAL_TMP libopanal) + + find_path(OPENAL_INCLUDE_DIRS NAMES al.h + PATHS + ${OPENAL_TMP_INCLUDE_DIRS} + /usr/include/AL + /usr/include + /usr/local/include/AL + /usr/local/include + ) + + find_library(OPENAL_LIBRARY_DIRS NAMES openal + PATHS + ${OPENAL_TMP_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + ) + + if(OPENAL_INCLUDE_DIRS AND OPENAL_LIBRARY_DIRS) + set(OPENAL_FOUND TRUE CACHE INTERNAL "OpenAL found") + message(STATUS "Found OpenAL: ${OPENAL_LIBRARY_DIRS}, ${OPENAL_INCLUDE_DIRS}") + else() + set(OPENAL_FOUND FALSE CACHE INTERNAL "OpenAL found") + message(STATUS "OpenAL not found.") + endif() +endif() + +if(OPENAL_FOUND AND NOT TARGET OpenAL::OpenAL) + add_library(OpenAL::OpenAL UNKNOWN IMPORTED) + set_target_properties(OpenAL::OpenAL PROPERTIES + INCLUDE_DIRECTORIES ${OPENAL_INCLUDE_DIRS} + INTERFACE_LINK_LIBRARIES ${OPENAL_LIBRARY_DIRS} + IMPORTED_LOCATION ${OPENAL_LIBRARY_DIRS} + ) +endif()