-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
CMake: fix detection of hidapi #4200
Conversation
I suppose we are not able to resolve this issue in 2.3 without touching the macOS and Windows environments. Our include paths are wrong. |
ea9ebb7
to
beda3b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This went smoother than expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the version detection in findhidapi.cmake requires an update to fix the issue.
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) | ||
find_package(hidapi 0.10.1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was wrong with this expression above?
Find_package(hidapi 0.10.1) succeeds on Ubuntu Bionic, because it is no version number set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof, why does CMake let this succeed...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this by adding hidapi_VERSION
to the find_package_handle_standard_args
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the error makes it clear what is happening:
-- Could NOT find hidapi (missing: hidapi_VERSION) (Required is at least version "0.10.1")
-- Linking internal libhidapi statically
Now it prints:
which is misleading. There is a |
I think it is good enough how it is. It prints the required version already. |
cmake/modules/Findhidapi.cmake
Outdated
# Version detection | ||
if (EXISTS "${hidapi_INCLUDE_DIR}/hidapi.h") | ||
file(READ "${hidapi_INCLUDE_DIR}/hidapi.h" hidapi_H_CONTENTS) | ||
if (EXISTS "${hidapi_INCLUDE_DIR}/hidapi/hidapi.h") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not sure if the header is in the /hidapi sub-directory.
Yes we are. This is easily verifiable by looking up the list of files installed by packages. Here is the libhidapi-dev package from Ubuntu 18.04:
https://packages.ubuntu.com/bionic/amd64/libhidapi-dev/filelist
It installs /usr/include/hidapi/hidapi.h.
I am not sure this code ever worked before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm that for Ubuntu Groovy. Maybe @uklotzde can explain why the code was written like that. Is it different with fedora?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is the same on Fedora:
❯ rpm -ql hidapi-devel
/usr/include/hidapi
/usr/include/hidapi/hidapi.h
/usr/lib64/libhidapi-hidraw.so
/usr/lib64/libhidapi-libusb.so
/usr/lib64/pkgconfig/hidapi-hidraw.pc
/usr/lib64/pkgconfig/hidapi-libusb.pc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same on Arch:
$ yay -Ql hidapi | grep -F hidapi.h
hidapi /usr/include/hidapi/hidapi.h
Why don't we just use PC_hidapi_VERSION? |
No, sorry. "Could NOT find hidapi" is wrong and misleading. |
I don't really care about perfect error messages for outdated operating systems. It still works and it gives a hint what is wrong:
|
@daschuer If you need better error messages for an issue that will disappear in the future and that probably affects only a minority of developers please take care of this later. |
What is the reason not to use "PC_hidapi_VERSION" that the error message would be reasonable by default. |
That requires rewriting more code to handle the case where there is no pkgconfig. |
We have it on all out targets. At least use the "PC_hidapi_VERSION" and fall back to reading the header file, with the code guessing the content of the pc file. |
@daschuer you can improve the error message for outdated operating systems if you want after merging this but I don't think there's any reason not to merge this now. I have a million other things to do. |
This can instantly merged, if you revert the changes in the CMakeList.txt, and making hidapi_VERSION not a requirement in findhidapi.cmake. The required bugfix is just to look into the hidapi sub folder, that's all and sufficient for the fix. |
I don't have energy for this bikeshedding. |
@daschuer Instead of starting a discussion it would have been more helpful to simply provide the changes you deem necessary. Then we could test if it still works for us. |
@uklotzde It is no problem for me to issue an alternative solution that makes use of the PC_hidapi_VERSION or just a simply fix of the header path. But for my understanding it is the normal way in a review to discuss things with the author. In this case l have discovered that he original PR was not working at all. Than I have clearly pointed out the later fix introduced an unecessary regression and suggested alternatives. It feels bad to being blamed for bikeshedding because of this. Since @Be-ing is stepped back from this let's discuss what would be a merge-able. Should I make use of PC_hidapi_VERSION or is it preferred to just fix the include path based on your original solution? |
@daschuer From what I understood the outcome is expected, i.e. the bundled/vendored version is used if the system version is too old and detection fails. The exact error message is a minor detail if it works. |
Why do we need to discuss this if the CI builds demonstrate that there are no actual regressions? This PR fixes the include paths and dynamic linking for all Linux distributions except Ubuntu LTS. What did I miss? |
Yes, but we have a solution in the 2.3 branch that has not the wrong error message. This solution was removed here along with the actual fix. I am happy to issue an alternative PR without this regression. I just need a conses before I start to work, because I have no interest to put work into a third solution. |
@@ -2605,12 +2605,12 @@ 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unrelated to the fix and can be reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not unrelated. find_package(hidapi 0.10.1)
creates the error message hinting the version is too old.
DEFAULT_MSG | ||
hidapi_LIBRARY | ||
hidapi_INCLUDE_DIR | ||
hidapi_VERSION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
Before: The code was silently broken Why do we need to pile up more work on top of it? Changing 1 or 2 lines would be ok, if it is as easy as claimed. But anything else could and should be done later. |
I was only asking for reverting a few lines, that's all. Let's move one and consider a solution .. After looking deeper into it I think the Findhidapi.cmake file is still broken. Do we know why using PATH_SUFFIXES was broken in the first place? It works on Linux. |
It was not broken, #4215 fixes all issues. |
/usr/include is correct. The file is at <hidapi/hidapi.h> relative to the installation prefix. |
Nope:
|
@Holzhaus yes that is what I mean. The #include paths in our C++ code were wrong. I fixed that in this PR. |
This is not what the hidapi README suggests: https://github.com/libusb/hidapi#what-does-the-api-look-like |
Well then the documentation is misleading. hidapi's build system has always installed the header to <hidapi/hidapi.h> relative to the installation prefix. |
Fix for the hidapi documentation: libusb/hidapi#323 |
I have already implemented a fully working solution. It does not create a welcoming environment to have every unimportant detail nitpicked to shreds then reimplemented in a worse way that does not solve all the problems, and makes the minuscule imperfections that were raised worse. |
The pkgconfig file says the #include path is /usr/include:
#include <hidapi/hidapi.h> is correct. |
Oh, wait the pkgconfig file is doing weird stuff:
That is normal.
That I did not expect. |
The example in
This is NOT how a consumer should include an external library. |
I think |
src/controllers/hid/hidcontroller.h
Outdated
@@ -1,6 +1,6 @@ | |||
#pragma once | |||
|
|||
#include <hidapi.h> | |||
#include <hidapi/hidapi.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not correct
as per HIDAPI design, you should only include <hidapi.h>
I reverted the change to the #include path. |
Mixxx was building its vendored copy of hidapi even when the system had hidapi 0.10.1.