From 1e83d2a4e9a70edffd392c1dd3e5808f553d62ab Mon Sep 17 00:00:00 2001 From: Bevan Weiss Date: Tue, 13 Oct 2020 23:13:08 +1100 Subject: [PATCH] LibUSB: Update to upstream master (and turn off YAML_CPP_INSTALL CMake property) May resolve some outstanding issues around libusb/hidapi (i.e. DS4 not being released on rpcs3 shutdown etc..) or may not. Fixes three outstanding compile warnings on non-Windows OS... introduces a few more warnings in WindowsOS (issue raised upstream with libusb around WINAPI_CHECK macro) Re-ordered the 3rd party CMake so libusb is in file order above hidapi (just to have document flow match logical flow) Also took this opportunity to remove the YAML INSTALL action (by setting YAML_CPP_INSTALL to OFF) Provided capability to use system library for libusb by providing USE_SYS_LIBUSB option to CMAKE Tested under: - [X] Windows 10 2004 OS with DS4 controller - [X] Windows 10 2004 OS with GCon3 controller - [X] Linux (Mint 20) with DS4 controller --- 3rdparty/CMakeLists.txt | 51 ++++++++++++++++++++++++---------- 3rdparty/libusb | 2 +- 3rdparty/libusb_cmake/os.cmake | 11 +++++--- 3rdparty/libusb_static.vcxproj | 10 +++---- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 53117c0cd1..e22ff16471 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -106,6 +106,36 @@ endif() add_subdirectory(pugixml EXCLUDE_FROM_ALL) +# libusb +if(CMAKE_SYSTEM MATCHES "DragonFly|FreeBSD") + pkg_check_modules(LIBUSB REQUIRED IMPORTED_TARGET libusb-1.0>=1.0 ) + CMAKE_DEPENDENT_OPTION( USE_SYS_LIBUSB "Use system libusb-1.0 as shared library" ON + "LIBUSB_FOUND" OFF) +else() + pkg_check_modules(LIBUSB IMPORTED_TARGET libusb-1.0>=1.0 ) + CMAKE_DEPENDENT_OPTION( USE_SYS_LIBUSB "Use system libusb-1.0 as shared library" OFF + "LIBUSB_FOUND" OFF) +endif() +if(CMAKE_SYSTEM MATCHES "DragonFly|FreeBSD") + # Always use system libusb as reference implementation isn't supported + add_library(usb-1.0-shared INTERFACE) + target_link_libraries(usb-1.0-shared INTERFACE PkgConfig::LIBUSB) +elseif(MSVC) + # Windows time.h defines timespec but doesn't add any flag for it, which makes libusb attempt to define it again + add_definitions(-DHAVE_STRUCT_TIMESPEC=1) + add_subdirectory(libusb_cmake EXCLUDE_FROM_ALL) +else() + if(USE_SYS_LIBUSB) + # we have the system libusb and have selected to use it + add_library(usb-1.0-shared INTERFACE) + target_link_libraries(usb-1.0-shared INTERFACE PkgConfig::LIBUSB) + else() + # we don't have the system libusb, so we compile from submodule + add_subdirectory(libusb_cmake EXCLUDE_FROM_ALL) + endif() +endif() + + # hidapi add_library(3rdparty_hidapi INTERFACE) target_include_directories(3rdparty_hidapi INTERFACE hidapi/hidapi) @@ -133,24 +163,11 @@ else() endif() -# libusb -if(CMAKE_SYSTEM MATCHES "DragonFly|FreeBSD") - # Always use system libusb as reference implementation isn't supported - add_library(usb-1.0-static INTERFACE) - target_link_libraries(usb-1.0-static INTERFACE usb) -elseif(MSVC) - # Windows time.h defines timespec but doesn't add any flag for it, which makes libusb attempt to define it again - add_definitions(-DHAVE_STRUCT_TIMESPEC=1) - add_subdirectory(libusb_cmake EXCLUDE_FROM_ALL) -else() - add_subdirectory(libusb_cmake EXCLUDE_FROM_ALL) -endif() - - # yaml-cpp # We don't want to install yaml-cpp but its cmake file doesn't have option # to disable it... # So we just install it to a different directory +set(YAML_CPP_INSTALL OFF CACHE BOOL "Don't install YAML") set(CMAKE_INSTALL_PREFIX_OLD ${CMAKE_INSTALL_PREFIX}) set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/yaml-cpp_install) @@ -460,7 +477,11 @@ else() endif() # add nice ALIAS targets for ease of use -add_library(3rdparty::libusb ALIAS usb-1.0-static) +if(USE_SYS_LIBUSB) + add_library(3rdparty::libusb ALIAS usb-1.0-shared) +else() + add_library(3rdparty::libusb ALIAS usb-1.0-static) +endif() add_library(3rdparty::zlib ALIAS 3rdparty_zlib) add_library(3rdparty::7z ALIAS 3rdparty_7z) add_library(3rdparty::flatbuffers ALIAS 3rdparty_flatbuffers) diff --git a/3rdparty/libusb b/3rdparty/libusb index e782eeb251..eee6998395 160000 --- a/3rdparty/libusb +++ b/3rdparty/libusb @@ -1 +1 @@ -Subproject commit e782eeb2514266f6738e242cdcb18e3ae1ed06fa +Subproject commit eee6998395184d87bd8e9c07ce2637caed1207f4 diff --git a/3rdparty/libusb_cmake/os.cmake b/3rdparty/libusb_cmake/os.cmake index 83f36e346e..cde292bc0a 100644 --- a/3rdparty/libusb_cmake/os.cmake +++ b/3rdparty/libusb_cmake/os.cmake @@ -6,6 +6,7 @@ if (CMAKE_USE_PTHREADS_INIT) endif() if (WIN32 OR "${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN") + add_compile_definitions(PLATFORM_WINDOWS=1) set(OS_WINDOWS 1 CACHE INTERNAL "controls config.h macro definition" FORCE) # Enable MingW support for RC language (for CMake pre-2.8) @@ -22,9 +23,9 @@ if (WIN32 OR "${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN") endif() list(APPEND PLATFORM_SRC - poll_windows.c + events_windows.c windows_usbdk.c - windows_nt_common.c + windows_common.c windows_winusb.c threads_windows.c ) @@ -36,13 +37,14 @@ if (WIN32 OR "${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN") endif() elseif (APPLE) # Apple != OSX alone + add_compile_definitions(PLATFORM_POSIX=1 HAVE_CLOCK_GETTIME) set(OS_DARWIN 1 CACHE INTERNAL "controls config.h macro definition" FORCE) if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") set(PLATFORM_SRC darwin_usb.c threads_posix.c - poll_posix.c + events_posix.c ) find_package(IOKit REQUIRED) @@ -72,6 +74,7 @@ int main() endif() elseif (UNIX) # Unix is for all *NIX systems including OSX + add_compile_definitions(PLATFORM_POSIX=1 HAVE_CLOCK_GETTIME) if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") set(OS_LINUX 1 CACHE INTERNAL "controls config.h macro definition" FORCE) @@ -79,7 +82,7 @@ elseif (UNIX) linux_usbfs.c linux_netlink.c threads_posix.c - poll_posix.c + events_posix.c ) list(APPEND LIBUSB_LIBRARIES rt) diff --git a/3rdparty/libusb_static.vcxproj b/3rdparty/libusb_static.vcxproj index 6f49b8f6bd..eb95e46772 100644 --- a/3rdparty/libusb_static.vcxproj +++ b/3rdparty/libusb_static.vcxproj @@ -43,7 +43,7 @@ /utf-8 %(AdditionalOptions) libusb\msvc;libusb\libusb;%(AdditionalIncludeDirectories) - WINVER=0x0501;_WIN32_WINNT=0x0501;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + WINVER=0x0600;_WIN32_WINNT=0x0600;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) $(IntDir)$(TargetName).pdb Level4 @@ -65,11 +65,11 @@ - + - + @@ -78,13 +78,11 @@ - + - -