xmake.lua 2.1 KB

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