From 2af7e40ce698eab25ac44cd492e7546e1010f16a Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Tue, 7 Jul 2020 10:13:15 +0000 Subject: cmake: unbreak system libusb support Reference libusb doesn't support DragonFly and FreeBSD because those ship a different libusb implementation (supports 0.1, 1.0, 2.0 API). ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(usbi_alloc_device) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(usbi_alloc_device) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(libusb_has_capability) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(libusb_has_capability) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(libusb_has_capability) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(usbi_connect_device) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(usbi_disconnect_device) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(libusb_get_device_list) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(libusb_get_device_list) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(libusb_unref_device) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(libusb_unref_device) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_write >>> referenced by core.c >>> core.c.o:(usbi_signal_event) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_read >>> referenced by core.c >>> core.c.o:(usbi_clear_event) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(libusb_wrap_sys_device) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(libusb_wrap_sys_device) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(libusb_wrap_sys_device) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(libusb_open) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_backend >>> referenced by core.c >>> core.c.o:(libusb_open) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_read >>> referenced by core.c >>> core.c.o:(libusb_close) in archive externals/libusb/libusb.a ld: error: undefined symbol: usbi_write >>> referenced by core.c >>> core.c.o:(libusb_close) in archive externals/libusb/libusb.a ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors) c++: error: linker command failed with exit code 1 (use -v to see invocation) --- CMakeLists.txt | 6 +++-- externals/find-modules/FindLibUSB.cmake | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 externals/find-modules/FindLibUSB.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 27383bce8..cd40e5cfe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -331,8 +331,10 @@ endif() # Ensure libusb is properly configured (based on dolphin libusb include) find_package(LibUSB) -add_subdirectory(externals/libusb) -set(LIBUSB_LIBRARIES usb) +if (NOT LIBUSB_FOUND) + add_subdirectory(externals/libusb) + set(LIBUSB_LIBRARIES usb) +endif() # Prefer the -pthread flag on Linux. diff --git a/externals/find-modules/FindLibUSB.cmake b/externals/find-modules/FindLibUSB.cmake new file mode 100644 index 000000000..dec0b98b0 --- /dev/null +++ b/externals/find-modules/FindLibUSB.cmake @@ -0,0 +1,43 @@ +# - Find libusb-1.0 library +# This module defines +# LIBUSB_INCLUDE_DIR, where to find bluetooth.h +# LIBUSB_LIBRARIES, the libraries needed to use libusb-1.0. +# LIBUSB_FOUND, If false, do not try to use libusb-1.0. +# +# Copyright (c) 2009, Michal Cihar, +# +# vim: expandtab sw=4 ts=4 sts=4: + +if(ANDROID) + set(LIBUSB_FOUND FALSE CACHE INTERNAL "libusb-1.0 found") + message(STATUS "libusb-1.0 not found.") +elseif (NOT LIBUSB_FOUND) + pkg_check_modules (LIBUSB_PKG libusb-1.0) + + find_path(LIBUSB_INCLUDE_DIR NAMES libusb.h + PATHS + ${LIBUSB_PKG_INCLUDE_DIRS} + /usr/include/libusb-1.0 + /usr/include + /usr/local/include/libusb-1.0 + /usr/local/include + ) + + find_library(LIBUSB_LIBRARIES NAMES usb-1.0 usb + PATHS + ${LIBUSB_PKG_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + ) + + if(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) + set(LIBUSB_FOUND TRUE CACHE INTERNAL "libusb-1.0 found") + message(STATUS "Found libusb-1.0: ${LIBUSB_INCLUDE_DIR}, ${LIBUSB_LIBRARIES}") + else(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) + set(LIBUSB_FOUND FALSE CACHE INTERNAL "libusb-1.0 found") + message(STATUS "libusb-1.0 not found.") + endif(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) + + mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES) +endif () + -- cgit v1.2.3