xmake.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package("libusb")
  2. set_homepage("https://libusb.info")
  3. set_description("A cross-platform library to access USB devices.")
  4. set_urls("https://github.com/libusb/libusb/archive/$(version).tar.gz",
  5. "https://github.com/libusb/libusb.git")
  6. add_versions("v1.0.24", "b7724c272dfc5713dce88ff717efd60f021ca5b7c8e30f08ebb2c42d2eea08ae")
  7. add_versions("v1.0.23", "02620708c4eea7e736240a623b0b156650c39bfa93a14bcfa5f3e05270313eba")
  8. if is_plat("macosx", "linux") then
  9. add_deps("autoconf", "automake", "libtool", "pkg-config")
  10. if is_plat("linux") then
  11. add_deps("eudev")
  12. end
  13. end
  14. if is_plat("macosx") then
  15. add_frameworks("CoreFoundation", "IOKit")
  16. elseif is_plat("linux") then
  17. add_syslinks("pthread")
  18. end
  19. -- it will be provided in xmake v2.5.2
  20. if add_extsources then
  21. add_extsources("pkgconfig::libusb-1.0")
  22. end
  23. add_includedirs("include", "include/libusb-1.0")
  24. on_install("windows", function (package)
  25. import("core.tool.toolchain")
  26. local arch = package:is_arch("x86") and "Win32" or "x64"
  27. local mode = package:debug() and "Debug" or "Release"
  28. local vs = toolchain.load("msvc"):config("vs") or "2019"
  29. local configs = {"libusb_" .. vs .. ".sln"}
  30. table.insert(configs, "/property:Configuration=" .. mode)
  31. table.insert(configs, "/property:Platform=" .. arch)
  32. local oldir = os.cd("msvc")
  33. import("package.tools.msbuild").build(package, configs)
  34. os.cd(oldir)
  35. os.vcp("libusb/*.h", package:installdir("include/libusb-1.0"))
  36. if package:config("shared") then
  37. os.vcp(path.join(arch, mode, "dll/libusb-1.0.dll"), package:installdir("lib"))
  38. os.vcp(path.join(arch, mode, "dll/libusb-1.0.lib"), package:installdir("lib"))
  39. else
  40. os.vcp(path.join(arch, mode, "lib/libusb-1.0.lib"), package:installdir("lib"))
  41. end
  42. end)
  43. on_install("macosx", "linux", function (package)
  44. local configs = {}
  45. if package:config("shared") then
  46. table.insert(configs, "--enable-shared=yes")
  47. else
  48. table.insert(configs, "--enable-shared=no")
  49. end
  50. if package:config("pic") ~= false then
  51. table.insert(configs, "--with-pic")
  52. end
  53. local cflags, ldflags
  54. if package:is_plat("linux") then
  55. cflags = "-I" .. package:dep("eudev"):installdir("include")
  56. ldflags = "-L" .. package:dep("eudev"):installdir("lib")
  57. end
  58. import("package.tools.autoconf").install(package, configs, {cflags = cflags, ldflags = ldflags})
  59. end)
  60. on_test(function (package)
  61. assert(package:has_cfuncs("libusb_init", {includes = "libusb-1.0/libusb.h"}))
  62. end)