diff options
Diffstat (limited to 'cmake/modules/FindLibUSB.cmake')
| -rw-r--r-- | cmake/modules/FindLibUSB.cmake | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/cmake/modules/FindLibUSB.cmake b/cmake/modules/FindLibUSB.cmake new file mode 100644 index 0000000..e976bf4 --- /dev/null +++ b/cmake/modules/FindLibUSB.cmake | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | #.rst: | ||
| 2 | # FindLibUSB | ||
| 3 | # ---------- | ||
| 4 | # Finds the USB library | ||
| 5 | # | ||
| 6 | # This will will define the following variables:: | ||
| 7 | # | ||
| 8 | # LIBUSB_FOUND - system has LibUSB | ||
| 9 | # LIBUSB_INCLUDE_DIRS - the USB include directory | ||
| 10 | # LIBUSB_LIBRARIES - the USB libraries | ||
| 11 | # | ||
| 12 | # and the following imported targets:: | ||
| 13 | # | ||
| 14 | # LibUSB::LibUSB - The USB library | ||
| 15 | |||
| 16 | if(PKG_CONFIG_FOUND) | ||
| 17 | pkg_check_modules(PC_LIBUSB libusb QUIET) | ||
| 18 | endif() | ||
| 19 | |||
| 20 | find_path(LIBUSB_INCLUDE_DIR usb.h | ||
| 21 | PATHS ${PC_LIBUSB_INCLUDEDIR}) | ||
| 22 | find_library(LIBUSB_LIBRARY NAMES usb | ||
| 23 | PATHS ${PC_LIBUSB_INCLUDEDIR}) | ||
| 24 | set(LIBUSB_VERSION ${PC_LIBUSB_VERSION}) | ||
| 25 | |||
| 26 | include(FindPackageHandleStandardArgs) | ||
| 27 | find_package_handle_standard_args(LIBUSB | ||
| 28 | REQUIRED_VARS LIBUSB_LIBRARY LIBUSB_INCLUDE_DIR | ||
| 29 | VERSION_VAR LIBUSB_VERSION) | ||
| 30 | |||
| 31 | if(LIBUSB_FOUND) | ||
| 32 | set(LIBUSB_INCLUDE_DIRS ${LIBUSB_INCLUDE_DIR}) | ||
| 33 | set(LIBUSB_LIBRARIES ${LIBUSB_LIBRARY}) | ||
| 34 | set(LIBUSB_DEFINITIONS -DUSE_LIBUSB=1) | ||
| 35 | |||
| 36 | if(NOT TARGET LibUSB::LibUSB) | ||
| 37 | add_library(LibUSB::LibUSB UNKNOWN IMPORTED) | ||
| 38 | set_target_properties(LibUSB::LibUSB PROPERTIES | ||
| 39 | IMPORTED_LOCATION "${LIBUSB_LIBRARY}" | ||
| 40 | INTERFACE_INCLUDE_DIRECTORIES "${LIBUSB_INCLUDE_DIR}" | ||
| 41 | INTERFACE_COMPILE_DEFINITIONS USE_LIBUSB=1) | ||
| 42 | endif() | ||
| 43 | endif() | ||
| 44 | |||
| 45 | mark_as_advanced(USB_INCLUDE_DIR USB_LIBRARY) | ||
