summaryrefslogtreecommitdiff
path: root/CMake/Modules/FindUsb.cmake
blob: 83b0e1546790a3e3510e30083e9636bdb6ca6f04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Findlibusb
# ==========
#
# Find the usb library
#
# This will define the following variables::
#
#  Usb_FOUND	- True if the system has the usb library
#  Usb_VERSION	- The verion of the usb library which was found
#
# and the following imported targets::
#
#  Usb::Usb	- The libusb library
#

include (LibFindMacros)

if (WIN32)
  # Use path suffixes on MS Windows as we probably shouldn't
  # trust the PATH envvar. PATH will still be searched to find the
  # library as last resort.
  if (CMAKE_SIZEOF_VOID_P MATCHES "8")
    set (_library_options PATH_SUFFIXES MinGW64/dll MinGW64/static)
  else ()
    set (_library_options PATH_SUFFIXES MinGW32/dll MinGW32/static)
  endif ()
endif ()
libfind_pkg_detect (Usb usb-1.0
  FIND_PATH libusb.h PATH_SUFFIXES include/libusb-1.0
  FIND_LIBRARY usb-1.0 ${_library_options}
  )

libfind_process (Usb)

if (Usb_FOUND AND NOT TARGET Usb::Usb)
  add_library (Usb::Usb UNKNOWN IMPORTED)
  set_target_properties (Usb::Usb PROPERTIES
    IMPORTED_LOCATION "${Usb_LIBRARY}"
    INTERFACE_COMPILE_OPTIONS "${Usb_PKGCONF_CFLAGS_OTHER}"
    INTERFACE_INCLUDE_DIRECTORIES "${Usb_INCLUDE_DIRS}"
    INTERFACE_LINK_LIBRARIES "${Usb_LIBRARIES}"
    )
endif ()

mark_as_advanced (
  Usb_INCLUDE_DIR
  Usb_LIBRARY
  Usb_LIBRARIES
  )