-
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
Add CMake build system #220
Conversation
- general build infrastructure, build options; - libusb/hidraw backends; - (optionally) hidtest;
refactor build system a bit
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.
Going to keep it at what I have now so it's not too overwhelming. Let me know if you'd like me to keep going or not :)
CMakeLists.txt
Outdated
if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "") | ||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Debug;Release;MinSizeRel;RelWithDebInfo" FORCE) | ||
endif() | ||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") | ||
|
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.
Don't modify this; it isn't idiomatic CMake and isn't necessary. If anything, give a warning about it not being set. In almost all cases, the user invoking cmake should specify it - e.g. the following is muscle memory for me personally:
mkdir build && cd build
cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON
if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "") | |
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Debug;Release;MinSizeRel;RelWithDebInfo" FORCE) | |
endif() | |
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") | |
if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "") | |
message(WARNING "CMAKE_BUILD_TYPE not specified; HIDAPI might get mis-configured.") | |
endif() |
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.
so instead of type less, you suggest always type more (and possible type more errors)
I vote for user-friendly
muscle memory for me personally
and it makes it harder to use for those, who don't have such muscle memory
even more: I use cmake-gui even more often then a command-line. It saves me much time. And it saves me time to pick a selection from a combo-box, instead of typing it manually each time.
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.
so instead of type less, you suggest always type more
In this case, yes. It's not about typing less/more. It's about not dictating how users use your package.
Further, most people that will be using this will be either installing from a package manager or using it as a submodule - and only the latter would require someone typing it once to configure it.
and it makes it harder to use for those, who don't have such muscle memory
The point wasn't that I'm better. The point is that it's a pretty standard way to use CMake.
even more: I use cmake-gui even more often then a command-line
That is not the majority case.
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.
or using it as a submodule - and only the latter would require someone typing it once to configure it.
And what problem does it make? Does it limit the users?
The point wasn't that I'm better.
Neither was mine.
The point is that it's a pretty standard way to use CMake.
For all my "small" project I have a different muscle memory: cmake .. && make -j
. Pretty standard to me (and I didn't invented it).
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.
The point here is that this is not common. Another user now has asked about it; you generally don't set these things, because debug/release isn't binary. I've rarely, hardly ever actually, seen a config that does this. It's the general case yo specify the config type you want to build for.
By the way, Travis removed support for open source projects as of this last November. You might want to consider moving entirely to sourcehut (since I see you're already using it and it's a fine option!) or to Github Actions/Circle/etc. The travis jobs will probably never complete and thus stay yellow :) |
Fortunately, that is not true. |
I guess I'd rather finish with the documentation first, so we can avoid my answers like "this is by current design". |
This is a good one, thanks. I'll switch to travis-ci.com. I though I already did it. |
Huh, I read something entirely different on HN. I guess that's good news, then. |
CMakeLists.txt
Outdated
if(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "") | ||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Debug;Release;MinSizeRel;RelWithDebInfo" FORCE) | ||
endif() | ||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") |
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 is the point of this? Why don't you leave it to CMake to set the default?
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 is the point of this?
It is for convenience of those, who are building hidapi as a standalone package/library. Try cmake-gui and you'll see.
Why don't you leave it to CMake to set the default?
Because by default CMake doesn't set it at all. Maybe it does makes sence somtime, but I haven't seen a single real project where it would.
As for the convenience part: see my other comment #220 (comment)
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 still don't get the point of overriding CMake's default behavior, but I guess it doesn't hurt? 🤷 It'll just be a bit of confusing code for people reading this in the future.
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.
but I guess it doesn't hurt?
That's my point.
CMake's default behavior
Humor me. Can you tell what's CMake's default behavior if you don't specify CMAKE_BUILD_TYPE at all?
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.
@Youw
There are multi-config generators (like MSVC) that ignores CMAKE_BUILD_TYPE
. The value of this variable is also not limited to the ones you've listed - for example I use also TSan
and ASan
build type for sanitizers. I agree this part of code isn't necessary here but I don't think it will break something on the other hand.
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.
ignores
CMAKE_BUILD_TYPE
The problem that it is not exactly ignored. It is still available in the CMake scripts, and what bothers me the most: CMake doesn't default it to empty value when MSVC generator is used, but rather to "Debug" (gcc + make - it is defaulted to empy value).
I find such behavior way more confusing, but I guess CMake's developers must have had their reasons for that.
I use also
TSan
andASan
build type for sanitizers
I must admit - I haven't seen any custom CMAKE_BUILD_TYPE usage/implementation, so I guess that is a good point too.
Can you point to me a reference how your/typical usage look like?
As I mentioned earlier, a standalone build likely not to be used with a non-standard build types but I agree that prohibiting it wouldn't be a good thing, so there is that.
I just tested this in two setups and it works great 👍🏻 Is anything holding back the merge? Is there anything I could do to help? 😊 |
I like this CMake improvement as well. Thanks. |
It seems to work fine under my Mac Mini M1 (macOS Big Sur ARM64).
|
What is left to do here? |
Working on it right now. Will finish today/tomorrow. |
Thanks for testing it. I don't have M1 mac to check it myself. Even though there is nothing platform/architecture-specific that could suggest that the build could have failed, having a confirmation is always a good thing. |
Signed-off-by: Ihor Dutchak <[email protected]>
Co-authored-by: Be <[email protected]>
BUILD.cmake.md
Outdated
```sh | ||
cd <build dir> | ||
# configure the build | ||
cmake -GNinja <HIDAPI source dir> | ||
cmake <HIDAPI source dir> | ||
# build it! | ||
cmake --build . | ||
# install library; by default installs into /usr/local/ | ||
cmake --build . --target install | ||
# NOTE: you need to run install command as root, to be able to install into /usr/local/ |
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 would use the source tree as the build directory.
cmake -S . -B build
creates the directory build
if it does not exist, then
cmake --build build
cmake --install build
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 would use the source tree as the build directory.
Of course it wouldn't. It will create a build tree under current directory, which by cd <build dir>
is any directory on the filesystem.
cmake -S . -B build
This creates a build directory inside the source tree, which by my experience is almost as bad as using source tree for build tree.
I'm using a software that scans all files under the source tree to index symbols (automatically) and if the build directory is under source tree - it scans it too, during the build as the build goes... So I prefer (and always recommend) to move build directorry somewhere outside the source tree completely.
This is still work-in-progress. A draft PR, so can be reviewed by community.See: #288.