-
Notifications
You must be signed in to change notification settings - Fork 410
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 build system #12
Comments
I'd rather use Meson as a build system than CMake |
I would suggest that any new build system not prevent the use of simple Makefiles for the many small *nixes out there that don't have access to Python or Internet access. |
I wouldn't suggest replacing build system. Not now.
Never used it. But quick reading over its readme/some docs, and it seems there is no much benefit in using Meson over CMake. |
Meson actually generates files for the ninja build system 😉 In my opinion, Meson has a much better syntax than CMake and many useful features included (such as the pkg-config file generation, painless cross-compilation, etc) There's also https://mesonbuild.com/Comparisons.html I think it would be best to have manual Makefiles for those |
I'd add it to
What would be a benefit of that effort? Also, as I pointed since the beginning - on of the main benefit with CMake is to have a single build system, instead of MSVC-version specific copy-paste, XCode support appears automatically too, etc. Mason with ninja only support - wouldn't make any difference here.
Already done by current build system.
Trivially with CMake. |
Sure, we can argue back and forth between Meson and CMake and nothing would change 😉 I'm for Meson, you're for CMake. Maybe others can chime in their thoughts :)
From my point of view autotools is pretty complicated (and I have little experience with it) and manual Makefiles wouldn't be any longer than the autotools-equivalents probably. And as, per platform, it's mostly just a matter of compiling a single .c file into a .so file and installing the header file, manual Makefiles would work great for that - but, as said before, I'm pretty to open to any build system that works, I'll still continue to use my favorite in my own projects :) |
I also prefer CMake to autotools, which I perceive as complicated. I have no experience with Meson. One thing I can add to the discussion is that CMake can generate both |
and many others I'll work on CMakeLists for hidapi |
👎 on meson. The maintainer is not very collaborative and has very strange dogmatic ideas about build systems that just do not work in the real world. For example, if hidapi was used by a dependency-of-a-dependency, meson would prevent you from building due to how it structures subprojects. Cmake doesn't care much about how you structure your files, in contrast. Also, if hidapi is used as a library for a build-time executable that is also built at build time (e.g. build EXE with hidapi as dep, then use the generated EXE as a tool to build another target), and the other target also uses hidapi, Meson will prevent the build because it thinks there will be a symbol collision - it tries to be smarter than you. There have been very exhaustive discussions over at the Meson repository and none of them have resulted in any meaningful thought coming from the maintainer. I highly caution anyone against using Meson. CMake is currently the industry standard, and while it isn't perfect it's definitely the most cooperative tool at the moment. |
Making some progress: https://github.com/libusb/hidapi/tree/cmake-support Before making a PR to master want to finish first:
|
Any chance of getting a rebase of cmake_support branch to include the latest commit on main? |
Done. But would be better if I put my mind and my hands into finishing the change and making a proper PR... |
Thank you very much, greatly appreciated. |
I've just given the cmake-support branch a go. There is one issue encountered so far. Currently when trying to use HIDAPI_WITH_LIBUSB, there doesn't appear to be any way to pass in the libusb header location explicitly (and defer the static / shared library linkage), hence it throws up the CMake error about not having the required libusb dependency (from pkg_check_modules). I'm quite a CMake noob... so perhaps there's an easy way around this, I just don't know it. |
Well, it is not only a CMake configuration alone... Since libusb officially provides only one method of delivery - build/install with autotools -> use pkg-config to find the installation - that is what being used by my implementation of CMake build system for hidapi. It uses pkg-config to find libusb and link against it. One not very obvious, but method that should work in your case: Before including hidapi as your CMake subdirectory, set This looks like a workaround (and it kind of is), but it should work for you. Meanwhile, I'll try to find a better solution. |
Hi @bevanweiss, |
@Youw thanks for your work already done to support cmake. It's a milestone! Could you please explain, how much ready is this branch today? On my linux environment, I receive:
EDIT: Thanks again. |
I think is is absolutely ready for Windows, macOS, Linux and Android. Other then that, I believe it is ready. In fact, I'm personally using this branch in my own (private) project, and keeping it in sync with master.
yeap |
@Youw could you open a PR with it (and preferably ping me? 🙂) I have some suggestions about the current configuration. |
@Youw did you try cross-compilation for arm64? It doesn't work for me:
I have both |
I don't suppose you cross-compiled libusb first? |
I have pre-compiled version installed via apt (architecture arm64) |
What is the package name you installed? |
For full cross-compilation:
The same configuration works good when using native amd64 architecture. |
@Youw
When I set this from cmake's command line argument ( |
@Youw one more issue:
This shows when using libusb backend - |
Its been a while since I tried to cross-compile relatively large CMake project with a hand-made toolchain file. I usually get one from YOCTO or use the one provided by Android NDK - those work for my just fine. I'll be able to try to repeat your steps later this week, maybe over the weekend. Some thoughts from top of my mind:
This is weird, I'd expect a variable set in toolchain file to be available everywhere. Maybe you need to make a full clean rebuild? This needs to be investigated more properly, but your workaround looks good to me.
Again, need to refresh my knowledge here, but it doesn't look obvious why do you need to set the last two parameters here.
This is a surprise. As I mentioned, I'll be able to check a bit later. One more thing you could try:
Add an This will give you the abitility to control build configuration in more details (check hidapi CMakeLists.txt in and /src directories, as I didn't document those yet). This will also allow you to disable standard install targets from hidapi CMake scripts, and make your own, if you need to. Can you share your toolchain file too (as an attachment)? If I'd try what you do, best if I use exactly same configuration. |
The pkg-config issue was on my side. The
and it works OK For the last problem, please check out the attached minimal reproducible example. Just run:
The example also contains toolchain file for arm64, but the last issue is reproducible on any architecture on Linux, so don't bother with cross-compiling. |
Ok, I see the problem you have, @jm4R. In your example, you add_subdirectory hidapi with EXCLUDE_FROM_ALL property. One of the simple options for you: set(HIDAPI_WITH_HIDRAW OFF) before add_subdirectory(${hidapi_SOURCE_DIR}/src ${hidapi_BINARY_DIR}) NOTE1: I suggest you NOTE2: if you do as NOTE1 suggests, you can also control whether to install hidapi or not by I'll see if I can come up with more user-friendly solution of-the-box. |
@Youw it's ok, but the variables you mentioned should be well documented. Or maybe the defaults could be different when build as non-root project (I think this is a common practice, yet I am not a cmake expert) |
You're right about the documentation. That's why these changes are not in master. It is yet to be finished. |
As a common CMake user I'd suggest it is very convenient to have CMake supported by the project off-the-box.
A platform like MSVC would gain a great benefit - won't need to have MSVC-2010/2015/2017/2019/etc. separate projects.
I'm ready to prepare the whole infrastructure if the team/community don't have anything against it.
The text was updated successfully, but these errors were encountered: