vim-cmake icon indicating copy to clipboard operation
vim-cmake copied to clipboard

CMake Preset support

Open bharatvaj opened this issue 2 years ago • 5 comments

Request description

Can we support CMake presets? I would like to see an option which shows the available presets and let's the user tab complete it. And possibly change state variables like g:cmake_build_dir_location based on selected preset.

Desired behavior

  1. After calling the CMakePreset command with the preferred preset, cmake --preset should be called.
  2. The g:cmake_build_dir_location, g:cmake_default_config et al. should be updated to match selected preset from CMakePresets.json file.
  3. The preset name should be displayed on the vim status line if enabled through any variable, g:cmake_show_preset_in_status_line maybe?
  4. Plugin should be able to configure with g:cmake_preset and do steps 1-3

Alternatives solutions

I am able to do this via terminal. This is my flow

# list the presets, maybe this can be used for autocomplete?
cmake --list-presets
# generate cmake files based on the preset
cmake --preset x86_64-unknown-linux-gnu
# configure local .vimrc manually 
# for pointing vim-cmake to the generated files

bharatvaj avatar Aug 13 '21 03:08 bharatvaj

Hi, thanks a lot for requesting this. Looks interesting. I'm currently on holidays, I'll have a look at it when I'm back.

cdelledonne avatar Aug 24 '21 07:08 cdelledonne

In my workflow I use all of the following commands:

cmake --list-presets
cmake --preset <my_config_preset>
cmake --build --list-presets
cmake --build --preset <my_build_preset>
ctest --list-presets
ctest --preset <my_test_preset>

These are all of the current preset commands as of CMake 3.22.0, so if all of these were supported then this plugin would have "full"-preset support - which would be great!

Kuxe avatar Nov 21 '21 18:11 Kuxe

So far, none of the vim/neovim plugins seem to support this feature. But there are more and more projects that use it. In these projects, you can't use these plugins, which is a pity. The Cmake plugin from VSCode has this feature integrated right away. I really hope that the vim/neovim plugins will follow suit. The cmake-presets are very comfortable.

maikelmeyers avatar Aug 10 '22 07:08 maikelmeyers

Hi, thanks for posting this comment. I absolutely agree that CMake presets should be supported, as you said more and more projects are using this feature. I just have little time to work on Vim-CMake at the moment, and I believe that adding support for presets requires some non-negligible amount of work to properly design and implement this addition. I can't promise anything for this month, but I'll try to find some time to at least sketch out what the feature should look like, so that in principle anyone could submit a PR.

cdelledonne avatar Aug 10 '22 07:08 cdelledonne

Here comes the reference: https://github.com/microsoft/vscode-cmake-tools/blob/HEAD/docs/cmake-presets.md

It would be enough if the preset mode is activated as soon as a CMakePresets.json is present.

Then it only needs a few elements:

  1. Selecting one of the Configure/Build and Test presets from the existing ones.
  2. CMakeGenerate/Build/Test are called with the selected presets.

maikelmeyers avatar Aug 10 '22 22:08 maikelmeyers