xmake.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.23", "1062155cc5882b55c48cb37f57a4dc783669e83ae0838535c62b206eeb1587a6")
  8. add_versions("0.11.22", "bcb07bfb27e6fa94d34da73ba2d5642d4940b208ec2a660dbf4e52e6b7cd492f")
  9. add_versions("0.11.21", "6afb5c231613d2fab4f1c668b7243ff9a7d6d78a7f5a2692c133f026fe508506")
  10. add_versions("0.11.15", "24a6d38fe69cd42d91f6c1ad211bb559f6c89768c4671fa05b8027f5601d5457")
  11. add_versions("0.11.16", "13320464820491c61bd178b95818fecb7cd0e68f9677d61e1345df6be8d4d77e")
  12. add_versions("0.11.17", "4b139065f7068588b73d507d24e865060e942eb731f988ee5a8f1828155b9480")
  13. add_versions("0.11.18", "85ca916266d809b39902e180a6d16f82caea9c2ea1cea6d374413641b7ba48c3")
  14. add_configs("headeronly", {description = "Install the headeronly version (or the split one if disabled).", default = true, type = "boolean"})
  15. add_configs("avx2", {description = "Enable AVX2 optimizations", default = true, type = "boolean"})
  16. add_configs("decoding", {description = "Enable decoding APIs", default = true, type = "boolean"})
  17. add_configs("device_io", {description = "Enable playback and recording", default = true, type = "boolean"})
  18. add_configs("disabled_backends", {description = "Disabled backends (none if empty)", default = {}, type = "table"})
  19. add_configs("encoding", {description = "Enable encoding APIs", default = true, type = "boolean"})
  20. add_configs("enabled_backends", {description = "Enabled backends (all if empty)", default = {}, type = "table"})
  21. add_configs("engine", {description = "Enable the engine API", default = true, type = "boolean"})
  22. add_configs("extra_nodes", {description = "Enable extra nodes", default = true, type = "boolean"})
  23. add_configs("flac", {description = "Enable the builtin FLAC decoder", default = true, type = "boolean"})
  24. add_configs("generation", {description = "Enable the generation APIs", default = true, type = "boolean"})
  25. add_configs("mp3", {description = "Enable the builtin MP3 decoder", default = true, type = "boolean"})
  26. add_configs("neon", {description = "Enable Neon optimizations", default = true, type = "boolean"})
  27. add_configs("node_graph", {description = "Enable the node graph API (required for engine)", default = true, type = "boolean"})
  28. add_configs("resource_manager", {description = "Enable the resource manager", default = true, type = "boolean"})
  29. add_configs("sse2", {description = "Enable SSE2 optimizations", default = true, type = "boolean"})
  30. add_configs("threading", {description = "Enable the threading API", default = true, type = "boolean"})
  31. add_configs("wav", {description = "Enable the builtin WAV decoder and encoder", default = true, type = "boolean"})
  32. add_configs("worklets", {description = "Enable AudioWorklets when targeting web", default = false, type = "boolean"})
  33. if is_plat("iphoneos") then
  34. add_frameworks("AudioToolbox", "AVFoundation", "CoreFoundation", "Foundation")
  35. elseif is_plat("macosx") then
  36. add_defines("MA_NO_RUNTIME_LINKING")
  37. add_frameworks("AudioToolbox", "CoreAudio", "AudioUnit", "AVFoundation", "CoreFoundation", "Foundation")
  38. end
  39. if is_plat("linux", "bsd") then
  40. add_syslinks("pthread")
  41. end
  42. on_load(function (package)
  43. if package:config("headeronly") then
  44. package:set("kind", "library", {headeronly = true})
  45. end
  46. local defines = import("build_defines")(package)
  47. if #defines > 0 then
  48. package:add("defines", table.unwrap(defines))
  49. end
  50. end)
  51. on_install(function (package)
  52. if package:config("extra_nodes") then
  53. -- fix extra nodes includes since we are changing path
  54. for _, nodeheader in ipairs(os.files("extras/nodes/**.h")) do
  55. io.replace(nodeheader, [[#include "../../../miniaudio.h"]], [[#include "miniaudio.h"]], {plain = true})
  56. end
  57. end
  58. if package:config("headeronly") then
  59. os.cp("miniaudio.h", package:installdir("include"))
  60. if package:config("extra_nodes") then
  61. os.cp("extras/nodes", package:installdir("include"))
  62. end
  63. else
  64. if package:is_plat("macosx", "iphoneos") then
  65. io.writefile("extras/miniaudio_split/miniaudio.m", "#include \"miniaudio.c\"")
  66. end
  67. local xmakefile = io.open("xmake.lua", "w")
  68. xmakefile:write([[
  69. add_rules("mode.debug", "mode.release")
  70. target("miniaudio")
  71. set_kind("$(kind)")
  72. add_headerfiles("extras/miniaudio_split/(miniaudio.h)")
  73. if is_plat("macosx", "iphoneos") then
  74. add_files("extras/miniaudio_split/miniaudio.m")
  75. else
  76. add_files("extras/miniaudio_split/miniaudio.c")
  77. end
  78. add_defines("MINIAUDIO_IMPLEMENTATION")
  79. ]])
  80. if package:config("extra_nodes") then
  81. xmakefile:write([[
  82. add_includedirs("extras/miniaudio_split")
  83. add_headerfiles("extras/(nodes/**.h)")
  84. add_files("extras/nodes/**.c|**_example.c")
  85. ]])
  86. end
  87. local defines = import("build_defines")(package)
  88. for _, define in ipairs(defines) do
  89. xmakefile:write(" add_defines(\"" .. define .. "\")\n")
  90. end
  91. xmakefile:close()
  92. import("package.tools.xmake").install(package)
  93. end
  94. end)
  95. on_test(function (package)
  96. local check_snippets = package.check_csnippets
  97. if package:config("headeronly") and package:is_plat("macosx", "iphoneos") then
  98. check_snippets = package.check_msnippets
  99. end
  100. assert(check_snippets(package, {test = [[
  101. void test() {
  102. ma_uint32 major, minor, rev;
  103. ma_version(&major, &minor, &rev);
  104. }
  105. ]]}, {includes = {"miniaudio.h"}, configs = {defines = package:config("headeronly") and "MINIAUDIO_IMPLEMENTATION" or nil}}))
  106. end)