From d210d2c67e0aceb38979c96ba888981a0a426d43 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Tue, 17 Mar 2020 07:25:26 +0100 Subject: [PATCH] use libusb_attach_kernel_driver only when OS is Linux --- CMakeLists.txt | 6 ++++++ src/ftdipp_mpsse.cpp | 3 +++ 2 files changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 74addf6..b5457dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,12 @@ target_link_libraries(openFPGALoader ${LIBUSB_LIBRARIES} ${LIBFTDI_LIBRARIES} ) + +# libusb_attach_kernel_driver is only available on Linux. +if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + add_definitions(-DATTACH_KERNEL) +endif() + if(ENABLE_UDEV) include_directories(${LIBUDEV_INCLUDE_DIRS}) target_link_libraries(openFPGALoader ${LIBUDEV_LIBRARIES}) diff --git a/src/ftdipp_mpsse.cpp b/src/ftdipp_mpsse.cpp index c157826..4de2277 100644 --- a/src/ftdipp_mpsse.cpp +++ b/src/ftdipp_mpsse.cpp @@ -131,11 +131,14 @@ int FTDIpp_MPSSE::close_device() fprintf(stderr, "release interface failed %d\n", rtn); return EXIT_FAILURE; } +#ifdef ATTACH_KERNEL + /* libusb_attach_kernel_driver is only available on Linux. */ if (_ftdi->module_detach_mode == AUTO_DETACH_SIO_MODULE) { rtn = libusb_attach_kernel_driver(_ftdi->usb_dev, _ftdi->interface); if( rtn != 0) fprintf(stderr, "detach error %d\n", rtn); } +#endif } ftdi_usb_close_internal();