diff --git a/cmake/modules/FindOpusFile.cmake b/cmake/modules/FindOpusFile.cmake new file mode 100644 index 0000000000..64b0c814ff --- /dev/null +++ b/cmake/modules/FindOpusFile.cmake @@ -0,0 +1,34 @@ +# Filename: FindOpusFile.cmake +# Authors: CFSworks (13 Jan, 2019) +# +# Usage: +# find_package(OpusFile [REQUIRED] [QUIET]) +# +# Once done this will define: +# OPUSFILE_FOUND - system has Ogg and opusfile +# OPUSFILE_INCLUDE_DIRS - the include directory/ies containing opus/ and ogg/ +# OPUSFILE_LIBRARIES - the paths to the opus and opusfile libraries +# + +# Find Ogg +find_package(Ogg QUIET) + +# Find Opus +find_path(OPUS_INCLUDE_DIR NAMES "opus/opusfile.h") + +find_library(OPUS_opus_LIBRARY NAMES "opus") +find_library(OPUS_opusfile_LIBRARY NAMES "opusfile") + +mark_as_advanced(OPUS_INCLUDE_DIR OPUS_opus_LIBRARY OPUS_opusfile_LIBRARY) + +# Define output variables +set(OPUSFILE_INCLUDE_DIRS ${OPUS_INCLUDE_DIR} "${OPUS_INCLUDE_DIR}/opus") +if(NOT OGG_INCLUDE_DIR STREQUAL OPUS_INCLUDE_DIR) + list(APPEND OPUSFILE_INCLUDE_DIRS ${OGG_INCLUDE_DIR}) +endif() +set(OPUSFILE_LIBRARIES ${OGG_LIBRARY} ${OPUS_opus_LIBRARY} ${OPUS_opusfile_LIBRARY}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OpusFile DEFAULT_MSG + Ogg_FOUND + OPUS_INCLUDE_DIR OPUS_opus_LIBRARY OPUS_opusfile_LIBRARY) diff --git a/dtool/Package.cmake b/dtool/Package.cmake index 01e14dfa0d..98a6a5162a 100644 --- a/dtool/Package.cmake +++ b/dtool/Package.cmake @@ -248,6 +248,13 @@ package_option(VORBIS "Enables support for decoding Vorbis-encoded .ogg audio files via libvorbisfile.") package_status(VORBIS "Vorbis") +# Opus +find_package(OpusFile QUIET) +package_option(OPUS + FOUND_AS OPUSFILE + "Enables support for decoding .opus audio files via libopusfile.") +package_status(OPUS "Opus") + # # ------------ Audio libraries ------------ # diff --git a/dtool/dtool_config.h.in b/dtool/dtool_config.h.in index 59950c5480..3208b29c38 100644 --- a/dtool/dtool_config.h.in +++ b/dtool/dtool_config.h.in @@ -51,6 +51,9 @@ /* Define if we have libvorbisfile available. */ #cmakedefine HAVE_VORBIS +/* Define if we have libopus available. */ +#cmakedefine HAVE_OPUS + /* Define if we have OpenSSL installed. */ #cmakedefine HAVE_OPENSSL #cmakedefine REPORT_OPENSSL_ERRORS diff --git a/panda/src/movies/CMakeLists.txt b/panda/src/movies/CMakeLists.txt index 5646bde08c..62af1e46d3 100644 --- a/panda/src/movies/CMakeLists.txt +++ b/panda/src/movies/CMakeLists.txt @@ -46,7 +46,7 @@ composite_sources(p3movies P3MOVIES_SOURCES) add_component_library(p3movies SYMBOL BUILDING_PANDA_MOVIES ${P3MOVIES_HEADERS} ${P3MOVIES_SOURCES}) target_link_libraries(p3movies p3pstatclient p3gobj p3pandabase pandaexpress - PKG::VORBIS) + PKG::VORBIS PKG::OPUS) target_interrogate(p3movies ALL) if(NOT BUILD_METALIBS)