xmake.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. if is_plat("iphoneos") then
  33. add_frameworks("AudioToolbox", "AVFoundation", "CoreFoundation", "Foundation")
  34. elseif is_plat("macosx") then
  35. add_defines("MA_NO_RUNTIME_LINKING")
  36. add_frameworks("AudioToolbox", "CoreAudio", "AudioUnit", "AVFoundation", "CoreFoundation", "Foundation")
  37. end
  38. if is_plat("linux", "bsd") then
  39. add_syslinks("pthread")
  40. end
  41. on_load(function (package)
  42. if package:config("headeronly") then
  43. package:set("kind", "library", {headeronly = true})
  44. end
  45. local defines = import("build_defines")(package)
  46. if #defines > 0 then
  47. package:add("defines", table.unwrap(defines))
  48. end
  49. end)
  50. on_install(function (package)
  51. if package:config("extra_nodes") then
  52. -- fix extra nodes includes since we are changing path
  53. for _, nodeheader in ipairs(os.files("extras/nodes/**.h")) do
  54. io.replace(nodeheader, [[#include "../../../miniaudio.h"]], [[#include "miniaudio.h"]], {plain = true})
  55. end
  56. end
  57. if package:config("headeronly") then
  58. os.cp("miniaudio.h", package:installdir("include"))
  59. if package:config("extra_nodes") then
  60. os.cp("extras/nodes", package:installdir("include"))
  61. end
  62. else
  63. if package:is_plat("macosx", "iphoneos") then
  64. io.writefile("extras/miniaudio_split/miniaudio.m", "#include \"miniaudio.c\"")
  65. end
  66. local xmakefile = io.open("xmake.lua", "w")
  67. xmakefile:write([[
  68. add_rules("mode.debug", "mode.release")
  69. target("miniaudio")
  70. set_kind("$(kind)")
  71. add_headerfiles("extras/miniaudio_split/(miniaudio.h)")
  72. if is_plat("macosx", "iphoneos") then
  73. add_files("extras/miniaudio_split/miniaudio.m")
  74. else
  75. add_files("extras/miniaudio_split/miniaudio.c")
  76. end
  77. add_defines("MINIAUDIO_IMPLEMENTATION")
  78. ]])
  79. if package:config("extra_nodes") then
  80. xmakefile:write([[
  81. add_includedirs("extras/miniaudio_split")
  82. add_headerfiles("extras/(nodes/**.h)")
  83. add_files("extras/nodes/**.c|**_example.c")
  84. ]])
  85. end
  86. local defines = import("build_defines")(package)
  87. for _, define in ipairs(defines) do
  88. xmakefile:write(" add_defines(\"" .. define .. "\")\n")
  89. end
  90. xmakefile:close()
  91. import("package.tools.xmake").install(package)
  92. end
  93. end)
  94. on_test(function (package)
  95. local check_snippets = package.check_csnippets
  96. if package:config("headeronly") and package:is_plat("macosx", "iphoneos") then
  97. check_snippets = package.check_msnippets
  98. end
  99. assert(check_snippets(package, {test = [[
  100. void test() {
  101. ma_uint32 major, minor, rev;
  102. ma_version(&major, &minor, &rev);
  103. }
  104. ]]}, {includes = {"miniaudio.h"}, configs = {defines = package:config("headeronly") and "MINIAUDIO_IMPLEMENTATION" or nil}}))
  105. end)