From 09eb8c43d405e7965b50582be7e0e714790a5de8 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] Make use of FindPackageHandleStandardArgs() to format user message --- CMakeLists.txt | 13 +++-------- cmake/modules/Findhidapi.cmake | 42 +++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 60cbdcf6260..3068770ac8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2605,18 +2605,11 @@ find_package(LibUSB) # USB HID controller support option(HID "USB HID controller support" ON) if(HID) - find_package(hidapi) + find_package(hidapi 0.10.1) # 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") + 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}")