Shatur / neovim-cmake

CMake integration for Neovim
GNU General Public License v3.0
87 stars 19 forks source link

Add possibility to set build_dir from a function #40

Closed JafarAbdi closed 2 years ago

JafarAbdi commented 2 years ago

I work with a pretty big codebase which consists of multiple CMake packages (sometimes 300 :D), so having a fixed string for the build_dir doesn't work well for my case, it would be great to have an option to call a function similar to nvim-lspconfig's root_dir

Shatur commented 2 years ago

How your callable build_dir looks?

JafarAbdi commented 2 years ago

This's how a workspace looks like

workspace/
  src/
    pkg1/
    ...
  build/
    pkg1_build_dir/
    ...

So, what I do is create a file called .clangd_config that live in each package's root path (it gets automatically generated when I build), it contains the path to the build directory for that package (it's somewhat a dumb solution, but that's the only solution I had :D)

local get_build_dir = function()
  local file_path = require("lspconfig.util").root_pattern(".clangd_config")(vim.fn.expand("%:p:h"))
  local p = Path:new(file_path, ".clangd_config")
  return Path:new(vim.trim(p:read()))
end
Shatur commented 2 years ago

But CMake automatically creates build folder for each project inside the build directory.

JafarAbdi commented 2 years ago

But CMake automatically creates build folder for each project inside the build directory.

The tool we use is built on top of CMake (https://github.com/colcon if you're interested), each package is a standalone CMake project and that tool create the build directory under the workspace directory

Shatur commented 2 years ago

But how you detect for which project you run CMake?

JafarAbdi commented 2 years ago

But how you detect for which project you run CMake?

By looking for .clangd_config file in one of the parent directories of the opened cpp/cmake files

Shatur commented 2 years ago

Got it, please update the README to indicate that build_dir could be a callable and I will merge it.

JafarAbdi commented 2 years ago

Please let me know if the description isn't clear, I apologize for the delayed response.

Shatur commented 2 years ago

It's good, thanks!