libftdi Archives

Subject: [PATCH v2 3/6] CMake: rework findlibusb module

From: yegorslists@xxxxxxxxxxxxxx
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Cc: thomas.jarosch@xxxxxxxxxxxxx, Yegor Yefremov <yegorslists@xxxxxxxxxxxxxx>
Date: Mon, 11 Sep 2023 10:04:01 +0200
From: Yegor Yefremov <yegorslists@xxxxxxxxxxxxxx>

Rename the module to FindLibUSB.cmake and use it as the only way
of finding libusb.

Bonus: perform CMake linting of the module.
---
 CMakeLists.txt                             | 14 +++-----------
 cmake/{FindUSB1.cmake => FindLibUSB.cmake} | 13 +++++++------
 2 files changed, 10 insertions(+), 17 deletions(-)
 rename cmake/{FindUSB1.cmake => FindLibUSB.cmake} (77%)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 39857a2..947fb34 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
diff --git a/cmake/FindUSB1.cmake b/cmake/FindLibUSB.cmake
similarity index 77%
rename from cmake/FindUSB1.cmake
rename to cmake/FindLibUSB.cmake
index b90e297..766fc82 100644
--- a/cmake/FindUSB1.cmake
+++ b/cmake/FindLibUSB.cmake
@@ -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
@@ -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
@@ -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)
-- 
2.34.1


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread