-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add CMakeList.txt #1
Conversation
Ported from libusb/libusb#1134 |
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.
a general comment:
- I suggest we follow some general CMake guidelines/code-style, e.g.:
UPPER_CAMEL_CASE
for all variables, including user-defined;
At the end, I'd like us to some practices we've umplemented for HIDAPI (documented here), e.g. add_subdirectory(libusb)
should be easy to do for any project (be configurable)
And thanks for doing this in a first place. |
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.
Add various comment and add support for find_package(usb-1.0)
for other project.
Feel free if you have questions 😃 Thanks for your initial commit.
Once this template will be a bit stabilize, I will try to add github actions.
Do you think the project name should be |
I don't think so. So if the resulting binary is |
There's quite a bit of comments in here :) and i'll have limited bandwidth until next week. I'd really appreciate any contributions to the branch if anyone else has bandwidth and would like to accelerate the merge (Seems like there's a few followup that might be queued behind it) |
It's worth adding a cmake style guide here since I have my own preferences but I'll gladly follow what you'd like them to be I tend to follow lower_case for local scoped variables and function names and UPPER_CASE for global scope variables / cached variables (I probably have violations for my own policy in this pr) but a few lines to standardize styling might help everyone. We can probably add a comment at the top here for styling if you don't want an extra file |
That's probably what triggered my attention the most.
Ideally would be to introduce something like cmake-format. But for now, jsut keeping the implementation clean/consistent - worth more as far as efforts spending is conserned. The most important idea is to make the usage of CMakeLists.txt as much flexible/comfortable as possible for all of: this repo developers, package managers, submodule users, etc. That's why I referenced the HIDAPI document where many such ideas already implemented and I'd like to use those here too. As much as I can tell based on comments in this thread - we're generally on the same page. |
It's complicated to contribute on a PR because I can't push code on it. Should I create a PR on our repo and you merge it ? |
I'm pretty sure you can push directly into ankurvdev/libusb-cmake:master Preferably to keep the entire conversation in this thread. |
Let me know if there are any permission issues. The branch should be open for any contributions. |
2) Added examples 3) Fixed a few other issues 4) Builds and runs under MSVS2022/MSVS2019/Ubuntu2202/OSX
Hi I might have gotten a little carried away. A Thursday night little project went south because libusbs lack of cmake support and I pulled this repo to find the "finish me" message ;) Anyway while doing other things I've updated the CMakefile per the comments. There were also a few things wrong or missing so I've sorted them out. @ankurvdev you should have a pull request on your repo if you want to take it forward. |
Updated the main CMakefile
Other than the above mentioned issues, the PR already works pretty well. I tested under Windows using the following test enviroment.
|
@mcuee About the lib name, I would say it's in fact correct, in over +20 year of coding I've never seen a Windows static lib prefixed with lib unless there is a Linux coder around ;) The lib prefix is very much a POSIX think which is why MinGW64 does it. However naming the bin is easy. Also good spot on the test being stress by bad. |
@ankurvdev Just a quick question, why did you put back the "" around all the paths? Did you run into a problem or was that just a style thing? Also thanks for the if(LIBUSB_TARGETS_INCLUDE_USING_SYSTEM) It got lost |
Quotes around paths in general are needed to handle paths with spaces. Most of source paths here don't need spaces anymore since I yanked out the SOURCE_DIR from LIBSUSB_ROOT which wasn't really needed and libusb paths themselves dont have spaces, but I also now simply consider it a style+good-practice to have all paths and single path variables be enclosed in Quotes for uniformity. |
Good point on the spaces and as its a standards thing then cool. tbh I'm working with about 4 different styles of CMake currently and was a little bit in auto mode at the time. Will keep with the ""'s The CMAKE_CURRENT_SORUCE_DIR Is something I do because of problems with nesting CMakefiles so its a defensive thing, in this case it might be overkill. |
I'm wondering when that's useful. I've never had to, the only place I remember using it was an add_custom_commands that did some sort of code generation etc and wanted to deal exclusively in absolute paths with Binary dir as my working dir. I tried an uber project with libusb add_subdirectory, with both , it being an actual subdirectory and with absolute path outside the outer project (with binary_dir) and it worked. So I figured I'll remove it and let you holler back :) |
lol problem. |
Haven't tried it yet, but I believe this is a perfect opportunity to do so for me. Git submodules is the default option under the tips of my fingers, but I'm in constant search of the alternatives to it.
I totally get you you on this one. In fact - I usually recommend using the "default" platform-specific behavior, which is familiar to the "natives" of the platform. But in this particular case - we're trying to mimc the current Autotools build system of libusb, so that in cases like this there is no or minimum difference in the behavior. TL;DR: Lets set the |
Thanks for all of the updates. I'll have a chance to take a look, hopefully, later this week. |
Ping ... |
- a bit if code-style consistency; - use standard CMake variables where possible (instead of CMAKE_SYSTEM_NAME STREQUAL) - `CMAKE_C_COMPILER_ID MATCHES "Clang"` instead of `STREQUAL` - at least to cover AppleClang; - automatically `enable_testing()` when `LIBUSB_BUILD_TESTING=ON` - otherwise the option doesn't makes sense; - don't buile example by default; - don't build tests by default; - all sources sorted alphabetically; - remove subjective comments;
I've applied all of the fixes from my comments myself, and I think we're in a good place to have it merged. |
Fixed. |
No description provided.