-
Couldn't load subscription status.
- Fork 1.1k
cmake: Add dev-mode #1234
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: Add dev-mode #1234
Conversation
CMakePresets.json
Outdated
| { | ||
| // Don't set "generator" here because developers should still be able to | ||
| // select their preferred generators. As a result we're affected by CMake | ||
| // bug https://gitlab.kitware.com/cmake/cmake/-/issues/23341, which means | ||
| // that dev-mode is not selectable in cmake-gui. But in our case, that's | ||
| // probably rather a feature than a bug. |
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.
GitHub highlights these lines because JSON doesn't have comments. But some parsers are very forgiving, and CMake's parser seems to be of that kind.
|
Concept ACK. |
|
nb: This is not urgent, but anyway my availability in the next weeks will be restricted. If this requires changes, feel free to take over and make changes in a separate branch / PR. |
Presets are available in CMake 3.19+ only. Should it be documented? |
I tend to say it's not necessary. It's for devs only and if you invoke |
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.
ACK d121958, tested on Ubuntu 22.04.
| @@ -0,0 +1,23 @@ | |||
| { | |||
| "version": 3, | |||
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.
That makes this preset usable only with CMake 3.21+.
And CMake 3.19 fails silently when cmake --preset dev-mode.
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.
Hm, I see. Do you have a suggestion? I don't think we can do much about it, except hope that noone tries to use this with 3.19 or 3.20.
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.
As it is a developer-specific feature, I'm OK with the current patch.
|
Maybe add |
|
Well, There are two options to avoid such behavior:
|
Done. I took the version without the leading slash because this file could in principle exist in
Okay, yes, this command was just intended as an example.
My thinking is that, while |
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.
ACK e8a4a94
.gitignore
Outdated
| libsecp256k1.pc | ||
|
|
||
| ### CMake | ||
| CMakeUserPresets.json |
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.
Maybe add
/CMakeUserPresets.jsonto the.gitignore?Done. I took the version without the leading slash because this file could in principle exist in
src/orexamples/too.
https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html:
CMakePresets.jsonandCMakeUserPresets.jsonlive in the project's root directory.
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.
Ok, you're right, fixed.
Command line options allow the user/developer to override a template. |
e8a4a94 to
712090f
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.
re-ACK 712090f
Would you prefer this to be added? I'm fine with either, but I still tend to think that this should not be the concern of the template. Pragmatically speaking, it doesn't make a big difference, of course. |
Let's merge it in its current state :) |
|
@theuni Would you like to review this? :) |
I just tested with 3.16.3, and it just silently swallows the unknown option and continues. Since I would otherwise have assumed it worked, I agree it's worth adding a quick note about required 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.
ACK modulo comment nit.
47bab0f to
50ef165
Compare
|
Updated to add a comment on the required CMake version. |
CMakePresets.json
Outdated
| // Note: JSON does not support officially, but CMake apparently | ||
| // ignores lines starting with whitespace followed by "//" silently. |
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.
Digging into the CMake repository brings some discussions about that:
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.
Urghs, thanks for doing the research here. So they first enabled comment support intentionally, then disabled it intentionally. Currently, it just works by accident.
I'm not sure how we should deal with this. Having the comments is risky because future versions may not support them. (This PR here uses presets only for dev mode, but we may add other presets, e.g., for coverage....)
It seems that CMake's parser defeats all the hacks I could imagine or find in https://stackoverflow.com/questions/244777/can-comments-be-used-in-json. Things we could do:
- Have a template file and strip
//lines using grep, generating the actual.jsonfrom it. But this needs some mechanism to make sure that the file is up to date etc... All doable but seems overkill for this tiny issue. - (https://hjson.github.io/ is an entire off-the-shelf solution for this, but that adds a maintainer dependency and is hard to remember.)
- We could just drop the comments. CMake templates support a
cmakeMinimumRequiredfield which I think is enough to document the need for CMake 3.21. A better warning should then be added to build docs (to be written :D). The comment about the missing generator thing can be in the commit message (not optimal but okayish).
I lean towards dropping comments. Sad that we need to spend time on this...
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 lean towards dropping comments.
Agree.
To use, invoke `cmake` with argument `--preset dev-mode`. Solves one item in bitcoin-core#1235. One disadvantage over `./configure --enable-dev-mode` is that CMake does not provide a way to "hide" presets from users. That is, `cmake --list-presets` will list dev-mode, and it will also appear in `cmake-gui`, even though it's not selectable there due to bug https://gitlab.kitware.com/cmake/cmake/-/issues/23341. (So in our case, that's probably rather a feature than a bug.) We curently use version 3 presets which require CMake 3.21+. Unfortunately, CMake versions before 3.19 may ignore the `--preset` argument silently. So if the preset is not picked up, make sure you have a recent enough CMake version. More unfortunately, we can't even spell this warning out in CMakePresets.json because CMake does not support officially support comments in JSON, see - https://gitlab.kitware.com/cmake/cmake/-/issues/21858 - https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5853 . We could use a hack hinted at in https://gitlab.kitware.com/cmake/cmake/-/issues/21858#note_908543 but that's risky, because it could simply break for future versions, and we probably want to use presets not only for dev mode.
This file is specifically intended for *local* CMake templates (as opposed to CMakePresets.json).
50ef165 to
ce5ba9e
Compare
|
Forced-push to remove the comments and move their contents to the commit message. |
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.
ACK ce5ba9e
| @@ -0,0 +1,19 @@ | |||
| { | |||
| "cmakeMinimumRequired": {"major": 3, "minor": 21, "patch": 0}, | |||
| "version": 3, | |||
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 note for reviewers: version 3 is required as we omit the generator entry.
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.
ACK ce5ba9e
To use, invoke
cmakewith argument--preset dev-mode.One disadvantage over
./configure --enable-dev-modeis that CMake does not provide a way to "hide" presets from users. That is,cmake --list-presetswill list dev-mode, and it will also appear incmake-gui, even though it's not selectable there due to a bug in cmake-gui.Solves one item in #1224.