xmake.lua 2.4 KB

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