kdelibs/cmake/modules/FindLibUSB.cmake
Ivailo Monev 3eb17fdf2b cmake: review modules rewritten so far by me
using pkg-config search as primary method with fallback to path lookup,
this may result in overlinking however if libraries require additional
include paths (as is the case with PulseAudio) with this change that will
not be a problem.

it will also reduce the lookups done during configuration/build since path
lookups will not be done, unless pkg-config lookup does not set the
required variables.

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
2020-02-10 20:52:45 +00:00

44 lines
1.1 KiB
CMake

# - Try to find libusb
#
# Once done this will define
#
# LIBUSB_FOUND - system has libusb
# LIBUSB_INCLUDES - the libusb include directory
# LIBUSB_LIBRARIES - The libraries needed to use libusb
#
# Copyright (c) 2016-2020, Ivailo Monev, <xakepa10@gmail.com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
if(LIBUSB_INCLUDES AND LIBUSB_LIBRARIES)
set(LIBUSB_FIND_QUIETLY TRUE)
endif()
if(NOT WIN32)
include(FindPkgConfig)
pkg_check_modules(PC_LIBUSB QUIET libusb-1.0)
set(LIBUSB_INCLUDES ${PC_LIBUSB_INCLUDE_DIRS})
set(LIBUSB_LIBRARIES ${PC_LIBUSB_LIBRARIES})
endif()
if(NOT LIBUSB_INCLUDES OR NOT LIBUSB_LIBRARIES)
find_path(LIBUSB_INCLUDES
NAMES libusb.h
PATH_SUFFIXES libusb-1.0
HINTS $ENV{LIBUSBDIR}/include
)
find_library(LIBUSB_LIBRARIES
NAMES usb-1.0
HINTS $ENV{LIBUSBDIR}/lib
)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibUSB
VERSION_VAR PC_LIBUSB_VERSION
REQUIRED_VARS LIBUSB_LIBRARIES LIBUSB_INCLUDES
)
mark_as_advanced(LIBUSB_INCLUDES LIBUSB_LIBRARIES)