Selaa lähdekoodia

steam-audio: add package (#6634)

* steam-audio: add package

* patch

* fix windows shared

* fix pdb install

* fix grammer

* remove so.dbg install

* libmysofa: fix pic for static build

* unsafe patch

* fix macos

* improve patch
star9029 4 kuukautta sitten
vanhempi
commit
d9b20290b5

+ 4 - 8
packages/f/flatbuffers/xmake.lua

@@ -17,15 +17,15 @@ package("flatbuffers")
     add_deps("cmake")
     add_deps("cmake")
 
 
     on_install(function(package)
     on_install(function(package)
+        if not package:is_cross() then
+            package:addenv("PATH", "bin")
+        end
+
         io.replace("CMakeLists.txt", "/MT", "", {plain = true})
         io.replace("CMakeLists.txt", "/MT", "", {plain = true})
         io.replace("CMakeLists.txt",
         io.replace("CMakeLists.txt",
             "RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}",
             "RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}",
             "RUNTIME DESTINATION bin", {plain = true})
             "RUNTIME DESTINATION bin", {plain = true})
 
 
-        if not package:is_cross() then
-            package:addenv("PATH", "bin")
-        end
-
         local configs = {"-DFLATBUFFERS_BUILD_TESTS=OFF"}
         local configs = {"-DFLATBUFFERS_BUILD_TESTS=OFF"}
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
         if package:is_binary() then
         if package:is_binary() then
@@ -46,10 +46,6 @@ package("flatbuffers")
         if package:is_binary() then
         if package:is_binary() then
             os.tryrm(package:installdir("include"))
             os.tryrm(package:installdir("include"))
         end
         end
-
-        if package:is_plat("windows") and package:is_debug() then
-            os.trymv(package:installdir("lib/flatc.pdb"), package:installdir("bin"))
-        end
     end)
     end)
 
 
     on_test(function(package)
     on_test(function(package)

+ 9 - 1
packages/l/libmysofa/xmake.lua

@@ -1,7 +1,6 @@
 package("libmysofa")
 package("libmysofa")
     set_homepage("https://github.com/hoene/libmysofa")
     set_homepage("https://github.com/hoene/libmysofa")
     set_description("Reader for AES SOFA files to get better HRTFs")
     set_description("Reader for AES SOFA files to get better HRTFs")
-
     set_license("BSD-3-Clause")
     set_license("BSD-3-Clause")
 
 
     add_urls("https://github.com/hoene/libmysofa/archive/refs/tags/$(version).tar.gz",
     add_urls("https://github.com/hoene/libmysofa/archive/refs/tags/$(version).tar.gz",
@@ -18,6 +17,13 @@ package("libmysofa")
     end
     end
 
 
     on_install(function (package)
     on_install(function (package)
+        if not package:config("shared") then
+            package:add("defines", "MYSOFA_STATIC_DEFINE")
+        end
+
+        if package:version() and package:version():le("1.3.2") then
+            io.replace("src/CMakeLists.txt", "${BUILD_SHARED_LIBS}", package:config("pic") and "ON" or "OFF", {plain = true})
+        end
         if package:is_plat("wasm", "cross") then
         if package:is_plat("wasm", "cross") then
             io.replace("src/CMakeLists.txt", [[find_library(MATH m)]], [[set(MATH "")]], {plain = true})
             io.replace("src/CMakeLists.txt", [[find_library(MATH m)]], [[set(MATH "")]], {plain = true})
         end
         end
@@ -36,10 +42,12 @@ package("libmysofa")
         os.rm("windows/third-party/zlib-1.2.11")
         os.rm("windows/third-party/zlib-1.2.11")
         os.rm("share/default.sofa")
         os.rm("share/default.sofa")
         os.cp("share/MIT_KEMAR_normal_pinna.sofa", "share/default.sofa")
         os.cp("share/MIT_KEMAR_normal_pinna.sofa", "share/default.sofa")
+
         local configs = {"-DBUILD_TESTS=OFF", "-DCMAKE_POLICY_DEFAULT_CMP0057=NEW"}
         local configs = {"-DBUILD_TESTS=OFF", "-DCMAKE_POLICY_DEFAULT_CMP0057=NEW"}
         table.insert(configs, "-DBUILD_STATIC_LIBS=" .. (package:config("shared") and "OFF" or "ON"))
         table.insert(configs, "-DBUILD_STATIC_LIBS=" .. (package:config("shared") and "OFF" or "ON"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        table.insert(configs, "-DADDRESS_SANITIZE=" .. (package:config("asan") and "ON" or "OFF"))
         import("package.tools.cmake").install(package, configs)
         import("package.tools.cmake").install(package, configs)
     end)
     end)
 
 

+ 65 - 0
packages/s/steam-audio/patch.lua

@@ -0,0 +1,65 @@
+function _unsafe_patch(package)
+    if package:is_plat("macosx") then
+        io.replace("CMakeLists.txt", [[set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")]], "", {plain = true})
+        io.replace("CMakeLists.txt", [[set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13")]], "", {plain = true})
+    end
+
+    -- clang unsupported this flag https://github.com/llvm/llvm-project/issues/25059
+    -- and build failed on ubuntu with libstdc++-13
+    io.replace("CMakeLists.txt", "add_compile_options(-fabi-version=6)", "", {plain = true})
+end
+
+function main(package)
+    if package:config("abi") then
+        _unsafe_patch(package)
+    end
+
+    if package:is_cross() then
+        io.replace("CMakeLists.txt", "add_compile_options(-m32 -mfpmath=sse -march=native)", "", {plain = true})
+    end
+
+    if package:is_plat("mingw", "msys") then
+        io.replace("CMakeLists.txt", "# Windows flags\nif (IPL_OS_WINDOWS)", "if(0)", {plain = true})
+    else
+        -- remove ucrt hardcode
+        io.replace("CMakeLists.txt", "$<$<AND:$<CONFIG:Debug>,$<BOOL:${STEAMAUDIO_STATIC_RUNTIME}>>:/MTd>", "", {plain = true})
+        io.replace("CMakeLists.txt", "$<$<AND:$<CONFIG:Debug>,$<NOT:$<BOOL:${STEAMAUDIO_STATIC_RUNTIME}>>>:/MDd>", "", {plain = true})
+        io.replace("CMakeLists.txt", "$<$<AND:$<NOT:$<CONFIG:Debug>>,$<BOOL:${STEAMAUDIO_STATIC_RUNTIME}>>:/MT>", "", {plain = true})
+        io.replace("CMakeLists.txt", "$<$<AND:$<NOT:$<CONFIG:Debug>>,$<NOT:$<BOOL:${STEAMAUDIO_STATIC_RUNTIME}>>>:/MD>", "", {plain = true})
+        io.replace("CMakeLists.txt", "$<IF:$<CONFIG:Debug>,_DEBUG,NDEBUG>", "", {plain = true})
+    
+        -- remove lto hardcode
+        io.replace("CMakeLists.txt", "$<$<CONFIG:Release>:/GL>", "", {plain = true})
+    end
+
+    -- remove zlib hardcode
+    io.replace("build/FindMySOFA.cmake", "set(ZLIB_ROOT ${CMAKE_HOME_DIRECTORY}/deps/zlib/lib/${IPL_BIN_SUBDIR}/release)", "", {plain = true})
+    io.replace("build/FindMySOFA.cmake", "set(ZLIB_INCLUDE_DIR ${CMAKE_HOME_DIRECTORY}/deps/zlib/include)", "", {plain = true})
+
+    -- https://github.com/ValveSoftware/steam-audio/pull/399
+    io.replace("src/core/profiler.h", [[#include "memory_allocator.h"]], [[
+        #include "memory_allocator.h"
+        #include <chrono>
+    ]], {plain = true})
+
+    io.replace("src/core/CMakeLists.txt", "get_bin_subdir(IPL_BIN_SUBDIR)", "set(IPL_BIN_SUBDIR )", {plain = true})
+    -- remove symbol install command
+    io.replace("src/core/CMakeLists.txt", 
+[[    install(
+        FILES       ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/phonon.pdb
+        DESTINATION symbols/${IPL_BIN_SUBDIR}
+    )]], "", {plain = true})
+    io.replace("src/core/CMakeLists.txt", 
+[[    install(
+        FILES       ${CMAKE_CURRENT_BINARY_DIR}/libphonon.so.dbg
+        DESTINATION symbols/${IPL_BIN_SUBDIR}
+    )]], "", {plain = true})
+
+    -- remove deps dll install command
+    io.replace("src/core/CMakeLists.txt", 
+[[    install(
+        FILES       ${CMAKE_HOME_DIRECTORY}/deps/trueaudionext/bin/windows-x64/$<LOWER_CASE:$<CONFIG>>/TrueAudioNext.dll
+                    ${CMAKE_HOME_DIRECTORY}/deps/trueaudionext/bin/windows-x64/$<LOWER_CASE:$<CONFIG>>/GPUUtilities.dll
+        DESTINATION lib/${IPL_BIN_SUBDIR}
+    )]], "", {plain = true})
+end

+ 86 - 0
packages/s/steam-audio/xmake.lua

@@ -0,0 +1,86 @@
+package("steam-audio")
+    set_homepage("https://valvesoftware.github.io/steam-audio/")
+    set_description("Valve's steam audio library")
+    set_license("Apache-2.0")
+
+    add_urls("https://github.com/ValveSoftware/steam-audio/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/ValveSoftware/steam-audio.git")
+
+    add_versions("v4.6.0", "b81479bf8fc55c3bbd49c1f9eb1356d7ff7a3a5efc553ba6653ed41715aaf368")
+
+    add_configs("fft", {description = "Choice fft library", default = "pffft", type = "string", values = {"ipp", "ffts", "pffft"}})
+    add_configs("mkl", {description = "Enable Intel MKL support for linear algebra operations.", default = false, type = "boolean"})
+    add_configs("embree", {description = "Enable Intel Embree support for ray tracing.", default = false, type = "boolean"})
+    add_configs("radeonrays", {description = "Enable AMD Radeon Rays support for GPU-accelerated ray tracing.", default = false, type = "boolean"})
+    add_configs("trueaudio_next", {description = "Enable AMD TrueAudio Next support for GPU-accelerated convolution.", default = false, type = "boolean", readonly = true})
+    add_configs("abi", {description = "Apply some unsafe patch for linux and macos build, maybe abi break", default = true, type = "boolean"})
+
+    add_deps("cmake")
+    add_deps("libmysofa", "flatbuffers")
+
+    if is_plat("windows") then
+        add_syslinks("delayimp")
+    elseif is_plat("linux") then
+        add_syslinks("m", "dl", "pthread")
+    elseif is_plat("android") then
+        add_syslinks("log", "android")
+    end
+
+    on_load(function (package)
+        package:add("deps", package:config("fft"))
+        if package:config("mkl") then
+            package:add("deps", "mkl")
+        end
+        if package:config("embree") then
+            package:add("deps", "ispc", "embree")
+        end
+        if package:config("radeonrays") then
+            package:add("deps", "python 3.x", {kind = "binary"})
+            package:add("deps", "radeonrays")
+        end
+
+        if package:is_cross() then
+            package:add("deps", "flatbuffers~host", {kind = "binary", private = true})
+        end
+    end)
+
+    on_install("!bsd and !mingw and !cross", function (package)
+        os.cd("core")
+        import("patch")(package)
+
+        local configs = {
+            "-DSTEAMAUDIO_BUILD_TESTS=OFF",
+            "-DSTEAMAUDIO_BUILD_BENCHMARKS=OFF",
+            "-DSTEAMAUDIO_BUILD_SAMPLES=OFF",
+            "-DSTEAMAUDIO_BUILD_ITESTS=OFF",
+            "-DSTEAMAUDIO_BUILD_DOCS=OFF",
+        }
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+
+        local fft = package:config("fft")
+        table.insert(configs, "-DSTEAMAUDIO_ENABLE_IPP=" .. (fft == "ipp" and "ON" or "OFF"))
+        table.insert(configs, "-DSTEAMAUDIO_ENABLE_FFTS=" .. (fft == "ffts" and "ON" or "OFF"))
+        table.insert(configs, "-DSTEAMAUDIO_ENABLE_MKL=" .. (package:config("mkl") and "ON" or "OFF"))
+        table.insert(configs, "-DSTEAMAUDIO_ENABLE_EMBREE=" .. (package:config("embree") and "ON" or "OFF"))
+        table.insert(configs, "-DSTEAMAUDIO_ENABLE_RADEONRAYS=" .. (package:config("radeonrays") and "ON" or "OFF"))
+        table.insert(configs, "-DSTEAMAUDIO_ENABLE_TRUEAUDIONEXT=" .. (package:config("trueaudio_next") and "ON" or "OFF"))
+        import("package.tools.cmake").install(package, configs)
+
+        os.mv(package:installdir("lib/*.dll"), package:installdir("bin"))
+        if package:is_plat("windows") and package:config("shared") then
+            local phonon_h = path.join(package:installdir("include"), "phonon.h")
+            io.replace(phonon_h, "#define IPLAPI\n#endif", "#define IPLAPI __declspec(dllimport)\n#endif", {plain = true})
+        end
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            void test() {
+                IPLContextSettings contextSettings{};
+                contextSettings.version = STEAMAUDIO_VERSION;
+                IPLContext context = nullptr;
+                iplContextCreate(&contextSettings, &context);
+            }
+        ]]}, {configs = {languages = "c++14"}, includes = "phonon.h"}))
+    end)