vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

Create configure- and build-presets on-the-fly from an existing build tree

Open neundorf opened this issue 9 months ago • 3 comments

Brief Issue Summary

We discussed this over here, now I created an issue for it as requested: https://github.com/microsoft/vscode-cmake-tools/discussions/4264#discussioncomment-12095234

This is about making it easier to use/"import" an existing cmake build tree without forcing the user to manually create a CMakeUserPresets.cmake.

I often create multiple build trees for one source tree: one for gcc 11, one for gcc 14, one for clang19, one with some project-specific options enabled, one for disabled, one with Qt5, one with Qt6, one under Ubuntu 24:04, one with AlmaLinux 9, one for each configuration, etc.

All I have to do for this is run cmake with the CC and CXX environment variables set respectively, and set some options via cmake-gui. Having to manually add an entry to CMakeUserPresets.json is tedious, and all the information I have to enter there can be easily retrieved via the cmake file API.

Actually I implemented this here as an option for cmake, but it hasn't been accepted yet: https://gitlab.kitware.com/neundorf/cmake/-/commit/f6e4e8a01e62ea0d52da9a2cb8f7d6d0b3f563bd

To my understanding, it should be easy for CMakeTools to create the information for a user preset on the fly when being pointed to a cmake build tree, i.e. when doing "Open folder" on a directory where a CMakeCache.txt exists. If it exists, CMakeTools could parse the CMAKE_COMMAND entry from it (which is according to Brad King basically guaranteed to exist), then check whether a query file for vscode already exists, if not add one, and then run the cmake executables it has found in CMakeCache.txt on it.

Then, for getting all the information which would be necessary for CMakeUserPresets.cmake, all CMake Tools would have to do is:

  • create one configurePreset,
    • find the source directory via the file API in cmakeFiles.json paths::source
    • the "binaryDir" - CMakeTools knows which directory it is opening right now
    • has a "name" - CMakeTools can generate one, e.g. from the path of the build tree
    • maybe (not sure) the "generator" - can be read from file API in index.json, cmake::generator::name
  • create one buildPreset for each configuration, i.e. one for single-config generators, and one for each type for multi-config generators
    • from cache.json, read CMAKE_CONFIGURATION_TYPES in the file API for multiconfig generators, and CMAKE_BUILD_TYPE for single config generators
    • for each of these types
      • add a "name" - e.g. the name of he configurePreset with the buildtype appended
      • add the "configurePreset" it has just created
      • add the "buildType"

With this, I could add arbitrary build trees and just load them directly in VS Code, without having to manually write json syntax correctly. ... or without expecting my colleagues who just want to write C++ code to learn that there is a file called CMakeUserPresets.json andwhat json entries have to be added there so it shows up in VS Code.

CMake Tools Diagnostics


Debug Log


Additional Information

No response

neundorf avatar Feb 23 '25 21:02 neundorf

Is there anything I can do to make this happen ?

neundorf avatar Feb 26 '25 22:02 neundorf

@neundorf Thanks for creating the issue, and thanks for the idea! We have triaged this, and we will do our best to prioritize accordingly, however, as you can imagine with the number of items posted on this repo, there is a lot to juggle.

Typically, we also prioritize based on the number of upvotes on a feature. We are also open to OSS contributions. Thanks!

gcampbell-msft avatar Feb 28 '25 14:02 gcampbell-msft

@neundorf Thanks for creating the issue, and thanks for the idea! We have triaged this, and we will do our best to prioritize accordingly, however, as you can imagine with the number of items posted on this repo, there is a lot to juggle.

Can you recommend a tutorial or video or something on how to get started with plugin/extension development for VS Code ? And where to start in the CMake tools ? Maybe I can get something done myself.

neundorf avatar Apr 12 '25 19:04 neundorf