Skip to content

Commit

Permalink
CMake: rework findlibusb module
Browse files Browse the repository at this point in the history
Rename the module to FindLibUSB.cmake and use it as the only way
of finding libusb.

Bonus: perform CMake linting of the module.
  • Loading branch information
yegorich authored and thomasjfox committed Oct 10, 2023
1 parent 3dc444f commit 161caf3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
14 changes: 3 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,9 @@ if(${CMAKE_BUILD_TYPE} STREQUAL Debug)
add_definitions(-DDEBUG)
endif(${CMAKE_BUILD_TYPE} STREQUAL Debug)

# find libusb
find_package( PkgConfig )
if (PkgConfig_FOUND)
pkg_check_modules( LIBUSB libusb-1.0 )
if (LIBUSB_FOUND)
include_directories ( ${LIBUSB_INCLUDE_DIRS} )
else()
find_package ( USB1 REQUIRED )
include_directories ( ${LIBUSB_INCLUDE_DIR} )
endif()
endif()
# Find libusb
find_package ( LibUSB REQUIRED )
include_directories ( ${LIBUSB_INCLUDE_DIR} )

# Find Boost
if (FTDIPP OR BUILD_TESTS)
Expand Down
13 changes: 7 additions & 6 deletions cmake/FindUSB1.cmake → cmake/FindLibUSB.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# - Try to find the freetype library
# - Try to find the libusb library
# Once done this defines
#
# LIBUSB_FOUND - system has libusb
Expand All @@ -10,7 +10,6 @@
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.


if (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)

# in cache already
Expand All @@ -22,16 +21,18 @@ else (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
find_package(PkgConfig)
pkg_check_modules(PC_LIBUSB libusb-1.0)

FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h
find_path(LIBUSB_INCLUDE_DIR libusb.h
PATH_SUFFIXES libusb-1.0
PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS})

FIND_LIBRARY(LIBUSB_LIBRARIES NAMES usb-1.0
find_library(LIBUSB_LIBRARIES NAMES usb-1.0
PATHS ${PC_LIBUSB_LIBDIR} ${PC_LIBUSB_LIBRARY_DIRS})

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBUSB DEFAULT_MSG LIBUSB_LIBRARIES LIBUSB_INCLUDE_DIR)
find_package_handle_standard_args(
LibUSB DEFAULT_MSG LIBUSB_LIBRARIES LIBUSB_INCLUDE_DIR
)

MARK_AS_ADVANCED(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES)
mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES)

endif (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)

0 comments on commit 161caf3

Please sign in to comment.