xmake.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package("libusb")
  2. set_homepage("https://libusb.info")
  3. set_description("A cross-platform library to access USB devices.")
  4. if is_plat("mingw") then
  5. add_urls("https://github.com/libusb/libusb/releases/download/$(version).7z", {version = function (version)
  6. return version .. "/libusb-" .. (version:gsub("v", ""))
  7. end})
  8. add_versions("v1.0.24", "620CEC4DBE4868202949294157DA5ADB75C9FBB4F04266146FC833EEF85F90FB")
  9. else
  10. add_urls("https://github.com/libusb/libusb/releases/download/$(version).tar.bz2", {version = function (version)
  11. return version .. "/libusb-" .. (version:gsub("v", ""))
  12. end})
  13. add_urls("https://github.com/libusb/libusb.git")
  14. add_versions("v1.0.24", "7efd2685f7b327326dcfb85cee426d9b871fd70e22caa15bb68d595ce2a2b12a")
  15. end
  16. if is_plat("macosx", "linux") then
  17. add_deps("autoconf", "automake", "libtool", "pkg-config")
  18. if is_plat("linux") then
  19. add_deps("eudev")
  20. end
  21. end
  22. if is_plat("macosx") then
  23. add_frameworks("CoreFoundation", "IOKit")
  24. elseif is_plat("linux") then
  25. add_syslinks("pthread")
  26. end
  27. on_fetch("linux", "macosx", function(package, opt)
  28. if opt.system then
  29. return find_package("pkgconfig::libusb-1.0")
  30. end
  31. end)
  32. add_includedirs("include", "include/libusb-1.0")
  33. on_install("windows", function (package)
  34. import("core.tool.toolchain")
  35. local vsversion = toolchain.load("msvc"):config("vs") or "2019"
  36. local solutionFiles = {
  37. "libusb_" .. vsversion .. ".sln",
  38. "libusb_2019.sln",
  39. "libusb_2017.sln",
  40. "libusb_2015.sln",
  41. }
  42. local solutionFile
  43. local oldir = os.cd("msvc")
  44. for _, file in ipairs(solutionFiles) do
  45. if os.isfile(file) then
  46. solutionFile = file
  47. break
  48. end
  49. end
  50. assert(solutionFile, "solution file not found")
  51. local arch = package:is_arch("x86") and "Win32" or "x64"
  52. local mode = package:debug() and "Debug" or "Release"
  53. local configs = {solutionFile}
  54. table.insert(configs, "/property:Configuration=" .. mode)
  55. table.insert(configs, "/property:Platform=" .. arch)
  56. import("package.tools.msbuild").build(package, configs)
  57. os.cd(oldir)
  58. os.vcp("libusb/*.h", package:installdir("include/libusb-1.0"))
  59. if package:config("shared") then
  60. os.vcp(path.join(arch, mode, "dll/libusb-1.0.dll"), package:installdir("lib"))
  61. os.vcp(path.join(arch, mode, "dll/libusb-1.0.lib"), package:installdir("lib"))
  62. else
  63. os.vcp(path.join(arch, mode, "lib/libusb-1.0.lib"), package:installdir("lib"))
  64. end
  65. end)
  66. on_install("mingw", function (package)
  67. os.cp("include/libusb-1.0/*.h",package:installdir("include/libusb-1.0"))
  68. if package:is_arch("x64", "x86_64") then
  69. os.cp("MinGW64/dll/*", package:installdir("bin"))
  70. os.cp("MinGW64/static/*", package:installdir("lib"))
  71. elseif package:is_arch("x86", "i386") then
  72. os.cp("MinGW32/dll/*", package:installdir("bin"))
  73. os.cp("MinGW32/static/*", package:installdir("lib"))
  74. end
  75. end)
  76. on_install("macosx", "linux", function (package)
  77. local configs = {}
  78. table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
  79. table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
  80. if package:config("pic") ~= false then
  81. table.insert(configs, "--with-pic")
  82. end
  83. local cflags, ldflags
  84. if package:is_plat("linux") then
  85. cflags = "-I" .. package:dep("eudev"):installdir("include")
  86. ldflags = "-L" .. package:dep("eudev"):installdir("lib")
  87. end
  88. import("package.tools.autoconf").install(package, configs, {cflags = cflags, ldflags = ldflags})
  89. end)
  90. on_test(function (package)
  91. assert(package:has_cfuncs("libusb_init", {includes = "libusb-1.0/libusb.h"}))
  92. end)