pupil-labs / libuvc

a cross-platform library for USB video devices
https://int80k.com/libuvc/
Other
52 stars 30 forks source link

Can't compile on some non-Windows targets #26

Open steven807 opened 6 years ago

steven807 commented 6 years ago

A change to compile on Windows broke non-Windows builds (at least on my mac). This change isn't portable to Windows, so I'm not submitting it as a pull request, but I had to make the following changes to build on MacOS (High Sierra):

git diff CMakeLists.txt  | cat
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 762f2b6..e3fafe7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,11 +24,12 @@ if(WIN32)
   find_library(LIBUSB_LIBRARIES usb-1.0
   PATHS /opt/local/lib)

-  find_path(LIBUSB_INCLUDE_DIR libusb-1.0/libusb.h
+  find_path(LIBUSB_INCLUDEDIR libusb-1.0/libusb.h
   PATHS /opt/local/include)
 else()
   find_package(PkgConfig)
   pkg_check_modules(LIBUSB libusb-1.0)
+  find_library(LIBUSB usb-1.0)
 endif()

@@ -54,7 +55,7 @@ SET(SOURCES src/ctrl.c src/ctrl-gen.c src/device.c src/diag.c
 include_directories(
   ${libuvc_SOURCE_DIR}/include
   ${libuvc_BINARY_DIR}/include
-  ${LIBUSB_INCLUDE_DIR}
+  ${LIBUSB_INCLUDEDIR}
   ${PTHREAD_INCLUDE_DIR}
 )

@@ -92,7 +93,7 @@ foreach(target_name ${UVC_TARGETS})
 endforeach()

 if(BUILD_UVC_SHARED)
-  target_link_libraries(uvc ${LIBUSB_LIBRARIES} ${PTHREAD_LIBRARIES})
+  target_link_libraries(uvc ${LIBUSB} ${PTHREAD_LIBRARIES})

   #add_executable(test src/test.c)
   #target_link_libraries(test uvc ${LIBUSB_LIBRARIES} opencv_highgui
mcuee commented 6 years ago

The CMake file here works for Windows (tested with MS Visual C++ x86 build) but it does not seem to be very good for other system. I am not a CMake expert but maybe the following can be a reference. http://developer.intra2net.com/git/?p=libftdi;a=blob;f=cmake/FindUSB1.cmake

burknator commented 6 years ago

Thanks a ton @steven807, couldn't have fixed it without you! I'm on a mac too.

onc commented 6 years ago

Could reproduce the issue and fix it using the patch suggested by @steven807 on Mojave.

algrant commented 3 years ago

this still works on Catalina! thanks @steven807