SDL_mixer: Cmake find opus file cmake (#468)

From d703e684e7972e967cc74e3dc0f9847385858afd Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sat, 17 Dec 2022 10:24:20 +0100
Subject: [PATCH] Cmake find opus file cmake (#468)

rename Findopusfile.cmake to FindOpusFile.cmake + fix SDL2_mixerConfig.cmake
---
 CMakeLists.txt            | 20 ++++++++++----------
 SDL2_mixerConfig.cmake.in | 10 +++++++---
 cmake/FindOpusFile.cmake  | 37 +++++++++++++++++++++++++++++++++++++
 cmake/Findopusfile.cmake  | 37 -------------------------------------
 4 files changed, 54 insertions(+), 50 deletions(-)
 create mode 100644 cmake/FindOpusFile.cmake
 delete mode 100644 cmake/Findopusfile.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b4b7880c..f90fdf80 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -369,8 +369,8 @@ if(SDL2MIXER_OPUS)
         )
         target_include_directories(SDL2_mixer PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
 
-        if(NOT TARGET opusfile::opusfile)
-            add_library(opusfile::opusfile ALIAS opusfile)
+        if(NOT TARGET OpusFile::opusfile)
+            add_library(OpusFile::opusfile ALIAS opusfile)
         endif()
         if(SDL2MIXER_OPUS_SHARED OR NOT SDL2MIXER_BUILD_SHARED_LIBS)
             list(APPEND INSTALL_EXTRA_TARGETS opus opusfile)
@@ -380,25 +380,25 @@ if(SDL2MIXER_OPUS)
         endif()
     else()
         message(STATUS "Using system opusfile")
-        find_package(opusfile REQUIRED)
+        find_package(OpusFile REQUIRED)
         if(NOT SDL2MIXER_OPUS_SHARED)
             list(APPEND PC_REQUIRES opusfile)
         endif()
     endif()
     if(SDL2MIXER_OPUS_SHARED)
         target_include_directories(SDL2_mixer PRIVATE
-            $<TARGET_PROPERTY:opusfile::opusfile,INCLUDE_DIRECTORIES>
-            $<TARGET_PROPERTY:opusfile::opusfile,INTERFACE_INCLUDE_DIRECTORIES>
-            $<TARGET_PROPERTY:opusfile::opusfile,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
+            $<TARGET_PROPERTY:OpusFile::opusfile,INCLUDE_DIRECTORIES>
+            $<TARGET_PROPERTY:OpusFile::opusfile,INTERFACE_INCLUDE_DIRECTORIES>
+            $<TARGET_PROPERTY:OpusFile::opusfile,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
         )
-        target_get_dynamic_library(dynamic_opusfile opusfile::opusfile)
+        target_get_dynamic_library(dynamic_opusfile OpusFile::opusfile)
         message(STATUS "Dynamic opus (opusfile): ${dynamic_opusfile}")
         target_compile_definitions(SDL2_mixer PRIVATE "OPUS_DYNAMIC=\"${dynamic_opusfile}\"")
         if(SDL2MIXER_VENDORED)
-            add_dependencies(SDL2_mixer opusfile::opusfile)
+            add_dependencies(SDL2_mixer OpusFile::opusfile)
         endif()
     else()
-        target_link_libraries(SDL2_mixer PRIVATE opusfile::opusfile)
+        target_link_libraries(SDL2_mixer PRIVATE OpusFile::opusfile)
     endif()
 endif()
 
@@ -851,7 +851,7 @@ if(SDL2MIXER_INSTALL)
                 cmake/Findlibxmp.cmake
                 cmake/Findlibxmp-lite.cmake
                 cmake/Findmodplug.cmake
-                cmake/Findopusfile.cmake
+                cmake/FindOpusFile.cmake
                 cmake/FindMPG123.cmake
                 cmake/FindVorbis.cmake
                 cmake/Findtremor.cmake
diff --git a/SDL2_mixerConfig.cmake.in b/SDL2_mixerConfig.cmake.in
index 107e9e58..b6c8154d 100644
--- a/SDL2_mixerConfig.cmake.in
+++ b/SDL2_mixerConfig.cmake.in
@@ -53,8 +53,8 @@ endif()
 
 if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2_mixer-static-targets.cmake")
 
+    include(CMakeFindDependencyMacro)
 
-include(CMakeFindDependencyMacro)
     if(SDL2MIXER_FLAC_LIBFLAC AND NOT SDL2MIXER_VENDORED AND NOT TARGET FLAC::FLAC)
         find_dependency(FLAC)
     endif()
@@ -83,8 +83,12 @@ include(CMakeFindDependencyMacro)
         find_dependency(tremor)
     endif()
 
-    if(SDL2MIXER_VORBIS_VORBISFILE AND NOT SDL2MIXER_VENDORED AND NOT TARGET vorbisfile::vorbisfile)
-        find_dependency(vorbisfile)
+    if(SDL2MIXER_VORBIS_VORBISFILE AND NOT SDL2MIXER_VENDORED AND NOT TARGET Vorbis::vorbisfile)
+        find_dependency(Vorbis)
+    endif()
+
+    if(SDL2MIXER_OPUS AND NOT SDL2MIXER_VENDORED AND NOT TARGET opusfile::opusfile)
+        find_dependency(OpusFile)
     endif()
 
     if(SDL2MIXER_WAVPACK AND NOT SDL2MIXER_VENDORED AND NOT TARGET WavPack::WavPack)
diff --git a/cmake/FindOpusFile.cmake b/cmake/FindOpusFile.cmake
new file mode 100644
index 00000000..835390d4
--- /dev/null
+++ b/cmake/FindOpusFile.cmake
@@ -0,0 +1,37 @@
+include(FindPackageHandleStandardArgs)
+
+find_library(OpusFile_LIBRARY
+    NAMES opusfile
+)
+
+set(OpusFile_COMPILE_OPTIONS "" CACHE STRING "Extra compile options of opusfile")
+
+set(OpusFile_LINK_LIBRARIES "" CACHE STRING "Extra link libraries of opusfile")
+
+set(OpusFile_LINK_FLAGS "" CACHE STRING "Extra link flags of opusfile")
+
+find_path(OpusFile_INCLUDE_PATH
+    NAMES opusfile.h
+    PATH_SUFFIXES opus
+)
+
+find_package_handle_standard_args(OpusFile
+    REQUIRED_VARS OpusFile_LIBRARY OpusFile_INCLUDE_PATH
+)
+
+if (OpusFile_FOUND)
+    set(OpusFile_dirs ${OpusFile_INCLUDE_PATH})
+    if(EXISTS "${OpusFile_INCLUDE_PATH}/opus")
+        list(APPEND OpusFile_dirs "${OpusFile_INCLUDE_PATH}/opus")
+    endif()
+    if (NOT TARGET OpusFile::opusfile)
+        add_library(OpusFile::opusfile UNKNOWN IMPORTED)
+        set_target_properties(OpusFile::opusfile PROPERTIES
+            IMPORTED_LOCATION "${OpusFile_LIBRARY}"
+            INTERFACE_INCLUDE_DIRECTORIES "${OpusFile_dirs}"
+            INTERFACE_COMPILE_OPTIONS "${OpusFile_COMPILE_OPTIONS}"
+            INTERFACE_LINK_LIBRARIES "${OpusFile_LINK_LIBRARIES}"
+            INTERFACE_LINK_FLAGS "${OpusFile_LINK_FLAGS}"
+        )
+    endif()
+endif()
diff --git a/cmake/Findopusfile.cmake b/cmake/Findopusfile.cmake
deleted file mode 100644
index 40648d3b..00000000
--- a/cmake/Findopusfile.cmake
+++ /dev/null
@@ -1,37 +0,0 @@
-include(FindPackageHandleStandardArgs)
-
-find_library(opusfile_LIBRARY
-    NAMES opusfile
-)
-
-set(opusfile_COMPILE_OPTIONS "" CACHE STRING "Extra compile options of opusfile")
-
-set(opusfile_LINK_LIBRARIES "" CACHE STRING "Extra link libraries of opusfile")
-
-set(opusfile_LINK_FLAGS "" CACHE STRING "Extra link flags of opusfile")
-
-find_path(opusfile_INCLUDE_PATH
-    NAMES opusfile.h
-    PATH_SUFFIXES opus
-)
-
-find_package_handle_standard_args(opusfile
-    REQUIRED_VARS opusfile_LIBRARY opusfile_INCLUDE_PATH
-)
-
-if (opusfile_FOUND)
-    set(opusfile_dirs ${opusfile_INCLUDE_PATH})
-    if(EXISTS "${opusfile_INCLUDE_PATH}/opus")
-        list(APPEND opusfile_dirs "${opusfile_INCLUDE_PATH}/opus")
-    endif()
-    if (NOT TARGET opusfile::opusfile)
-        add_library(opusfile::opusfile UNKNOWN IMPORTED)
-        set_target_properties(opusfile::opusfile PROPERTIES
-            IMPORTED_LOCATION "${opusfile_LIBRARY}"
-            INTERFACE_INCLUDE_DIRECTORIES "${opusfile_dirs}"
-            INTERFACE_COMPILE_OPTIONS "${opusfile_COMPILE_OPTIONS}"
-            INTERFACE_LINK_LIBRARIES "${opusfile_LINK_LIBRARIES}"
-            INTERFACE_LINK_FLAGS "${opusfile_LINK_FLAGS}"
-        )
-    endif()
-endif()