Browse Source

CMake: Detect Opus

Sam Edwards 7 years ago
parent
commit
052004d06b

+ 34 - 0
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)

+ 7 - 0
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 ------------
 #

+ 3 - 0
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

+ 1 - 1
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)