SDL_mixer: cmake: opusfile header include ogg/ogg.h, so look for ogg as well

From 1be89d64eedab16152c34ea4ca4f298a841f6e43 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Fri, 12 Jan 2024 17:25:46 +0100
Subject: [PATCH] cmake: opusfile header include ogg/ogg.h, so look for ogg as
 well

---
 cmake/FindOgg.cmake      | 50 ++++++++++++++++++++++++++++++++++++++++
 cmake/FindOpusFile.cmake |  8 ++++---
 2 files changed, 55 insertions(+), 3 deletions(-)
 create mode 100644 cmake/FindOgg.cmake

diff --git a/cmake/FindOgg.cmake b/cmake/FindOgg.cmake
new file mode 100644
index 00000000..1d3c7cf9
--- /dev/null
+++ b/cmake/FindOgg.cmake
@@ -0,0 +1,50 @@
+include(FindPackageHandleStandardArgs)
+
+find_package(PkgConfig QUIET)
+pkg_check_modules(PC_OGG QUIET ogg)
+
+find_library(Ogg_LIBRARY
+    NAMES ogg
+    HINTS ${PC_OGG_LIBDIR}
+)
+
+find_path(Ogg_INCLUDE_PATH
+    NAMES ogg/ogg.h
+    HINTS ${PC_OGG_INCLUDEDIR}
+)
+
+if(PC_OGG_FOUND)
+    get_flags_from_pkg_config("${Ogg_LIBRARY}" "PC_OGG" "_ogg")
+endif()
+
+set(Ogg_COMPILE_OPTIONS "${_ogg_compile_options}" CACHE STRING "Extra compile options of ogg")
+
+set(Ogg_LINK_LIBRARIES "${_ogg_link_libraries}" CACHE STRING "Extra link libraries of ogg")
+
+set(Ogg_LINK_OPTIONS "${_ogg_link_options}" CACHE STRING "Extra link flags of ogg")
+
+set(Ogg_LINK_DIRECTORIES "${_ogg_link_directories}" CACHE PATH "Extra link directories of ogg")
+
+find_package(Ogg)
+
+find_package_handle_standard_args(Ogg
+    REQUIRED_VARS Ogg_LIBRARY Ogg_INCLUDE_PATH Ogg_FOUND
+)
+
+if(Ogg_FOUND)
+    set(Ogg_dirs ${Ogg_INCLUDE_PATH})
+    if(EXISTS "${Ogg_INCLUDE_PATH}/opus")
+        list(APPEND Ogg_dirs "${Ogg_INCLUDE_PATH}/opus")
+    endif()
+    if (NOT TARGET Ogg::Ogg)
+        add_library(Ogg::Ogg UNKNOWN IMPORTED)
+        set_target_properties(Ogg::Ogg PROPERTIES
+            IMPORTED_LOCATION "${Ogg_LIBRARY}"
+            INTERFACE_INCLUDE_DIRECTORIES "${Ogg_dirs}"
+            INTERFACE_COMPILE_OPTIONS "${Ogg_COMPILE_OPTIONS}"
+            INTERFACE_LINK_LIBRARIES "${Ogg_LINK_LIBRARIES}"
+            INTERFACE_LINK_OPTIONS "${Ogg_LINK_OPTIONS}"
+            INTERFACE_LINK_DIRECTORIES "${Ogg_LINK_DIRECTORIES}"
+        )
+    endif()
+endif()
diff --git a/cmake/FindOpusFile.cmake b/cmake/FindOpusFile.cmake
index 1cc3d895..45992cf5 100644
--- a/cmake/FindOpusFile.cmake
+++ b/cmake/FindOpusFile.cmake
@@ -25,11 +25,13 @@ set(OpusFile_LINK_OPTIONS "${_opusfile_link_options}" CACHE STRING "Extra link f
 
 set(OpusFile_LINK_DIRECTORIES "${_opusfile_link_directories}" CACHE PATH "Extra link directories of opusfile")
 
+find_package(Ogg)
+
 find_package_handle_standard_args(OpusFile
-    REQUIRED_VARS OpusFile_LIBRARY OpusFile_INCLUDE_PATH
+    REQUIRED_VARS OpusFile_LIBRARY OpusFile_INCLUDE_PATH Ogg_FOUND
 )
 
-if (OpusFile_FOUND)
+if(OpusFile_FOUND AND Ogg_FOUND)
     set(OpusFile_dirs ${OpusFile_INCLUDE_PATH})
     if(EXISTS "${OpusFile_INCLUDE_PATH}/opus")
         list(APPEND OpusFile_dirs "${OpusFile_INCLUDE_PATH}/opus")
@@ -40,7 +42,7 @@ if (OpusFile_FOUND)
             IMPORTED_LOCATION "${OpusFile_LIBRARY}"
             INTERFACE_INCLUDE_DIRECTORIES "${OpusFile_dirs}"
             INTERFACE_COMPILE_OPTIONS "${OpusFile_COMPILE_OPTIONS}"
-            INTERFACE_LINK_LIBRARIES "${OpusFile_LINK_LIBRARIES}"
+            INTERFACE_LINK_LIBRARIES "${OpusFile_LINK_LIBRARIES};Ogg::Ogg"
             INTERFACE_LINK_OPTIONS "${OpusFile_LINK_OPTIONS}"
             INTERFACE_LINK_DIRECTORIES "${OpusFile_LINK_DIRECTORIES}"
         )