浏览代码

libsdl2_mixer: add FLAC option and validate FLAC::FLAC CMakeConfig (#7734)

* libsdl2_mixer: add FLAC option and validate FLAC::FLAC CMakeConfig

* 1. Remove FindOgg.cmake to resolve ogg.lib linkage during shared windows builds. 2. Repair .cmake.in to check for Threads before linking against Thread::Thread.

* validate libflac plats

* Resolve libflac missing symbols by following lib config for shared.

* Use upstream solution to resolve ARM64 InterlockedExchange enforcement. https://github.com/libsdl-org/SDL/pull/13340

* guard DRFLAC=OFF behind flac config
Saikari 2 月之前
父节点
当前提交
366271c8ae

+ 15 - 0
packages/l/libflac/patches/1.5.0/fix-cmake-in.patch

@@ -0,0 +1,15 @@
+diff --git a/flac-config.cmake.in b/flac-config.cmake.in
+index bcafc4c8..dcf299dd 100644
+--- a/flac-config.cmake.in
++++ b/flac-config.cmake.in
+@@ -5,6 +5,10 @@ if(NOT TARGET Ogg::ogg)
+     find_dependency(Ogg)
+ endif()
+ 
++if (@ENABLE_MULTITHREADING@)
++    find_dependency(Threads)
++endif()
++
+ include("${CMAKE_CURRENT_LIST_DIR}/targets.cmake")
+ 
+ if(TARGET FLAC::FLAC)

+ 3 - 1
packages/l/libflac/xmake.lua

@@ -10,6 +10,8 @@ package("libflac")
     add_versions("1.4.3", "0a4bb82a30609b606650d538a804a7b40205366ce8fc98871b0ecf3fbb0611ee")
     add_versions("1.4.2", "8e8e0406fb9e1d177bb4ba8cfed3ca3935d37144eac8f0219a03e8c1ed5cc18e")
     add_versions("1.3.3", "668cdeab898a7dd43cf84739f7e1f3ed6b35ece2ef9968a5c7079fe9adfe1689")
+    
+    add_patches("1.5.0", "patches/1.5.0/fix-cmake-in.patch", "326971747da526e18fa47e86cd127f2f3a80b9f85ac8f214a238c2456849be83")
     add_patches("1.5.0", "patches/1.5.0/cmake.patch", "6ce0ff5c6e8be0a68d4abaf9c0801f988f5cb600228ee9e2db812adf6e4cf3c1")
     add_patches("1.4.3", "patches/1.4.2/cmake.patch", "0a99382d5d7bd33078572b6cc3af08ee7e5e3618c80754a5fdc400bd69f4e470")
     add_patches("1.4.2", "patches/1.4.2/cmake.patch", "0a99382d5d7bd33078572b6cc3af08ee7e5e3618c80754a5fdc400bd69f4e470")
@@ -43,7 +45,7 @@ package("libflac")
         end
     end)
 
-    on_install("windows", "linux", "macosx", "iphoneos", "mingw", "android", "wasm", function (package)
+    on_install(function (package)
         local configs = {}
         table.insert(configs, "-DBUILD_CXXLIBS=OFF")
         table.insert(configs, "-DBUILD_DOCS=OFF")

+ 16 - 0
packages/l/libsdl2/patches/2.32.2/fix-arm64.patch

@@ -0,0 +1,16 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index ea2368cdfe9aa..ea13c80493b58 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -755,6 +755,11 @@ if(MSVC)
+   if(MSVC_VERSION GREATER 1926 AND CMAKE_GENERATOR_PLATFORM MATCHES "Win32|x64")
+     list(APPEND EXTRA_LDFLAGS_BUILD "-CETCOMPAT")
+   endif()
++
++  # for VS >= 17.14 targeting ARM64: inline the Interlocked funcs
++  if(MSVC_VERSION GREATER 1943 AND SDL_CPU_ARM64 AND NOT SDL_LIBC)
++    list(APPEND EXTRA_CFLAGS /forceInterlockedFunctions-)
++  endif()
+ endif()
+ 
+ if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")

+ 2 - 1
packages/l/libsdl2/xmake.lua

@@ -83,8 +83,9 @@ package("libsdl2")
     add_versions("github:2.30.10", "release-2.30.10")
     add_versions("github:2.32.2", "release-2.32.2")
 
-    add_patches("2.30.0", path.join(os.scriptdir(), "patches", "2.30.0", "fix_mingw.patch"), "ab54eebc2e58d88653b257bc5b48a232c5fb0e6fad5d63661b6388215a7b0cd0")
+    add_patches("2.30.0", "patches/2.30.0/fix_mingw.patch", "ab54eebc2e58d88653b257bc5b48a232c5fb0e6fad5d63661b6388215a7b0cd0")
     add_patches("2.30.6", "https://github.com/libsdl-org/SDL/commit/7cf3234efeb7a68636bcfdfb3b1507b43fbb0845.patch", "c2fba1e76f8f10631544b63e8ce105a67d582b23bba7c96bdef5f135bd6b4cad")
+    add_patches("2.32.2", "patches/2.32.2/fix-arm64.patch", "11ba63e6f93299030750afd26234da63c534f6cb0f10f9e87bd4efb248768261")
 
     add_deps("cmake")
 

+ 21 - 3
packages/l/libsdl2_mixer/xmake.lua

@@ -12,6 +12,9 @@ package("libsdl2_mixer")
     add_versions("2.6.2", "61549615a67e731805ca1df553e005be966a625c1d20fb085bf99edeef6e0469")
     add_versions("2.8.0", "02df784cc68723419dd266530ee6964f810a6f02a27b03ecc85689c2e5e442ce")
 
+    add_configs("vendored", {description = "Use vendored third-party libraries.", default = false, type = "boolean"})
+    add_configs("flac", {description = "Use libflac to play FLAC audio format.", default = true, type = "boolean"})
+
     if is_plat("mingw") and is_subhost("msys") then
         add_extsources("pacman::SDL2_mixer")
     elseif is_plat("linux") then
@@ -30,6 +33,9 @@ package("libsdl2_mixer")
 
     on_load(function (package)
         package:add("deps", "libsdl2", { configs = { shared = package:config("shared") }})
+        if package:config("flac") then
+            package:add("deps", "libflac", { configs = { shared = package:config("shared") }})
+        end
     end)
 
     on_install(function (package)
@@ -47,7 +53,6 @@ target_link_libraries(SDL2_mixer PRIVATE ${SDL2_LIBRARY})
 
         local configs = {
                             "-DSDL2MIXER_CMD=OFF",
-                            "-DSDL2MIXER_FLAC=OFF",
                             "-DSDL2MIXER_GME=OFF",
                             "-DSDL2MIXER_MIDI=OFF",
                             "-DSDL2MIXER_MOD=OFF",
@@ -55,10 +60,23 @@ target_link_libraries(SDL2_mixer PRIVATE ${SDL2_LIBRARY})
                             "-DSDL2MIXER_OPUS=OFF",
                             "-DSDL2MIXER_SAMPLES=OFF",
                             "-DSDL2MIXER_WAVE=ON", -- was on by not being here
-                            "-DSDL2MIXER_WAVPACK=OFF",
+                            "-DSDL2MIXER_WAVPACK=OFF"
                         }
+        table.insert(configs, "-DSDL2MIXER_VENDORED=" .. (package:config("vendored") and "ON" or "OFF"))
+        table.insert(configs, "-DSDL2MIXER_FLAC=" .. (package:config("flac") and "ON" or "OFF"))
+        table.insert(configs, "-DSDL2MIXER_FLAC_LIBFLAC=" .. (package:config("flac") and "ON" or "OFF"))
+        -- If dependency FLAC is static or shared
+        local flac = package:dep("libflac")
+        if flac then
+            table.insert(configs, "-DSDL2MIXER_FLAC_LIBFLAC_SHARED=" .. (flac:config("shared") and "ON" or "OFF"))
+        end
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+        local opt = {}
+        if package:config("flac") then
+            table.insert(configs, "-DSDL2MIXER_FLAC_DRFLAC=OFF")
+            opt.packagedeps = {"libogg"}
+        end
         local libsdl2 = package:dep("libsdl2")
         if libsdl2 and not libsdl2:is_system() then
             table.insert(configs, "-DSDL2_DIR=" .. libsdl2:installdir())
@@ -81,7 +99,7 @@ target_link_libraries(SDL2_mixer PRIVATE ${SDL2_LIBRARY})
                 table.insert(configs, "-DSDL2_LIBRARY=" .. table.concat(libfiles, ";"))
             end
         end
-        import("package.tools.cmake").install(package, configs)
+        import("package.tools.cmake").install(package, configs, opt)
     end)
 
     on_test(function (package)