Browse Source

libusb: support more platform (#6935)

* libusb: support more platform

* support cross & wasm

* fix cross
star9029 5 months ago
parent
commit
f067dc05eb
1 changed files with 16 additions and 8 deletions
  1. 16 8
      packages/l/libusb/xmake.lua

+ 16 - 8
packages/l/libusb/xmake.lua

@@ -12,23 +12,31 @@ package("libusb")
     add_resources(">=1.0.26", "libusb-cmake", "https://github.com/libusb/libusb-cmake.git", "8f0b4a38fc3eefa2b26a99dff89e1c12bf37afd4")
 
     if is_plat("macosx") then
-        add_frameworks("CoreFoundation", "IOKit", "Security")
         add_extsources("brew::libusb")
-    elseif is_plat("bsd") then
-        add_syslinks("pthread")
     elseif is_plat("linux") then
-        add_deps("eudev")
-        add_syslinks("pthread")
         add_extsources("apt::libusb-dev", "pacman::libusb")
     elseif is_plat("mingw") and is_subhost("msys") then
         add_extsources("pacman::libusb")
     end
 
+    if is_plat("macosx") then
+        add_frameworks("CoreFoundation", "IOKit", "Security")
+    elseif is_plat("linux", "bsd") then
+        add_syslinks("pthread")
+    end
+
     add_deps("cmake")
+    if is_plat("linux", "cross") then
+        add_deps("eudev")
+    end
 
     add_includedirs("include", "include/libusb-1.0")
+    -- https://github.com/emscripten-core/emscripten/issues/13017
+    if is_plat("wasm") then
+        add_ldflags("--bind", "-s ASYNCIFY=1")
+    end
 
-    on_install("windows", "linux", "macosx", "bsd", "msys", "android", function (package)
+    on_install("!iphoneos", function (package)
         local dir = package:resourcefile("libusb-cmake")
         os.cp(path.join(dir, "CMakeLists.txt"), os.curdir())
         os.cp(path.join(dir, "config.h.in"), os.curdir())
@@ -37,11 +45,11 @@ package("libusb")
             [[get_filename_component(LIBUSB_ROOT "libusb" ABSOLUTE)]], {plain = true})
 
         local configs = {}
-        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
 
         local packagedeps = {}
-        if package:is_plat("linux") then
+        if package:is_plat("linux", "cross") then
             table.insert(packagedeps, "eudev")
         end
         import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps})