2
0

xmake.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.27", "e8f18a7a36ecbb11fb820bd71540350d8f61bcd9db0d2e8c18a6fb80b214a3de")
  8. add_versions("v1.0.26", "a09bff99c74e03e582aa30759cada218ea8fa03580517e52d463c59c0b25e240")
  9. add_resources(">=1.0.26", "libusb-cmake", "https://github.com/libusb/libusb-cmake.git", "8f0b4a38fc3eefa2b26a99dff89e1c12bf37afd4")
  10. if is_plat("macosx") then
  11. add_frameworks("CoreFoundation", "IOKit", "Security")
  12. add_extsources("brew::libusb")
  13. elseif is_plat("bsd") then
  14. add_syslinks("pthread")
  15. elseif is_plat("linux") then
  16. add_deps("eudev")
  17. add_syslinks("pthread")
  18. add_extsources("apt::libusb-dev", "pacman::libusb")
  19. elseif is_plat("mingw") and is_subhost("msys") then
  20. add_extsources("pacman::libusb")
  21. end
  22. add_deps("cmake")
  23. add_includedirs("include", "include/libusb-1.0")
  24. on_install("windows", "linux", "macosx", "bsd", "msys", "android", function (package)
  25. local dir = package:resourcefile("libusb-cmake")
  26. os.cp(path.join(dir, "CMakeLists.txt"), os.curdir())
  27. os.cp(path.join(dir, "config.h.in"), os.curdir())
  28. io.replace("CMakeLists.txt",
  29. [[get_filename_component(LIBUSB_ROOT "libusb/libusb" ABSOLUTE)]],
  30. [[get_filename_component(LIBUSB_ROOT "libusb" ABSOLUTE)]], {plain = true})
  31. local configs = {}
  32. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  33. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  34. local packagedeps = {}
  35. if package:is_plat("linux") then
  36. table.insert(packagedeps, "eudev")
  37. end
  38. import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps})
  39. end)
  40. on_test(function (package)
  41. assert(package:has_cfuncs("libusb_init", {includes = "libusb-1.0/libusb.h"}))
  42. end)