summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorBe <be@mixxx.org>2021-08-17 15:37:59 -0500
committerBe <be@mixxx.org>2021-08-17 15:37:59 -0500
commitffdf2a4046dd81608f370e47233a149fcd5194c4 (patch)
tree2b6de72b640cdfab07003e7dff8079151953bc2a /cmake
parent54a68c4130e65ba4f8d7f2ace9aa8eaa90c641bd (diff)
parentdb4b911a258c64c2c8ab59a555395922d767bb41 (diff)
Merge remote-tracking branch 'upstream/2.3'
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modules/Findhidapi.cmake42
1 files changed, 24 insertions, 18 deletions
diff --git a/cmake/modules/Findhidapi.cmake b/cmake/modules/Findhidapi.cmake
index b74a53fedc..14178a0e0d 100644
--- a/cmake/modules/Findhidapi.cmake
+++ b/cmake/modules/Findhidapi.cmake
@@ -71,29 +71,35 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
mark_as_advanced(hidapi-hidraw_LIBRARY)
endif()
+# Version detection
+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()
+ endif()
+endif()
+
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
hidapi
- DEFAULT_MSG
- hidapi_LIBRARY
- hidapi_INCLUDE_DIR
+ REQUIRED_VARS hidapi_LIBRARY hidapi_INCLUDE_DIR
+ VERSION_VAR hidapi_VERSION
)
-# 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}")