xmake.lua 2.3 KB

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