summaryrefslogtreecommitdiff
path: root/gnu/packages/patches/prusa-slicer-add-cmake-module.patch
blob: ba1be9f2af5fcb4e84f70c8766f78943f2ce29f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
From 23f1b40dbf6223b4b8af3845efe64b076998b2d7 Mon Sep 17 00:00:00 2001
From: nomike <nomike@nomike.com>
Date: Sat, 12 Jul 2025 03:14:16 +0200
Subject: [PATCH] Add CMake module for finding HidAPI library

---
 cmake/modules/FindHidAPI.cmake | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 cmake/modules/FindHidAPI.cmake

diff --git a/cmake/modules/FindHidAPI.cmake b/cmake/modules/FindHidAPI.cmake
new file mode 100644
index 000000000..0fdcecf88
--- /dev/null
+++ b/cmake/modules/FindHidAPI.cmake
@@ -0,0 +1,30 @@
+find_package(PkgConfig)
+pkg_search_module(PC_HIDAPI QUIET hidapi hidapi-libusb)
+
+find_path(HIDAPI_INCLUDE_DIR NAMES hidapi.h
+	HINTS
+	${PC_HIDAPI_INCLUDEDIR}
+	${PC_HIDAPI_INCLUDE_DIRS})
+
+find_library(HIDAPI_LIBRARY NAMES hidapi hidapi-libusb
+	HINTS
+	${PC_HIDAPI_LIBDIR}
+	${PC_HIDAPI_LIBRARY_DIRS})
+
+if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_INCLUDE_DIR}/hidapi.h")
+  file(STRINGS "${HIDAPI_INCLUDE_DIR}/hidapi.h" hidapi_version_major
+      REGEX "^#define[\t ]+HID_API_VERSION_MAJOR[\t ]+[0-9]+")
+  file(STRINGS "${HIDAPI_INCLUDE_DIR}/hidapi.h" hidapi_version_minor
+      REGEX "^#define[\t ]+HID_API_VERSION_MINOR[\t ]+[0-9]+")
+  file(STRINGS "${HIDAPI_INCLUDE_DIR}/hidapi.h" hidapi_version_patch
+      REGEX "^#define[\t ]+HID_API_VERSION_PATCH[\t ]+[0-9]+")
+  string(REGEX REPLACE "[^0-9.]" "" HIDAPI_VERSION_STRING "${hidapi_version_major}.${hidapi_version_minor}.${hidapi_version_patch}")
+  unset(hidapi_version_major)
+  unset(hidapi_version_minor)
+  unset(hidapi_version_patch)
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(HidAPI REQUIRED_VARS HIDAPI_LIBRARY HIDAPI_INCLUDE_DIR)
+
+mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_LIBRARY)
-- 
2.50.0