xmake.lua 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package("libusb")
  2. set_homepage("https://libusb.info")
  3. set_description("A cross-platform library to access USB devices ")
  4. set_license("LGPL-2.1")
  5. add_urls("https://github.com/libusb/libusb/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/libusb/libusb.git")
  7. add_versions("v1.0.29", "7c2dd39c0b2589236e48c93247c986ae272e27570942b4163cb00a060fcf1b74")
  8. add_versions("v1.0.28", "378b3709a405065f8f9fb9f35e82d666defde4d342c2a1b181a9ac134d23c6fe")
  9. add_versions("v1.0.27", "e8f18a7a36ecbb11fb820bd71540350d8f61bcd9db0d2e8c18a6fb80b214a3de")
  10. add_versions("v1.0.26", "a09bff99c74e03e582aa30759cada218ea8fa03580517e52d463c59c0b25e240")
  11. add_resources(">=1.0.26", "libusb-cmake", "https://github.com/libusb/libusb-cmake.git", "8f0b4a38fc3eefa2b26a99dff89e1c12bf37afd4")
  12. add_patches("v1.0.26", "patches/windows-add-clock-gettime-check.patch", "38cc23fd5a9c2445951dbe6c6f19e677d333f82332ff5be18a4f362637265f0d")
  13. if is_plat("macosx") then
  14. add_extsources("brew::libusb")
  15. elseif is_plat("linux") then
  16. add_extsources("apt::libusb-dev", "pacman::libusb")
  17. elseif is_plat("mingw") and is_subhost("msys") then
  18. add_extsources("pacman::libusb")
  19. end
  20. if is_plat("macosx") then
  21. add_frameworks("CoreFoundation", "IOKit", "Security")
  22. elseif is_plat("linux", "bsd") then
  23. add_syslinks("pthread")
  24. end
  25. add_deps("cmake")
  26. if is_plat("linux", "cross") then
  27. add_deps("eudev")
  28. end
  29. add_includedirs("include", "include/libusb-1.0")
  30. -- https://github.com/emscripten-core/emscripten/issues/13017
  31. if is_plat("wasm") then
  32. add_ldflags("--bind", "-s ASYNCIFY=1")
  33. end
  34. on_check("wasm", function (package)
  35. if package:version() and package:version():le("1.0.26") then
  36. raise("package(libusb <=1.0.26) unsupported platform!")
  37. end
  38. end)
  39. -- @see https://github.com/libusb/libusb-cmake/issues/33#issuecomment-3028680966
  40. on_install("!iphoneos and !bsd", function (package)
  41. local dir = package:resourcefile("libusb-cmake")
  42. os.cp(path.join(dir, "CMakeLists.txt"), os.curdir())
  43. os.cp(path.join(dir, "config.h.in"), os.curdir())
  44. io.replace("CMakeLists.txt",
  45. [[get_filename_component(LIBUSB_ROOT "libusb/libusb" ABSOLUTE)]],
  46. [[get_filename_component(LIBUSB_ROOT "libusb" ABSOLUTE)]], {plain = true})
  47. local configs = {}
  48. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  49. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  50. local opt = {}
  51. if package:is_plat("linux", "cross") then
  52. opt.packagedeps = {"eudev"}
  53. end
  54. if package:config("shared") and package:is_plat("macosx") then
  55. opt.shflags = {"-framework", "CoreFoundation", "-framework", "IOKit", "-framework", "Security"}
  56. end
  57. import("package.tools.cmake").install(package, configs, opt)
  58. end)
  59. on_test(function (package)
  60. assert(package:has_cfuncs("libusb_init", {includes = "libusb-1.0/libusb.h"}))
  61. end)