diff options
author | Jan Holthuis <jan.holthuis@ruhr-uni-bochum.de> | 2021-03-19 19:45:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-19 19:45:00 +0100 |
commit | f7ac64dac483bab03cdb131888f58d75588e79ad (patch) | |
tree | d7ad89c3ad016f3aa4a75629c96b090c32382d33 | |
parent | 31953aa8ef4372ff77666bd267200dcf83f0ea11 (diff) | |
parent | 7d52868c6c6fba51e5fca01c92a97ea0f00b3a1c (diff) |
Merge pull request #3730 from uklotzde/cmake-hidapi-version
CMake: Fix detection of hidapi_VERSION
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | cmake/modules/Findhidapi.cmake | 15 |
2 files changed, 17 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dc762d5d0..be67c340d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2536,7 +2536,8 @@ find_package(LibUSB) # USB HID controller support find_package(hidapi) option(HID "USB HID controller support" ON) -default_option(HIDAPI_STATIC "Link HIDAPI library statically" "NOT HIDAPI_FOUND") +# hidapi_VERSION is only available starting with 0.10.0 +default_option(HIDAPI_STATIC "Link HIDAPI library statically" "NOT hidapi_FOUND OR NOT hidapi_VERSION OR hidapi_VERSION VERSION_LESS 0.10.0") if(HID) target_sources(mixxx-lib PRIVATE src/controllers/hid/hidcontroller.cpp diff --git a/cmake/modules/Findhidapi.cmake b/cmake/modules/Findhidapi.cmake index 8984767583..b4a7b282dd 100644 --- a/cmake/modules/Findhidapi.cmake +++ b/cmake/modules/Findhidapi.cmake @@ -70,6 +70,21 @@ find_package_handle_standard_args( 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 + if (hidapi_VERSION_MAJOR AND hidapi_VERSION_MINOR AND hidapi_VERSION_PATCH) + set(hidapi_VERSION "${hidapi_VERSION_MAJOR}.${hidapi_VERSION_MINOR}.${hidapi_VERSION_PATCH}") + endif() +endif () + if(hidapi_FOUND) set(hidapi_LIBRARIES "${hidapi_LIBRARY}") set(hidapi_INCLUDE_DIRS "${hidapi_INCLUDE_DIR}") |