vscode-cmake-tools
vscode-cmake-tools copied to clipboard
CMake presets parser not compliant with CMake
Issue Summary
The presets parser used in VSCode (and VSStudio) is not compliant with the cmake specifications. It's for example possible to create a set of preset files that will correctly parse using VSCode, but not using CMake itself (VSCode parser is accepting things it shouldn't). I've created a ticket on the CMake issue tracker with an example of such files: https://gitlab.kitware.com/cmake/cmake/-/issues/25505
When carefully reading CMake presets specifications, it's quite clear that the issue is actually a bug in VSCode/VSStudio (by being not strict enough).
Thanks for letting us know! This is definitely something that we want to make sure is matching cmake.exe, I'll mark it as a bug and place it on our backlog!
Just so you know, I successfully tested the CMake dev branch that fixes the issue I reported (all links in the CMake ticket). It's using (required) the upcoming version: 9
field, so I truly hope the VSCode plugin will support it in the near future.
Thanks a lot.
Hi, small update: version: 9
will come in next cmake version, the code has been merged.
Hopefully VSCode plugin will be updated to support all the new cmake presets
features.
@christophe-calmejane Following up on this, are there explicit items that you've noticed that we should fix? I agree that in general we need to fix it to match ALL of the spec, but I wondered if there are specific things that we should prioritize. Thanks!
Sure, I'll try to do a small setup and share it. It will require ‛version: 9‛ support though, since it's the only way (with official cmake parser) to share common preset files with multiple projects.
Hi,
please find attached a sample projects that works fine when using cmake presets parser (requires version 9 support that will land in 3.30).
The idea is this:
- A cmake presets file is shared accros multiple projects (can be in a submodule or whatever). This file can hold shared compile definition, shared targets, ...
- Each project define the minimum ‛project specific‛ definition and include the ‛shared file‛ to minimize maintenance
After discussing the 2 possibilities with other cmake members, the retained solution was to extend (thus the version 9 for presets definition) the ‛include‛ directive so it can search for ‛sourceDir‛ variable expansion.
So basically in order for my sample project to work with VSCode, the required modifications are:
- Fix the incorrect transitive include declaration from the plugin (ie. each presets file must be able to work as a standalone file, meaning a target definition cannot be searched for in an include file that was included before the file)
- Implement the ‛sourceDir‛ variable substitution
v9 support for cmakepresets will be coming in a later release, see #3946
Hi and thanks for this. Unfortunately the fix broke something that was working previously.
In case you have both CMakePresets.json and CMakeUserPresets.json in your folder, the root file that must be loaded is CMakeUserPresets.json and cmake documentation says that it implicitly includes CMakePresets.json (first thing). It doesn't seem to be the case as my CMakeUserPresets.json which extends some targets defined in my CMakePresets.json aren't recognized anymore.
Edit: seems a bit more complicated, I created a ticket here https://github.com/microsoft/vscode-cmake-tools/issues/3956