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

CMakeGenerate! does not define CMAKE_BUILD_TYPE if the target build dir already has a build config

Open henczati opened this issue 3 months ago • 0 comments

Bug description

If my notes are correct from my testing...

If the build config directory that CMakeGenerate! [<config>] would use (i.e. <g:cmake_build_dir_location>/<g:cmake_default_config> or <g:cmake_build_dir_location>/<config> resp.) already exists and has a build config (e.g. by previous :CMakeClean then :CMakeGenerate [<same_config>]), then:

  • :CMakeGenerate! does NOT pass -D CMAKE_BUILD_TYPE=<g:cmake_default_config> to cmake;
  • :CMakeGenerate! <config> does NOT pass -D CMAKE_BUILD_TYPE=<config> to cmake;

For comparison, in initial state (no build config) or after :CMakeClean -- all as expected --:

  • :CMakeGenerate does pass -D CMAKE_BUILD_TYPE=<g:cmake_default_config> to cmake;
  • :CMakeGenerate! does pass -D CMAKE_BUILD_TYPE=<g:cmake_default_config> to cmake;
  • :CMakeGenerate <config> does pass -D CMAKE_BUILD_TYPE=<config> to cmake, for both config==g:cmake_default_config and config!=g:cmake_default_config;
  • :CMakeGenerate! <config> does pass -D CMAKE_BUILD_TYPE=<config> to cmake, for both config==g:cmake_default_config and config!=g:cmake_default_config.

Note, in my testing scenario, let g:cmake_build_dir_location="./build", let g:cmake_default_config="Debug" was applied, so the default config path was ./build/Debug.

To Reproduce

Case: default config

  1. Ensure you have no project build dir for the default configuration (or do CMakeClean, rm -Rf ./build/ etc. -- adjust to your situation).
  2. In project root dir (with main CMakeLists.txt) open vim, run :CMakeGenerate.
  3. Observe CMAKE_BUILD_TYPE being passed as a cli argument to cmake in the output.
  4. Run :CMakeGenerate!.
  5. Observe CMAKE_BUILD_TYPE NOT being passed as a cli argument to cmake in the output.

Case: specified config

Note, tested for <config> := Debug and <config> := Release.

  1. Ensure you have no project build dir for the configuration (or do :CMakeSwitch <config> then CMakeClean, or rm -Rf ./build/ etc. -- adjust to your situation).
  2. In project root dir (with main CMakeLists.txt) open vim, run :CMakeGenerate <config>.
  3. Observe CMAKE_BUILD_TYPE being passed as a cli argument to cmake in the output.
  4. Run :CMakeGenerate! <config>.
  5. Observe CMAKE_BUILD_TYPE NOT being passed as a cli argument to cmake in the output.

Expected behavior

CMakeGenerate! should work exactly as if CMakeClean then CMakeGenerate would have been executed for the given config, even if...or -- given the purpose of the command -- especially if the build config dir already exists. That includes passing the build config type to cmake in CMAKE_BUILD_TYPE, which is currently not happening.

Behavior with minimal .vimrc

Absolute minimum .vimrc not tested.

Used vim-cmake config in .vimrc:

let g:cmake_build_dir_location = './build'
let g:cmake_link_compile_commands = 1
let g:cmake_default_config = 'Debug'

Screenshots

Not deemed important.

Other info

  • OS: Lubuntu 18.04
  • Vim/Neovim version: 9.0 (2022 Jun 28, compiled May 10 2022 08:40:37), Included patches: 1-749 (from binary package 2:9.0.0749-0york0~18.04 from "deb http://ppa.launchpad.net/jonathonf/vim/ubuntu bionic main")
  • Vim-CMake version (:echo cmake#GetInfo().version): 0.16.0
  • CMake version (cmake --version): 3.25.1 (from binary package 3.25.1-12ppa1~ubuntu18.04 from "deb http://ppa.launchpad.net/ecal/cmake-3.25/ubuntu bionic main")

Additional context

None.

henczati avatar Nov 16 '25 20:11 henczati