xmake.lua 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package("libremidi")
  2. set_homepage("https://github.com/jcelerier/libremidi")
  3. set_description("A modern C++ MIDI real-time & file I/O library. Supports Windows, macOS, Linux and WebMIDI.")
  4. set_license("BSD-2-Clause")
  5. add_urls("https://github.com/jcelerier/libremidi/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/jcelerier/libremidi.git")
  7. add_versions("v3.0", "133b40396ca72e35d94cb0950199c9d123352951e4705971a9cd7606f905328a")
  8. add_configs("header_only", {description = "Use header only version.", default = false, type = "boolean"})
  9. add_configs("boost", {description = "Use boost::small_vector to pass midi bytes instead of std::vector to reduce allocations.", default = false, type = "boolean"})
  10. add_configs("jack", {description = "Enable JACK back-end", default = false, type = "boolean"})
  11. add_configs("slim_message", {description = "Use a fixed-size message format", default = "0", type = "string"})
  12. if is_plat("windows", "mingw") then
  13. add_syslinks("winmm")
  14. elseif is_plat("macosx") then
  15. add_frameworks("CoreFoundation", "CoreMIDI", "CoreAudio")
  16. elseif is_plat("iphoneos") then
  17. add_frameworks("CoreMIDI")
  18. elseif is_plat("linux", "bsd") then
  19. add_syslinks("pthread")
  20. end
  21. add_deps("cmake")
  22. on_load(function (package)
  23. if package:config("header_only") then
  24. package:set("library", {headeronly = true})
  25. package:add("defines", "LIBREMIDI_HEADER_ONLY=1")
  26. if package:config("jack") then
  27. package:add("defines", "LIBREMIDI_JACK=1")
  28. end
  29. if package:is_plat("windows") then
  30. package:add("defines", "LIBREMIDI_WINMM=1")
  31. -- TODO: support UWP
  32. -- package:add("defines", "LIBREMIDI_WINUWP=1")
  33. elseif package:is_plat("linux") then
  34. package:add("defines", "LIBREMIDI_ALSA=1")
  35. elseif package:is_plat("wasm") then
  36. package:add("defines", "LIBREMIDI_EMSCRIPTEN=1")
  37. end
  38. end
  39. if package:config("boost") then
  40. package:add("deps", "boost")
  41. end
  42. end)
  43. on_install(function (package)
  44. local configs = {"-DLIBREMIDI_EXAMPLES=OFF", "-DLIBREMIDI_TESTS=OFF"}
  45. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  46. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  47. table.insert(configs, "-DLIBREMIDI_HEADER_ONLY=" .. (package:config("header_only") and "ON" or "OFF"))
  48. table.insert(configs, "-DLIBREMIDI_NO_JACK=" .. (package:config("jack") and "OFF" or "ON"))
  49. table.insert(configs, "-DLIBREMIDI_SLIM_MESSAGE=" .. package:config("slim_message"))
  50. if package:config("boost") then
  51. table.insert(configs, "-DLIBREMIDI_NO_BOOST=OFF")
  52. table.insert(configs, "-DLIBREMIDI_FIND_BOOST=ON")
  53. else
  54. table.insert(configs, "-DLIBREMIDI_NO_BOOST=ON")
  55. end
  56. io.replace("CMakeLists.txt", " ARCHIVE DESTINATION lib/static", " ARCHIVE DESTINATION lib", {plain = true})
  57. import("package.tools.cmake").install(package, configs)
  58. end)
  59. on_test(function (package)
  60. -- TODO: v4 version will break api
  61. assert(package:check_cxxsnippets({test = [[
  62. #include <libremidi/libremidi.hpp>
  63. void test() {
  64. libremidi::midi_in midi;
  65. for (int i = 0, N = midi.get_port_count(); i < N; i++) {
  66. std::string name = midi.get_port_name(i);
  67. }
  68. }
  69. ]]}, {configs = {languages = "c++20"}}))
  70. end)