xmake.lua 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package("miniaudio")
  2. set_homepage("https://miniaud.io")
  3. set_description("Single file audio playback and capture library written in C.")
  4. set_license("MIT")
  5. set_urls("https://github.com/mackron/miniaudio/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/mackron/miniaudio.git")
  7. add_versions("0.11.22", "bcb07bfb27e6fa94d34da73ba2d5642d4940b208ec2a660dbf4e52e6b7cd492f")
  8. add_versions("0.11.21", "6afb5c231613d2fab4f1c668b7243ff9a7d6d78a7f5a2692c133f026fe508506")
  9. add_versions("0.11.15", "24a6d38fe69cd42d91f6c1ad211bb559f6c89768c4671fa05b8027f5601d5457")
  10. add_versions("0.11.16", "13320464820491c61bd178b95818fecb7cd0e68f9677d61e1345df6be8d4d77e")
  11. add_versions("0.11.17", "4b139065f7068588b73d507d24e865060e942eb731f988ee5a8f1828155b9480")
  12. add_versions("0.11.18", "85ca916266d809b39902e180a6d16f82caea9c2ea1cea6d374413641b7ba48c3")
  13. add_configs("headeronly", {description = "Install the headeronly version (or the split one if disabled).", default = true, type = "boolean"})
  14. add_configs("avx2", {description = "Enable AVX2 optimizations", default = true, type = "boolean"})
  15. add_configs("decoding", {description = "Enable decoding APIs", default = true, type = "boolean"})
  16. add_configs("device_io", {description = "Enable playback and recording", default = true, type = "boolean"})
  17. add_configs("disabled_backends", {description = "Disabled backends (none if empty)", default = {}, type = "table"})
  18. add_configs("encoding", {description = "Enable encoding APIs", default = true, type = "boolean"})
  19. add_configs("enabled_backends", {description = "Enabled backends (all if empty)", default = {}, type = "table"})
  20. add_configs("engine", {description = "Enable the engine API", default = true, type = "boolean"})
  21. add_configs("flac", {description = "Enable the builtin FLAC decoder", default = true, type = "boolean"})
  22. add_configs("generation", {description = "Enable the generation APIs", default = true, type = "boolean"})
  23. add_configs("mp3", {description = "Enable the builtin MP3 decoder", default = true, type = "boolean"})
  24. add_configs("neon", {description = "Enable Neon optimizations", default = true, type = "boolean"})
  25. add_configs("node_graph", {description = "Enable the node graph API (required for engine)", default = true, type = "boolean"})
  26. add_configs("resource_manager", {description = "Enable the resource manager", default = true, type = "boolean"})
  27. add_configs("sse2", {description = "Enable SSE2 optimizations", default = true, type = "boolean"})
  28. add_configs("threading", {description = "Enable the threading API", default = true, type = "boolean"})
  29. add_configs("wav", {description = "Enable the builtin WAV decoder and encoder", default = true, type = "boolean"})
  30. if is_plat("iphoneos") then
  31. add_frameworks("AudioToolbox", "AVFoundation", "CoreFoundation", "Foundation")
  32. elseif is_plat("macosx") then
  33. add_defines("MA_NO_RUNTIME_LINKING")
  34. add_frameworks("AudioToolbox", "CoreAudio", "AudioUnit", "AVFoundation", "CoreFoundation", "Foundation")
  35. end
  36. if is_plat("linux", "bsd") then
  37. add_syslinks("pthread")
  38. end
  39. on_load(function (package)
  40. if package:config("headeronly") then
  41. package:set("kind", "library", {headeronly = true})
  42. end
  43. local defines = import("build_defines")(package)
  44. if #defines > 0 then
  45. package:add("defines", table.unwrap(defines))
  46. end
  47. end)
  48. on_install(function (package)
  49. if package:config("headeronly") then
  50. os.cp("miniaudio.h", package:installdir("include"))
  51. else
  52. local defines = import("build_defines")(package)
  53. if package:is_plat("macosx", "iphoneos") then
  54. io.writefile("extras/miniaudio_split/miniaudio.m", "#include \"miniaudio.c\"")
  55. end
  56. local definelist = table.concat(table.imap(defines, function (_, d) return " add_defines(\"" .. d .. "\")" end), "\n")
  57. io.writefile("xmake.lua", [[
  58. add_rules("mode.debug", "mode.release")
  59. target("miniaudio")
  60. set_kind("$(kind)")
  61. add_headerfiles("extras/miniaudio_split/(miniaudio.h)")
  62. if is_plat("macosx", "iphoneos") then
  63. add_files("extras/miniaudio_split/miniaudio.m")
  64. else
  65. add_files("extras/miniaudio_split/miniaudio.c")
  66. end
  67. add_defines("MINIAUDIO_IMPLEMENTATION")
  68. ]] .. definelist)
  69. import("package.tools.xmake").install(package)
  70. end
  71. os.cp("extras/nodes", package:installdir("include"))
  72. end)
  73. on_test(function (package)
  74. local check_snippets = package.check_csnippets
  75. if package:config("headeronly") and package:is_plat("macosx", "iphoneos") then
  76. check_snippets = package.check_msnippets
  77. end
  78. assert(check_snippets(package, {test = [[
  79. void test() {
  80. ma_uint32 major, minor, rev;
  81. ma_version(&major, &minor, &rev);
  82. }
  83. ]]}, {includes = {"miniaudio.h"}, configs = {defines = package:config("headeronly") and "MINIAUDIO_IMPLEMENTATION" or nil}}))
  84. end)