xmake.lua 5.0 KB

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