xmake.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. if is_plat("macosx") then
  13. add_extsources("brew::libusb")
  14. elseif is_plat("linux") then
  15. add_extsources("apt::libusb-dev", "pacman::libusb")
  16. elseif is_plat("mingw") and is_subhost("msys") then
  17. add_extsources("pacman::libusb")
  18. end
  19. if is_plat("macosx") then
  20. add_frameworks("CoreFoundation", "IOKit", "Security")
  21. elseif is_plat("linux", "bsd") then
  22. add_syslinks("pthread")
  23. end
  24. add_deps("cmake")
  25. if is_plat("linux", "cross") then
  26. add_deps("eudev")
  27. end
  28. add_includedirs("include", "include/libusb-1.0")
  29. -- https://github.com/emscripten-core/emscripten/issues/13017
  30. if is_plat("wasm") then
  31. add_ldflags("--bind", "-s ASYNCIFY=1")
  32. end
  33. on_install("!iphoneos and !bsd", function (package)
  34. local dir = package:resourcefile("libusb-cmake")
  35. os.cp(path.join(dir, "CMakeLists.txt"), os.curdir())
  36. os.cp(path.join(dir, "config.h.in"), os.curdir())
  37. io.replace("CMakeLists.txt",
  38. [[get_filename_component(LIBUSB_ROOT "libusb/libusb" ABSOLUTE)]],
  39. [[get_filename_component(LIBUSB_ROOT "libusb" ABSOLUTE)]], {plain = true})
  40. local configs = {}
  41. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  42. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  43. local opt = {}
  44. if package:is_plat("linux", "cross") then
  45. opt.packagedeps = {"eudev"}
  46. end
  47. if package:config("shared") and package:is_plat("macosx") then
  48. opt.shflags = {"-framework", "CoreFoundation", "-framework", "IOKit", "-framework", "Security"}
  49. end
  50. import("package.tools.cmake").install(package, configs, opt)
  51. end)
  52. on_test(function (package)
  53. assert(package:has_cfuncs("libusb_init", {includes = "libusb-1.0/libusb.h"}))
  54. end)