From 0656ccd629ae5e01aedbc67337d8a28424c01214 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Sat, 5 Feb 2022 16:26:27 +0100 Subject: [PATCH] CMake: Add support for Tremor (vorbisidec) --- CMakeLists.txt | 9 ++++ builds/cmake/Modules/FindOpusfile.cmake | 5 +- builds/cmake/Modules/FindTremor.cmake | 70 +++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 builds/cmake/Modules/FindTremor.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 869c202f33a..06eda61c751 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -813,6 +813,13 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|libretro|psvita|3ds|switch|wii)$") DEFINITION HAVE_OGGVORBIS TARGET Vorbisfile::Vorbisfile) + if(NOT VORBISFILE_FOUND) + player_find_package(NAME Tremor + CONDITION PLAYER_WITH_OGGVORBIS + DEFINITION HAVE_TREMOR + TARGET Tremor::Tremor) + endif() + # opusfile player_find_package(NAME Opusfile CONDITION PLAYER_WITH_OPUS @@ -1207,6 +1214,8 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|libretro|psvita|3ds|switch|wii)$") if(VORBISFILE_FOUND) message(STATUS "Ogg Vorbis playback: libvorbis") + elseif(TREMOR_FOUND) + message(STATUS "Ogg Vorbis playback: tremor") else() message(STATUS "Ogg Vorbis playback: None") endif() diff --git a/builds/cmake/Modules/FindOpusfile.cmake b/builds/cmake/Modules/FindOpusfile.cmake index 1d4e17cd2ce..6e86af37a8b 100644 --- a/builds/cmake/Modules/FindOpusfile.cmake +++ b/builds/cmake/Modules/FindOpusfile.cmake @@ -43,6 +43,9 @@ if(NOT OPUSFILE_LIBRARY) endif() # Additional dependencies +find_library(OGG_LIBRARY + NAMES libogg ogg) + find_library(OPUS_LIBRARY NAMES libopus opus) @@ -61,7 +64,7 @@ if(OPUSFILE_FOUND) add_library(Opusfile::Opusfile UNKNOWN IMPORTED) set_target_properties(Opusfile::Opusfile PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${OPUSFILE_INCLUDE_DIRS}" - INTERFACE_LINK_LIBRARIES ${OPUS_LIBRARY} + INTERFACE_LINK_LIBRARIES "${OGG_LIBRARY};${OPUS_LIBRARY}" IMPORTED_LOCATION "${OPUSFILE_LIBRARY}") endif() endif() diff --git a/builds/cmake/Modules/FindTremor.cmake b/builds/cmake/Modules/FindTremor.cmake new file mode 100644 index 00000000000..c50f2ddfd3b --- /dev/null +++ b/builds/cmake/Modules/FindTremor.cmake @@ -0,0 +1,70 @@ +#.rst: +# FindTremor +# ----------- +# +# Find the Tremor Library +# +# Imported Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the following :prop_tgt:`IMPORTED` targets: +# +# ``Tremor::Tremor`` +# The ``Tremor`` library, if found. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module will set the following variables in your project: +# +# ``TREMOR_INCLUDE_DIRS`` +# where to find Tremor headers. +# ``TREMOR_LIBRARIES`` +# the libraries to link against to use Tremor. +# ``TREMOR_FOUND`` +# true if the Tremor headers and libraries were found. + +find_package(PkgConfig QUIET) + +pkg_check_modules(PC_TREMOR QUIET tremor) + +# Look for the header file. +find_path(TREMOR_INCLUDE_DIR + NAMES ogg.h + PATH_SUFFIXES libogg ogg + HINTS ${PC_TREMOR_INCLUDE_DIRS}) + +# Look for the library. +# Allow TREMOR_LIBRARY to be set manually, as the location of the Tremor library +if(NOT TREMOR_LIBRARY) + find_library(TREMOR_LIBRARY + NAMES libvorbisidec vorbisidec + HINTS ${PC_TREMOR_LIBRARY_DIRS}) +endif() + +# Additional dependencies +find_library(OGG_LIBRARY + NAMES libogg ogg) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Tremor + REQUIRED_VARS TREMOR_LIBRARY TREMOR_INCLUDE_DIR + VERSION_VAR TREMOR_VERSION) + +if(TREMOR_FOUND) + set(TREMOR_INCLUDE_DIRS ${TREMOR_INCLUDE_DIR}) + + if(NOT TREMOR_LIBRARIES) + set(TREMOR_LIBRARIES ${TREMOR_LIBRARIES}) + endif() + + if(NOT TARGET Tremor::Tremor) + add_library(Tremor::Tremor UNKNOWN IMPORTED) + set_target_properties(Tremor::Tremor PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${TREMOR_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${OGG_LIBRARY}" + IMPORTED_LOCATION "${TREMOR_LIBRARY}") + endif() +endif() + +mark_as_advanced(TREMOR_INCLUDE_DIR TREMOR_LIBRARY)