-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
CMake: fix detection of hidapi #4200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2605,9 +2605,8 @@ find_package(LibUSB) | |
| # USB HID controller support | ||
| option(HID "USB HID controller support" ON) | ||
| if(HID) | ||
| find_package(hidapi) | ||
| # hidapi_VERSION is only available starting with 0.10.0 | ||
| if(NOT hidapi_FOUND OR NOT hidapi_VERSION OR hidapi_VERSION VERSION_LESS 0.10.1) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is unrelated to the fix and can be reverted.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not unrelated. |
||
| find_package(hidapi 0.10.1) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was wrong with this expression above?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oof, why does CMake let this succeed...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed this by adding
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the error makes it clear what is happening: |
||
| 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) | ||
|
Be-ing marked this conversation as resolved.
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,14 +62,6 @@ 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) | ||
|
|
@@ -80,10 +72,22 @@ if (EXISTS "${hidapi_INCLUDE_DIR}/hidapi.h") | |
| 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) | ||
| # 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 | ||
| hidapi_VERSION | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the hidapi_VERSION version required to "find" the package which is an issue because the code above does not work for versions < 0.10.0. We can make it work by using the version from the PC file or just stick with the original solution.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please give a hint what you prefer and I will prepare a PR.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intentional. We require 0.10.1, so if there is no hidapi_VERSION it is too old anyway. |
||
| ) | ||
|
|
||
| if(hidapi_FOUND) | ||
| set(hidapi_LIBRARIES "${hidapi_LIBRARY}") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.