cmake: find libusb through LibUSB cmake module

This commit is contained in:
Anonymous Maarten
2023-11-29 21:47:05 +01:00
committed by Sam Lantinga
parent 2a775cad6f
commit 0e6fcf947a
2 changed files with 78 additions and 8 deletions

View File

@@ -1039,13 +1039,10 @@ macro(CheckHIDAPI)
set(HAVE_HIDAPI ON)
if(SDL_HIDAPI_LIBUSB)
set(HAVE_LIBUSB FALSE)
set(LibUSB_PKG_CONFIG_SPEC libusb-1.0>=1.0.16)
pkg_check_modules(PC_LIBUSB IMPORTED_TARGET ${LibUSB_PKG_CONFIG_SPEC})
if(PC_LIBUSB_FOUND)
find_package(LibUSB)
if(LibUSB_FOUND)
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_INCLUDES ${PC_LIBUSB_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES PkgConfig::PC_LIBUSB)
list(APPEND CMAKE_REQUIRED_LIBRARIES LibUSB::LibUSB)
check_c_source_compiles("
#include <stddef.h>
#include <libusb.h>
@@ -1060,9 +1057,9 @@ macro(CheckHIDAPI)
if(SDL_HIDAPI_LIBUSB_SHARED AND USB_1.0_LIB_SONAME)
set(HAVE_HIDAPI_LIBUSB_SHARED ON)
set(SDL_LIBUSB_DYNAMIC "\"${USB_1.0_LIB_SONAME}\"")
sdl_link_dependency(hidapi INCLUDES $<TARGET_PROPERTY:PkgConfig::PC_LIBUSB,INTERFACE_INCLUDE_DIRECTORIES>)
sdl_link_dependency(hidapi INCLUDES $<TARGET_PROPERTY:LibUSB::LibUSB,INTERFACE_INCLUDE_DIRECTORIES>)
else()
sdl_link_dependency(hidapi LIBS PkgConfig::PC_LIBUSB PKG_CONFIG_PREFIX PC_LIBUSB PKG_CONFIG_SPECS ${LibUSB_PKG_CONFIG_SPEC})
sdl_link_dependency(hidapi LIBS LibUSB::LibUSB PKG_CONFIG_SPECS "${LibUSB_PKG_CONFIG_SPEC}" CMAKE_MODULE LibUSB)
endif()
endif()
endif()