cmake-tools.nvim icon indicating copy to clipboard operation
cmake-tools.nvim copied to clipboard

Allow more flexible cwd and build directory configuration

Open uiofgh opened this issue 10 months ago • 1 comments

I uses nvim-rooter and workspace.nvim to manange my projects, everytime i open my project, i have to manually use CMakeSelectCwd and CMakeSettings to locate my cmakelists.txt and set build directory.

This behavior comes from the fact that cmake-tools.nvim init all its path config when loading the plugin. Any neovim working dir path changed after by other plugins or user operation is ignored. This is really frustrating.

Currently cmake-tools supports session based on cwd, but that path is also decided at setup which won't help in my situation.

Maybe adding some config function that allow users to determine those paths when they are relevant.

require("cmake-tools").setup {
  cmake_build_directory = function() -- currently runs when plugin setups, which won't work if i later changes my working dir
    if osys.iswin32 then
      return "out\\${variant:buildType}"
    end
    return "out/${variant:buildType}"
  end,
  cwd = function() -- add new cwd function
    return custom_user_function()  -- calls everytime when using cmds like CMakeBuild or CMakeRun.
  end,
}

uiofgh avatar Feb 14 '25 07:02 uiofgh

Maybe a custom "find root" function to search for a CMakeLists.txt file in parent directories might help. That could be invoked if the cwd is changed

lceWolf avatar Feb 27 '25 11:02 lceWolf

I've basically the same issue, even if I'm using "coffebar/neovim-project"! I think the approach @lceWolf suggests could work.

pdicerbo avatar Jun 04 '25 21:06 pdicerbo

It is indeed very necessary for us to have such a feature, I am avoiding this issure by execute require("lazy").reload("cmake-tool.nvim") automatically every time when switch a project session, that's obviously not a good solution...

celeste3z avatar Oct 11 '25 16:10 celeste3z