浏览代码

libuvc: add Linux/MacOS X platforms (#7551)

* libuvc: add plat

* fix

* add frameworks for macosx

* fix libusb

* remove bsd

* try to use openBSD implementation for freeBSD

* try to use netBSD implementation for freeBSD

* libusb: limit bsd

---------

Co-authored-by: Saikari <[email protected]>
choyy 2 月之前
父节点
当前提交
591fd57df1

+ 7 - 4
packages/l/libusb/xmake.lua

@@ -38,7 +38,7 @@ package("libusb")
         add_ldflags("--bind", "-s ASYNCIFY=1")
         add_ldflags("--bind", "-s ASYNCIFY=1")
     end
     end
 
 
-    on_install("!iphoneos", function (package)
+    on_install("!iphoneos and !bsd", function (package)
         local dir = package:resourcefile("libusb-cmake")
         local dir = package:resourcefile("libusb-cmake")
         os.cp(path.join(dir, "CMakeLists.txt"), os.curdir())
         os.cp(path.join(dir, "CMakeLists.txt"), os.curdir())
         os.cp(path.join(dir, "config.h.in"), os.curdir())
         os.cp(path.join(dir, "config.h.in"), os.curdir())
@@ -50,11 +50,14 @@ package("libusb")
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_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"))
         table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
 
 
-        local packagedeps = {}
+        local opt = {}
         if package:is_plat("linux", "cross") then
         if package:is_plat("linux", "cross") then
-            table.insert(packagedeps, "eudev")
+            opt.packagedeps = {"eudev"}
         end
         end
-        import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps})
+        if package:config("shared") and package:is_plat("macosx") then
+            opt.shflags = {"-framework", "CoreFoundation", "-framework", "IOKit", "-framework", "Security"}
+        end
+        import("package.tools.cmake").install(package, configs, opt)
     end)
     end)
 
 
     on_test(function (package)
     on_test(function (package)

+ 58 - 0
packages/l/libuvc/patches/2024.03.05/linux.patch

@@ -0,0 +1,58 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index fbaffc9..56fc32d 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -39,11 +39,12 @@ set(SOURCES
+   src/misc.c
+ )
+ 
+-find_package(LibUSB)
++find_package(PkgConfig REQUIRED)
++pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb)
+ 
+ # JpegPkg name to differ from shipped with CMake
+-find_package(JpegPkg QUIET)
+-if(JPEG_FOUND)
++pkg_check_modules(libjpeg REQUIRED IMPORTED_TARGET libjpeg)
++if(libjpeg_FOUND)
+   message(STATUS "Building libuvc with JPEG support.")
+   set(LIBUVC_HAS_JPEG TRUE)
+   list(APPEND SOURCES src/frame-mjpeg.c)
+@@ -116,11 +117,12 @@ foreach(target_name IN LISTS UVC_TARGETS)
+   )
+   target_link_libraries(${target_name}
+     # libusb-1.0 used internally so we link to it privately.
+-    PRIVATE LibUSB::LibUSB ${threads}
++    PRIVATE ${threads}
++    PRIVATE PkgConfig::libusb
+   )
+-  if(JPEG_FOUND)
++  if(libjpeg_FOUND)
+     target_link_libraries(${target_name}
+-      PRIVATE JPEG::JPEG
++      PRIVATE PkgConfig::libjpeg
+     )
+   endif()
+   set_target_properties(${target_name} PROPERTIES
+@@ -191,12 +193,6 @@ install(EXPORT libuvcTargets
+   DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
+ )
+ 
+-install(FILES 
+-    cmake/FindLibUSB.cmake
+-    cmake/FindJpegPkg.cmake
+-  DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
+-)
+-
+ include(CMakePackageConfigHelpers)
+ write_basic_package_version_file(libuvcConfigVersion.cmake
+   COMPATIBILITY AnyNewerVersion
+@@ -207,7 +203,7 @@ install(FILES
+   DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
+ )
+ 
+-if(JPEG_FOUND)
++if(libjpeg_FOUND)
+   # If we have used JPEG library we need to 
+   # add linker flag for it in config file for pkgconfig
+   set(PKGCONFIG_JPEG_LDFLAG "-ljpeg")

+ 1 - 1
packages/l/libuvc/patches/2024.03.05/windows.patch

@@ -75,7 +75,7 @@ index d387150..6ed6d50 100644
  #include <stdint.h>
  #include <stdint.h>
 -#include <sys/time.h>
 -#include <sys/time.h>
 +#include <time.h>
 +#include <time.h>
-+#include <winsock.h>
++#include <winsock2.h>
  #include <libuvc/libuvc_config.h>
  #include <libuvc/libuvc_config.h>
  
  
  struct libusb_context;
  struct libusb_context;

+ 22 - 4
packages/l/libuvc/xmake.lua

@@ -6,14 +6,29 @@ package("libuvc")
     add_urls("https://github.com/libuvc/libuvc.git")
     add_urls("https://github.com/libuvc/libuvc.git")
     add_versions("2024.03.05", "047920bcdfb1dac42424c90de5cc77dfc9fba04d")
     add_versions("2024.03.05", "047920bcdfb1dac42424c90de5cc77dfc9fba04d")
 
 
+    if is_plat("macosx") then
+        add_extsources("brew::libuvc")
+    elseif is_plat("linux") then
+        add_extsources("apt::libuvc-dev", "pacman::libuvc")
+    elseif is_plat("mingw") and is_subhost("msys") then
+        add_extsources("pacman::libuvc")
+    end
+
     add_configs("jpeg", {description = "Enable jpeg support.", default = true, type = "boolean"})
     add_configs("jpeg", {description = "Enable jpeg support.", default = true, type = "boolean"})
+    add_configs("winsock2", {description = "Use winsock2.h or winsock.h in windows.", default = true, type = "boolean"})
 
 
-    add_deps("cmake")
+    add_deps("cmake", "pkgconf")
     add_deps("libusb")
     add_deps("libusb")
 
 
     if is_plat("windows") then
     if is_plat("windows") then
-        add_patches("2024.03.05", "patches/2024.03.05/windows.patch", "87eae0b3bbc07038654a5ef7f5f7d0213472436e517f9b65963353738bb0a3dc")
-        add_deps("pkgconf", "pthreads4w")
+        add_patches("2024.03.05", "patches/2024.03.05/windows.patch", "1a3356ad2a37ac68bd29ea61457de85210740643843f57e030b20fd70efc9597")
+        add_deps("pthreads4w")
+    else
+        add_patches("2024.03.05", "patches/2024.03.05/linux.patch", "6a17c1eb271a6db1a2fd17aa2003159f60b85f02a3443ee5b600472f94786bda")
+    end
+
+    if is_plat("macosx") then
+        add_frameworks("CoreFoundation", "IOKit", "Security")
     end
     end
 
 
     on_load(function (package)
     on_load(function (package)
@@ -22,7 +37,10 @@ package("libuvc")
         end
         end
     end)
     end)
 
 
-    on_install("windows|x64", "windows|x86", function (package)
+    on_install("windows|x64", "windows|x86", "linux", "macosx", function (package)
+        if package:is_plat("windows") and not package:config("winsock2") then
+            io.replace("include/libuvc/libuvc.h", "winsock2.h", "winsock.h", {plain = true})
+        end
         local configs = {}
         local configs = {}
         table.insert(configs, "-DBUILD_EXAMPLE=OFF")
         table.insert(configs, "-DBUILD_EXAMPLE=OFF")
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
         table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))