summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Klotz <uklotz@mixxx.org>2021-03-19 18:26:00 +0100
committerUwe Klotz <uklotz@mixxx.org>2021-03-19 18:26:00 +0100
commit7d52868c6c6fba51e5fca01c92a97ea0f00b3a1c (patch)
treeaa2fe62805387adfe9a37c875624edac0d9c950d
parent7866dea6e4ad38392040ea37739feba4ae8cceae (diff)
CMake: Fix detection of hidapi_VERSION
-rw-r--r--CMakeLists.txt3
-rw-r--r--cmake/modules/Findhidapi.cmake15
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}")