From 9a06f20b08189f1828ba6cfe5bf1c64c367f47d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Tue, 17 Aug 2021 10:40:26 +0200 Subject: [PATCH 1/5] Findhidapi.cmake: Fix detection of Version 0 digits Co-authored-by: Be-ing --- cmake/modules/Findhidapi.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/modules/Findhidapi.cmake b/cmake/modules/Findhidapi.cmake index b4a7b282dd7..652608bffb9 100644 --- a/cmake/modules/Findhidapi.cmake +++ b/cmake/modules/Findhidapi.cmake @@ -80,7 +80,10 @@ if (EXISTS "${hidapi_INCLUDE_DIR}/hidapi.h") string(REGEX MATCH "#define HID_API_VERSION_PATCH ([0-9]+)" _dummy "${hidapi_H_CONTENTS}") set(hidapi_VERSION_PATCH "${CMAKE_MATCH_1}") # hidapi_VERSION is only available starting with 0.10.0 - if (hidapi_VERSION_MAJOR AND hidapi_VERSION_MINOR AND hidapi_VERSION_PATCH) + # Simply using if(NOT) does not work because 0 is a valid value, so compare to empty string. + if (NOT hidapi_VERSION_MAJOR STREQUAL "" AND + NOT hidapi_VERSION_MINOR STREQUAL "" AND + NOT hidapi_VERSION_PATCH STREQUAL "") set(hidapi_VERSION "${hidapi_VERSION_MAJOR}.${hidapi_VERSION_MINOR}.${hidapi_VERSION_PATCH}") endif() endif () From 4b0973cd838c7be183b69c64d5fd8bb0644dbba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 15 Aug 2021 11:49:57 +0200 Subject: [PATCH 2/5] Improve messages when linking hidapi --- CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 175e6ea8179..c0e1faf5102 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2608,7 +2608,14 @@ if(HID) find_package(hidapi) # hidapi_VERSION is only available starting with 0.10.0 if(NOT hidapi_FOUND OR NOT hidapi_VERSION OR hidapi_VERSION VERSION_LESS 0.10.1) - message(STATUS "Linking internal libhidapi statically") + if(hidapi_FOUND) + if(hidapi_VERSION) + message(STATUS "Found libhidapi version: ${hidapi_VERSION}") + else() + message(STATUS "Found libhidapi version < 0.10.0") + endif() + endif() + message(STATUS "Linking internal libhidapi 0.10.1 statically") add_library(mixxx-hidapi STATIC EXCLUDE_FROM_ALL) target_include_directories(mixxx-hidapi SYSTEM PUBLIC lib/hidapi/hidapi) if(WIN32) @@ -2630,7 +2637,6 @@ if(HID) endif() target_link_libraries(mixxx-lib PRIVATE mixxx-hidapi) else() - message(STATUS "Linking libhidapi dynamically") if(NOT HIDAPI_FOUND) message(FATAL_ERROR "USB HID controller support requires libhidapi-libusb and its development headers.") endif() From dc6978569a06aee3150d13a80b86f048aa7ccc28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Tue, 17 Aug 2021 12:03:13 +0200 Subject: [PATCH 3/5] Remove unreachable error message --- CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0e1faf5102..0c02a286838 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2637,9 +2637,6 @@ if(HID) endif() target_link_libraries(mixxx-lib PRIVATE mixxx-hidapi) else() - if(NOT HIDAPI_FOUND) - message(FATAL_ERROR "USB HID controller support requires libhidapi-libusb and its development headers.") - endif() target_link_libraries(mixxx-lib PRIVATE hidapi::hidapi) endif() target_sources(mixxx-lib PRIVATE From 826617fbe798ee31e25b6e501bb135ff52c3cd7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Tue, 17 Aug 2021 15:41:55 +0200 Subject: [PATCH 4/5] Introduced a MINIMUM_hidapi_VERSION variable to avoid repeat the version number literaly --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c02a286838..60cbdcf6260 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2607,15 +2607,16 @@ option(HID "USB HID controller support" ON) if(HID) find_package(hidapi) # hidapi_VERSION is only available starting with 0.10.0 - if(NOT hidapi_FOUND OR NOT hidapi_VERSION OR hidapi_VERSION VERSION_LESS 0.10.1) + set(MINIMUM_hidapi_VERSION "0.10.1") + if(NOT hidapi_FOUND OR NOT hidapi_VERSION OR hidapi_VERSION VERSION_LESS MINIMUM_hidapi_VERSION) if(hidapi_FOUND) if(hidapi_VERSION) message(STATUS "Found libhidapi version: ${hidapi_VERSION}") else() - message(STATUS "Found libhidapi version < 0.10.0") + message(STATUS "Found libhidapi version < ${MINIMUM_hidapi_VERSION}") endif() endif() - message(STATUS "Linking internal libhidapi 0.10.1 statically") + message(STATUS "Linking internal libhidapi ${MINIMUM_hidapi_VERSION} statically") add_library(mixxx-hidapi STATIC EXCLUDE_FROM_ALL) target_include_directories(mixxx-hidapi SYSTEM PUBLIC lib/hidapi/hidapi) if(WIN32) From a3e6da5547d6cc5a3802ac32c9b87ae4cd7dbd60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Tue, 17 Aug 2021 17:03:31 +0200 Subject: [PATCH 5/5] Make use of FindPackageHandleStandardArgs() to format user message --- CMakeLists.txt | 15 +++--------- cmake/modules/Findhidapi.cmake | 42 +++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 60cbdcf6260..7a5aa749a1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2605,18 +2605,9 @@ find_package(LibUSB) # USB HID controller support option(HID "USB HID controller support" ON) if(HID) - find_package(hidapi) - # hidapi_VERSION is only available starting with 0.10.0 - set(MINIMUM_hidapi_VERSION "0.10.1") - if(NOT hidapi_FOUND OR NOT hidapi_VERSION OR hidapi_VERSION VERSION_LESS MINIMUM_hidapi_VERSION) - if(hidapi_FOUND) - if(hidapi_VERSION) - message(STATUS "Found libhidapi version: ${hidapi_VERSION}") - else() - message(STATUS "Found libhidapi version < ${MINIMUM_hidapi_VERSION}") - endif() - endif() - message(STATUS "Linking internal libhidapi ${MINIMUM_hidapi_VERSION} statically") + find_package(hidapi 0.10.1) + if(NOT hidapi_FOUND) + message(STATUS "Linking internal libhidapi statically") add_library(mixxx-hidapi STATIC EXCLUDE_FROM_ALL) target_include_directories(mixxx-hidapi SYSTEM PUBLIC lib/hidapi/hidapi) if(WIN32) diff --git a/cmake/modules/Findhidapi.cmake b/cmake/modules/Findhidapi.cmake index 652608bffb9..a4e04c9204b 100644 --- a/cmake/modules/Findhidapi.cmake +++ b/cmake/modules/Findhidapi.cmake @@ -62,32 +62,36 @@ find_library(hidapi_LIBRARY ) mark_as_advanced(hidapi_LIBRARY) -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args( - hidapi - DEFAULT_MSG - hidapi_LIBRARY - hidapi_INCLUDE_DIR -) # Version detection -if (EXISTS "${hidapi_INCLUDE_DIR}/hidapi.h") - file(READ "${hidapi_INCLUDE_DIR}/hidapi.h" hidapi_H_CONTENTS) - string(REGEX MATCH "#define HID_API_VERSION_MAJOR ([0-9]+)" _dummy "${hidapi_H_CONTENTS}") - set(hidapi_VERSION_MAJOR "${CMAKE_MATCH_1}") - string(REGEX MATCH "#define HID_API_VERSION_MINOR ([0-9]+)" _dummy "${hidapi_H_CONTENTS}") - set(hidapi_VERSION_MINOR "${CMAKE_MATCH_1}") - string(REGEX MATCH "#define HID_API_VERSION_PATCH ([0-9]+)" _dummy "${hidapi_H_CONTENTS}") - set(hidapi_VERSION_PATCH "${CMAKE_MATCH_1}") - # hidapi_VERSION is only available starting with 0.10.0 - # Simply using if(NOT) does not work because 0 is a valid value, so compare to empty string. +if(DEFINED PC_hidapi_VERSION) + set(hidapi_VERSION "${PC_hidapi_VERSION}") +else() + if (EXISTS "${hidapi_INCLUDE_DIR}/hidapi.h") + file(READ "${hidapi_INCLUDE_DIR}/hidapi.h" hidapi_H_CONTENTS) + string(REGEX MATCH "#define HID_API_VERSION_MAJOR ([0-9]+)" _dummy "${hidapi_H_CONTENTS}") + set(hidapi_VERSION_MAJOR "${CMAKE_MATCH_1}") + string(REGEX MATCH "#define HID_API_VERSION_MINOR ([0-9]+)" _dummy "${hidapi_H_CONTENTS}") + set(hidapi_VERSION_MINOR "${CMAKE_MATCH_1}") + string(REGEX MATCH "#define HID_API_VERSION_PATCH ([0-9]+)" _dummy "${hidapi_H_CONTENTS}") + set(hidapi_VERSION_PATCH "${CMAKE_MATCH_1}") + # hidapi_VERSION is only available starting with 0.10.0 + # Simply using if(NOT) does not work because 0 is a valid value, so compare to empty string. if (NOT hidapi_VERSION_MAJOR STREQUAL "" AND NOT hidapi_VERSION_MINOR STREQUAL "" AND NOT hidapi_VERSION_PATCH STREQUAL "") - set(hidapi_VERSION "${hidapi_VERSION_MAJOR}.${hidapi_VERSION_MINOR}.${hidapi_VERSION_PATCH}") - endif() + set(hidapi_VERSION "${hidapi_VERSION_MAJOR}.${hidapi_VERSION_MINOR}.${hidapi_VERSION_PATCH}") + endif() + endif() endif () +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + hidapi + REQUIRED_VARS hidapi_LIBRARY hidapi_INCLUDE_DIR + VERSION_VAR hidapi_VERSION +) + if(hidapi_FOUND) set(hidapi_LIBRARIES "${hidapi_LIBRARY}") set(hidapi_INCLUDE_DIRS "${hidapi_INCLUDE_DIR}")