xmake.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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("v5.3.1", "b68cdb81feb168bfafa44a139c76b459ff622e75c36fda76b39baf2f3efabdd6")
  8. add_versions("v5.3.0", "56d23d13c8d3fc40f0b46442af320865d485da908ad52d8950a87e05f9073c87")
  9. add_versions("v5.2.0", "d34a2e8aaede56f234f0f1b653fef0d84aeae1084e66d71c7237c85280d4be1a")
  10. add_versions("v5.1.0", "bd5f2f81fbed58c9d926741f5df5ec5b714854004492d1cf30609f650e199338")
  11. add_versions("v4.5.0", "2e884a4c826dd87157ee4fab8cd8c7b9dbbc1ddb804cb10ef0852094200724db")
  12. add_versions("v3.0", "133b40396ca72e35d94cb0950199c9d123352951e4705971a9cd7606f905328a")
  13. add_configs("header_only", {description = "Use header only version.", default = false, type = "boolean"})
  14. add_configs("boost", {description = "Use boost::small_vector to pass midi bytes instead of std::vector to reduce allocations.", default = false, type = "boolean"})
  15. add_configs("slim_message", {description = "Use a fixed-size message format", default = "0", type = "string"})
  16. add_configs("win_mm", {description = "Enable WinMM back-end", default = is_plat("windows", "mingw"), type = "boolean"})
  17. add_configs("win_uwp", {description = "Enable UWP back-end", default = false, type = "boolean"})
  18. add_configs("win_midi", {description = "Enable WinMIDI back-end", default = false, type = "boolean"})
  19. add_configs("jack", {description = "Enable JACK back-end", default = false, type = "boolean"})
  20. if is_plat("macosx") then
  21. add_frameworks("CoreFoundation", "CoreMIDI", "CoreAudio")
  22. elseif is_plat("iphoneos") then
  23. add_frameworks("CoreMIDI")
  24. elseif is_plat("linux", "bsd") then
  25. add_syslinks("pthread")
  26. end
  27. add_deps("cmake")
  28. on_load(function (package)
  29. if package:config("header_only") then
  30. package:set("kind", "library", {headeronly = true})
  31. package:add("defines", "LIBREMIDI_HEADER_ONLY")
  32. end
  33. if package:config("shared") then
  34. package:add("defines", "LIBREMIDI_EXPORTS")
  35. end
  36. if package:config("jack") then
  37. package:add("defines", "LIBREMIDI_JACK")
  38. end
  39. if package:config("win_mm") then
  40. package:add("defines", "LIBREMIDI_WINMM")
  41. package:add("syslinks", "winmm")
  42. end
  43. if package:config("win_uwp") then
  44. package:add("defines", "LIBREMIDI_WINUWP")
  45. package:add("syslinks", "RuntimeObject")
  46. end
  47. if package:config("win_midi") then
  48. -- TODO: libremidi.winmidi.cmake will donwload winmidi-headers, package it or add_resources?
  49. package:add("defines", "LIBREMIDI_WINMIDI")
  50. package:add("syslinks", "RuntimeObject")
  51. end
  52. if package:is_plat("linux") then
  53. package:add("defines", "LIBREMIDI_ALSA")
  54. elseif package:is_plat("wasm") then
  55. package:add("defines", "LIBREMIDI_EMSCRIPTEN")
  56. end
  57. if package:config("boost") then
  58. package:add("deps", "boost")
  59. end
  60. end)
  61. on_install(function (package)
  62. io.replace("CMakeLists.txt", " ARCHIVE DESTINATION lib/static", " ARCHIVE DESTINATION lib", {plain = true})
  63. local configs = {"-DLIBREMIDI_EXAMPLES=OFF", "-DLIBREMIDI_TESTS=OFF", "-DLIBREMIDI_NO_WARNINGS=ON"}
  64. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  65. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  66. table.insert(configs, "-DLIBREMIDI_NO_EXPORTS=" .. (package:config("shared") and "OFF" or "ON"))
  67. table.insert(configs, "-DLIBREMIDI_HEADER_ONLY=" .. (package:config("header_only") and "ON" or "OFF"))
  68. table.insert(configs, "-DLIBREMIDI_SLIM_MESSAGE=" .. package:config("slim_message"))
  69. if package:config("boost") then
  70. table.insert(configs, "-DLIBREMIDI_NO_BOOST=OFF")
  71. table.insert(configs, "-DLIBREMIDI_FIND_BOOST=ON")
  72. else
  73. table.insert(configs, "-DLIBREMIDI_NO_BOOST=ON")
  74. end
  75. table.insert(configs, "-DLIBREMIDI_NO_JACK=" .. (package:config("jack") and "OFF" or "ON"))
  76. table.insert(configs, "-DLIBREMIDI_NO_WINMM=" .. (package:config("win_mm") and "OFF" or "ON"))
  77. table.insert(configs, "-DLIBREMIDI_NO_WINUWP=" .. (package:config("win_uwp") and "OFF" or "ON"))
  78. table.insert(configs, "-DLIBREMIDI_NO_WINMIDI=" .. (package:config("win_midi") and "OFF" or "ON"))
  79. import("package.tools.cmake").install(package, configs)
  80. if package:is_plat("windows") and package:config("shared") then
  81. local src = "#define LIBREMIDI_EXPORT __declspec(dllexport)"
  82. local dst = "#define LIBREMIDI_EXPORT __declspec(dllimport)"
  83. local include = package:installdir("include/libremidi")
  84. io.replace(path.join(include, "config.hpp"), src, dst, {plain = true})
  85. io.replace(path.join(include, "libremidi-c.h"), src, dst, {plain = true})
  86. end
  87. end)
  88. on_test(function (package)
  89. local code
  90. if package:version() and package:version():lt("4.0.0") then
  91. code = [[
  92. void test() {
  93. libremidi::midi_in midi;
  94. for (int i = 0, N = midi.get_port_count(); i < N; i++) {
  95. std::string name = midi.get_port_name(i);
  96. }
  97. }
  98. ]]
  99. else
  100. code = [[
  101. void test() {
  102. libremidi::observer obs;
  103. for(const libremidi::input_port& port : obs.get_input_ports()) {}
  104. }
  105. ]]
  106. end
  107. assert(package:check_cxxsnippets({test = code}, {configs = {languages = "c++20"}, includes = {"libremidi/libremidi.hpp"}}))
  108. end)