xmake.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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("v4.5.0", "2e884a4c826dd87157ee4fab8cd8c7b9dbbc1ddb804cb10ef0852094200724db")
  8. add_versions("v3.0", "133b40396ca72e35d94cb0950199c9d123352951e4705971a9cd7606f905328a")
  9. add_configs("header_only", {description = "Use header only version.", default = false, type = "boolean"})
  10. add_configs("boost", {description = "Use boost::small_vector to pass midi bytes instead of std::vector to reduce allocations.", default = false, type = "boolean"})
  11. add_configs("jack", {description = "Enable JACK back-end", default = false, type = "boolean"})
  12. add_configs("slim_message", {description = "Use a fixed-size message format", default = "0", type = "string"})
  13. if is_plat("windows", "mingw") then
  14. add_syslinks("winmm")
  15. elseif is_plat("macosx") then
  16. add_frameworks("CoreFoundation", "CoreMIDI", "CoreAudio")
  17. elseif is_plat("iphoneos") then
  18. add_frameworks("CoreMIDI")
  19. elseif is_plat("linux", "bsd") then
  20. add_syslinks("pthread")
  21. end
  22. add_deps("cmake")
  23. on_load(function (package)
  24. if package:config("header_only") then
  25. package:set("kind", "library", {headeronly = true})
  26. package:add("defines", "LIBREMIDI_HEADER_ONLY=1")
  27. if package:config("jack") then
  28. package:add("defines", "LIBREMIDI_JACK=1")
  29. end
  30. if package:is_plat("windows") then
  31. package:add("defines", "LIBREMIDI_WINMM=1")
  32. -- TODO: support UWP
  33. -- package:add("defines", "LIBREMIDI_WINUWP=1")
  34. elseif package:is_plat("linux") then
  35. package:add("defines", "LIBREMIDI_ALSA=1")
  36. elseif package:is_plat("wasm") then
  37. package:add("defines", "LIBREMIDI_EMSCRIPTEN=1")
  38. end
  39. end
  40. if package:config("boost") then
  41. package:add("deps", "boost")
  42. end
  43. end)
  44. on_install(function (package)
  45. local configs = {"-DLIBREMIDI_EXAMPLES=OFF", "-DLIBREMIDI_TESTS=OFF"}
  46. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  47. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  48. table.insert(configs, "-DLIBREMIDI_HEADER_ONLY=" .. (package:config("header_only") and "ON" or "OFF"))
  49. table.insert(configs, "-DLIBREMIDI_NO_JACK=" .. (package:config("jack") and "OFF" or "ON"))
  50. table.insert(configs, "-DLIBREMIDI_SLIM_MESSAGE=" .. package:config("slim_message"))
  51. if package:config("boost") then
  52. table.insert(configs, "-DLIBREMIDI_NO_BOOST=OFF")
  53. table.insert(configs, "-DLIBREMIDI_FIND_BOOST=ON")
  54. else
  55. table.insert(configs, "-DLIBREMIDI_NO_BOOST=ON")
  56. end
  57. io.replace("CMakeLists.txt", " ARCHIVE DESTINATION lib/static", " ARCHIVE DESTINATION lib", {plain = true})
  58. import("package.tools.cmake").install(package, configs)
  59. end)
  60. on_test(function (package)
  61. local code
  62. if package:version():lt("4.0.0") then
  63. code = [[
  64. void test() {
  65. libremidi::midi_in midi;
  66. for (int i = 0, N = midi.get_port_count(); i < N; i++) {
  67. std::string name = midi.get_port_name(i);
  68. }
  69. }
  70. ]]
  71. else
  72. code = [[
  73. void test() {
  74. libremidi::observer obs;
  75. for(const libremidi::input_port& port : obs.get_input_ports()) {}
  76. }
  77. ]]
  78. end
  79. assert(package:check_cxxsnippets({test = code}, {configs = {languages = "c++20"}, includes = {"libremidi/libremidi.hpp"}}))
  80. end)