miniaudio: Add support for split version and expose extra/nodes (#5686)

* miniaudio: Add support for split version and expose extra/nodes

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* restore headeronly

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Move build_defines to its own file

* Update xmake.lua

* Update xmake.lua
pull/5704/head
Jérôme Leclercq 2 weeks ago committed by GitHub
parent 96525815f1
commit c8bd247e6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 73
      packages/m/miniaudio/build_defines.lua
  2. 72
      packages/m/miniaudio/xmake.lua

@ -0,0 +1,73 @@
import("core.base.hashset")
local available_backends = hashset.from{"aaudio", "audio4", "alsa", "coreaudio", "dsound", "jack", "null", "opensl", "oss", "pulseaudio", "wasapi", "webaudio", "winmm"}
function main(package)
local defines = {}
if not package:config("headeronly") and package:config("shared") then
table.insert(defines, "MA_DLL")
end
local enabled_backends = package:config("enabled_backends")
if #enabled_backends > 0 then
table.insert(defines, "MA_ENABLE_ONLY_SPECIFIC_BACKENDS")
for _, backend in ipairs(enabled_backends) do
if not available_backends:has(backend) then
os.raise("unknown backend " .. backend)
end
table.insert(defines, "MA_ENABLE_" .. backend:upper())
end
end
local disabled_backends = package:config("disabled_backends")
for _, backend in ipairs(disabled_backends) do
for _, backend in ipairs(enabled_backends) do
if not available_backends:has(backend) then
os.raise("unknown backend " .. backend)
end
table.insert(defines, "MA_NO_" .. backend:upper())
end
end
if not package:config("avx2") then
table.insert(defines, "MA_NO_AVX2")
end
if not package:config("decoding") then
table.insert(defines, "MA_NO_DECODING")
end
if not package:config("device_io") then
table.insert(defines, "MA_NO_DEVICE_IO")
end
if not package:config("encoding") then
table.insert(defines, "MA_NO_ENCODING")
end
if not package:config("engine") then
table.insert(defines, "MA_NO_ENGINE")
end
if not package:config("flac") then
table.insert(defines, "MA_NO_FLAC")
end
if not package:config("generation") then
table.insert(defines, "MA_NO_GENERATION")
end
if not package:config("mp3") then
table.insert(defines, "MA_NO_MP3")
end
if not package:config("neon") then
table.insert(defines, "MA_NO_NEON")
end
if not package:config("node_graph") then
table.insert(defines, "MA_NO_NODE_GRAPH")
end
if not package:config("resource_manager") then
table.insert(defines, "MA_NO_RESOURCE_MANAGER")
end
if not package:config("sse2") then
table.insert(defines, "MA_NO_SSE2")
end
if not package:config("threading") then
table.insert(defines, "MA_NO_THREADING")
end
if not package:config("wav") then
table.insert(defines, "MA_NO_WAV")
end
return table.unique(defines)
end

@ -1,7 +1,7 @@
package("miniaudio")
set_kind("library", {headeronly = true})
set_homepage("https://miniaud.io")
set_description("Single file audio playback and capture library written in C.")
set_license("MIT")
set_urls("https://github.com/mackron/miniaudio/archive/refs/tags/$(version).tar.gz",
"https://github.com/mackron/miniaudio.git")
@ -11,6 +11,25 @@ package("miniaudio")
add_versions("0.11.17", "4b139065f7068588b73d507d24e865060e942eb731f988ee5a8f1828155b9480")
add_versions("0.11.18", "85ca916266d809b39902e180a6d16f82caea9c2ea1cea6d374413641b7ba48c3")
add_configs("headeronly", {description = "Install the headeronly version (or the split one if disabled).", default = true, type = "boolean"})
add_configs("avx2", {description = "Enable AVX2 optimizations", default = true, type = "boolean"})
add_configs("decoding", {description = "Enable decoding APIs", default = true, type = "boolean"})
add_configs("device_io", {description = "Enable playback and recording", default = true, type = "boolean"})
add_configs("disabled_backends", {description = "Disabled backends (none if empty)", default = {}, type = "table"})
add_configs("encoding", {description = "Enable encoding APIs", default = true, type = "boolean"})
add_configs("enabled_backends", {description = "Enabled backends (all if empty)", default = {}, type = "table"})
add_configs("engine", {description = "Enable the engine API", default = true, type = "boolean"})
add_configs("flac", {description = "Enable the builtin FLAC decoder", default = true, type = "boolean"})
add_configs("generation", {description = "Enable the generation APIs", default = true, type = "boolean"})
add_configs("mp3", {description = "Enable the builtin MP3 decoder", default = true, type = "boolean"})
add_configs("neon", {description = "Enable Neon optimizations", default = true, type = "boolean"})
add_configs("node_graph", {description = "Enable the node graph API (required for engine)", default = true, type = "boolean"})
add_configs("resource_manager", {description = "Enable the resource manager", default = true, type = "boolean"})
add_configs("sse2", {description = "Enable SSE2 optimizations", default = true, type = "boolean"})
add_configs("threading", {description = "Enable the threading API", default = true, type = "boolean"})
add_configs("wav", {description = "Enable the builtin WAV decoder and encoder", default = true, type = "boolean"})
if is_plat("iphoneos") then
add_frameworks("AudioToolbox", "AVFoundation", "CoreFoundation", "Foundation")
elseif is_plat("macosx") then
@ -18,10 +37,57 @@ package("miniaudio")
add_frameworks("AudioToolbox", "CoreAudio", "AudioUnit", "AVFoundation", "CoreFoundation", "Foundation")
end
if is_plat("linux", "bsd") then
add_syslinks("pthread")
end
on_load(function (package)
if package:config("headeronly") then
package:set("kind", "library", {headeronly = true})
end
local defines = import("build_defines")(package)
if #defines > 0 then
package:add("defines", table.unwrap(defines))
end
end)
on_install(function (package)
os.cp("miniaudio.h", package:installdir("include"))
if package:config("headeronly") then
os.cp("miniaudio.h", package:installdir("include"))
else
local defines = import("build_defines")(package)
if package:is_plat("macosx", "iphoneos") then
io.writefile("extras/miniaudio_split/miniaudio.m", "#include \"miniaudio.c\"")
end
local definelist = table.concat(table.imap(defines, function (_, d) return " add_defines(\"" .. d .. "\")" end), "\n")
io.writefile("xmake.lua", [[
add_rules("mode.debug", "mode.release")
target("miniaudio")
set_kind("$(kind)")
add_headerfiles("extras/miniaudio_split/(miniaudio.h)")
if is_plat("macosx", "iphoneos") then
add_files("extras/miniaudio_split/miniaudio.m")
else
add_files("extras/miniaudio_split/miniaudio.c")
end
add_defines("MINIAUDIO_IMPLEMENTATION")
]] .. definelist)
import("package.tools.xmake").install(package)
end
os.cp("extras/nodes", package:installdir("include"))
end)
on_test(function (package)
assert(package:has_cfuncs("ma_encoder_config_init", {includes = "miniaudio.h"}))
local check_snippets = package.check_csnippets
if package:config("headeronly") and package:is_plat("macosx", "iphoneos") then
check_snippets = package.check_msnippets
end
assert(check_snippets(package, {test = [[
void test() {
ma_uint32 major, minor, rev;
ma_version(&major, &minor, &rev);
}
]]}, {includes = {"miniaudio.h"}, configs = {defines = package:config("headeronly") and "MINIAUDIO_IMPLEMENTATION" or nil}}))
end)

Loading…
Cancel
Save