xmake.lua 4.6 KB

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