xmake.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package("libsdl_mixer")
  2. set_homepage("https://www.libsdl.org/projects/SDL_mixer/")
  3. set_description("Simple DirectMedia Layer mixer audio library")
  4. set_license("zlib")
  5. add_urls("https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-$(version).zip",
  6. "https://github.com/libsdl-org/SDL_mixer/releases/download/release-$(version)/SDL2_mixer-$(version).zip")
  7. add_versions("2.0.4", "9affb8c7bf6fbffda0f6906bfb99c0ea50dca9b188ba9e15be90042dc03c5ded")
  8. add_versions("2.6.0", "aca0ffc96a4bf2a56a16536a269de28e341ce38a46a25180bc1ef75e19b08a3a")
  9. add_versions("2.6.1", "788c748c1d3a87126511e60995b03526ed4e31e2ba053dffd9dcc8abde97b950")
  10. add_versions("2.6.2", "61549615a67e731805ca1df553e005be966a625c1d20fb085bf99edeef6e0469")
  11. add_versions("2.8.0", "02df784cc68723419dd266530ee6964f810a6f02a27b03ecc85689c2e5e442ce")
  12. if is_plat("mingw") and is_subhost("msys") then
  13. add_extsources("pacman::SDL2_mixer")
  14. elseif is_plat("linux") then
  15. add_extsources("pacman::sdl2_mixer", "apt::libsdl2-mixer-dev")
  16. elseif is_plat("macosx") then
  17. add_extsources("brew::sdl2_mixer")
  18. end
  19. add_deps("cmake")
  20. add_includedirs("include", "include/SDL2")
  21. if is_plat("wasm") then
  22. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  23. end
  24. on_load(function (package)
  25. package:add("deps", "libsdl", { configs = { shared = package:config("shared") }})
  26. end)
  27. on_install(function (package)
  28. if package:is_plat("wasm") then
  29. io.replace("CMakeLists.txt", "sdl_find_sdl2(${sdl2_target_name} ${SDL_REQUIRED_VERSION})", "", {plain = true})
  30. io.replace("CMakeLists.txt", "target_link_libraries(SDL2_mixer PRIVATE $<BUILD_INTERFACE:${sdl2_target_name}>)", [[
  31. target_include_directories(SDL2_mixer PRIVATE ${SDL2_INCLUDE_DIR})
  32. target_link_libraries(SDL2_mixer PRIVATE $<BUILD_INTERFACE:${SDL2_LIBRARY}>)
  33. ]], {plain = true})
  34. io.replace("CMakeLists.txt", "target_link_libraries(SDL2_mixer PRIVATE ${sdl2_target_name})", [[
  35. target_include_directories(SDL2_mixer PRIVATE ${SDL2_INCLUDE_DIR})
  36. target_link_libraries(SDL2_mixer PRIVATE ${SDL2_LIBRARY})
  37. ]], {plain = true})
  38. end
  39. local configs = {
  40. "-DSDL2MIXER_CMD=OFF",
  41. "-DSDL2MIXER_FLAC=OFF",
  42. "-DSDL2MIXER_GME=OFF",
  43. "-DSDL2MIXER_MIDI=OFF",
  44. "-DSDL2MIXER_MOD=OFF",
  45. "-DSDL2MIXER_MP3=ON", -- was on by not being here
  46. "-DSDL2MIXER_OPUS=OFF",
  47. "-DSDL2MIXER_SAMPLES=OFF",
  48. "-DSDL2MIXER_WAVE=ON", -- was on by not being here
  49. "-DSDL2MIXER_WAVPACK=OFF",
  50. }
  51. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  52. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  53. local libsdl = package:dep("libsdl")
  54. if libsdl and not libsdl:is_system() then
  55. table.insert(configs, "-DSDL2_DIR=" .. libsdl:installdir())
  56. local fetchinfo = libsdl:fetch()
  57. if fetchinfo then
  58. for _, dir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do
  59. if os.isfile(path.join(dir, "SDL_version.h")) then
  60. table.insert(configs, "-DSDL2_INCLUDE_DIR=" .. dir)
  61. break
  62. end
  63. end
  64. local libfiles = {}
  65. for _, libfile in ipairs(fetchinfo.libfiles) do
  66. if libfile:match("SDL2%..+$") or libfile:match("SDL2-static%..+$") then
  67. if not (package:config("shared") and libfile:endswith(".dll")) then
  68. table.insert(libfiles, libfile)
  69. end
  70. end
  71. end
  72. table.insert(configs, "-DSDL2_LIBRARY=" .. table.concat(libfiles, ";"))
  73. end
  74. end
  75. import("package.tools.cmake").install(package, configs)
  76. end)
  77. on_test(function (package)
  78. assert(package:check_cxxsnippets({test = [[
  79. #include <SDL2/SDL.h>
  80. #include <SDL2/SDL_mixer.h>
  81. int main(int argc, char** argv) {
  82. Mix_Init(MIX_INIT_OGG);
  83. Mix_Quit();
  84. return 0;
  85. }
  86. ]]}, {configs = {defines = "SDL_MAIN_HANDLED"}}));
  87. end)