[cmake-configurator] Support For Metadata #115
Replies: 1 comment 7 replies
-
Thanks for opening this conversation, Michele. I spent some time thinking about this. Let me first describe the problem for everyone. The idea is to develop a cmake configurator similar to ccmake (cmake-curses-gui), but more powerful. Currently, CMake options have a very limited set of types and have no support for groups, dependencies etc. Now, while it would be possible in theory to design from scratch a new format for describing options and then generating cmake files with a new tool, that would be quite inconvenient because the build system will require a whole new "level of indirection" and CMakeLists.txt files wouldn't be the starting point. The new tool will have to be run at each build to check if the "options metadata" changed and re-generate at least one CMakeLists.txt file. That would look like cumbersome to use and would also be totally incompatible CMake-based build systems. Also, what if we'd like to edit the CMakeLists.txt containing the options? If a tool re-generates that will, we'd loose everything we changed. Therefore, the tool would either have to parse and edit it, or the new format will have to include "echo" statements to emit the rest of the CMake. Therefore, that approach would be like creating a whole pre-processor for CMake, which is already kind-of pre-processor for other build systems (make, ninja etc.). That doesn't look like a good solution to me. An alternative idea would be to keep CMakeLists.txt untouched, but to keep in parallel some metadata file for extending the capabilities of the CMake options (stored as cached variables). That could work and it will be less invasive than the previous approach, but will go against the "single source of truth" principle (the name of the options would be mentioned in two files without a direct dependency) and that would cause plenty of issues in the long term. At this point, there only one approach remaining that would keep the CMakeLists.txt files as the "single source of truth" and not require them to be re-generated: put some metadata in the comments. For example, in CMakeLists.txt we have options (cached variables) defined as: set(KRN_TRACK_NESTED_INTERR ON CACHE BOOL
"Track the nested interrupts")
set(PANIC_SHOW_STACKTRACE ON CACHE BOOL
"Show the stacktrace in case of a kernel panic")
set(DEBUG_CHECKS ON CACHE BOOL
"Keep checking ASSERTs and other debug checks even in release builds")
Those definitions will cause CMake to generate a
Tools like Therefore, to reduce this new ugliness, we'll have to try coming up with the format lightweight as possible that will almost "blend in" with the rest of the comment's contents. While a format like JSON would be perfect to parsing, it would be insanely ugly to use while piggybacking data on comments. Imagine this: set(KRN_TRACK_NESTED_INTERR ON CACHE BOOL
"Track the nested interrupts { \"group\"=\"debug\", \"depends\"=[] ") How ugly is that? We'd need a non-invasive format like Markdown, which used things like For example, we could have an initial keyword for specifying the beginning of the metadata like set(KRN_TRACK_NESTED_INTERR ON CACHE BOOL
"Track the nested interrupts [metadata] group=debug; depends_on=DEBUG_CHECKS" How we'll support string values? We could require them to be in single-quotes set(KRN_TRACK_NESTED_INTERR ON CACHE BOOL
"Track the nested interrupts [metadata] group=debug; depends_on=DEBUG_CHECKS; something='abc'" But it's clear that we shouldn't see to use strings very often. An alternative syntax that will allow us to skip the initial set(KRN_TRACK_NESTED_INTERR ON CACHE BOOL
"Track the nested interrupts [group] debug; [depends_on] DEBUG_CHECKS, OPT_3; [something] abc" In this case, even strings won't need quotes, if we continue with the requirement that the special chars won't be used. In theory, even the semi-columns after each option could be skipped with this syntax, e.g.: set(KRN_TRACK_NESTED_INTERR ON CACHE BOOL
"Track the nested interrupts [group] debug [depends_on] DEBUG_CHECKS, OPT_3 [something] abc" But I'm not really sure that's so much better even from the human point of view, because it feels unclear when the value finishes. I'm open to further suggestions about the best syntax to use. |
Beta Was this translation helpful? Give feedback.
-
The whole idea of cmake-configurator is to carry metadata that can be specified to give the actual data itself different properties not supported by ccmake. For example ints are not supported, but it would be a better user experience to suport them. The choice would be primarily between some kind of easy to parse meta-data (such as json or yaml), or some easy to read one (like for example a custom one).
Which one would be a better fit? (We should also think about expansibility in the future)
Beta Was this translation helpful? Give feedback.
All reactions