Skip to content

Commit

Permalink
CMake: Add support for Tremor (vorbisidec)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry authored and carstene1ns committed Mar 1, 2022
1 parent 8f9c50c commit c7e0e53
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,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
Expand Down Expand Up @@ -1203,6 +1210,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()
Expand Down
5 changes: 4 additions & 1 deletion builds/cmake/Modules/FindOpusfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()
Expand Down
70 changes: 70 additions & 0 deletions builds/cmake/Modules/FindTremor.cmake
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c7e0e53

Please sign in to comment.