Specify format of `cmake_build_dir` path
Closed this issue ยท 9 comments
Is your feature request related to a problem? Please describe.
I have several projects at work, and for each one I have to set up the build directory
manually since it's in the form of $HOME/workspace/build/$project_name/$compiler/$build_type
, but currently I cannot tell the plugin to have it in that form.
The default after setting the cmake_build_dir_prefix
is $HOME/workspace/build/$build_type
.
Describe the solution you'd like
I would like to be able to specify the format of the path to the build directory, like mentioned above, although that may be overkill.
Describe alternatives you've considered
Currently I edited autoload/utils/cmake.vim:50
to this:
return g:cmake_build_dir_prefix . l:cmake_info['cmake']['project_name'] . '/' . g:cmake_cxx_compiler . '/' . l:build_type
This works after the build folder has been created since l:cmake_info['cmake']['project_name']
is empty the first time, and it's not persistent across multiple sessions, which makes sense since it's hackish.
Additional context
I would open a PR, but I'm not sure how to enable this feature in a resonable way, if the user should be able to set a format for it, e.g. path/$project_name/$compiler/$build_type
, I don't exactly know how to implement that, except it being a literal string of vimscript and then just execute
it, but I'm just a vimscript beginner so I'm not sure if that's the way to do it.
Also the "new" path should be remembered somehow for the next vim
sesssion to just run :CMakeBuild
And I'd actually be happier with using the name of the project's root folder in the output build path, instead of the ['cmake']['project_name']
, currently for that I have a separate script which uses basename $(git rev-parse --show-toplevel)
In the meantime, I just edited the source like this:
--- a/autoload/utils/cmake.vim
+++ b/autoload/utils/cmake.vim
@@ -47,7 +47,8 @@ function! s:detectCMakeBuildDir() abort
return l:cmake_info['cmake']['build_dir']
endif
let l:build_type = s:detectCMakeBuildType()
- return g:cmake_build_dir_prefix . l:build_type
+ let l:project_name = systemlist('basename $(git rev-parse --show-toplevel)')[0]
+ return g:cmake_build_dir_prefix . l:project_name . '/' . g:cmake_cxx_compiler . '/' . l:build_type
endfunction
Hi @mark2185
Sorry, I didn't have a time to have a look at the issue.
If you have several projects, why cannot you use local vimrc files in order to define the build folders for each project?
I think in this case the plugin should allow to use build paths like: $HOME/workspace/build/$project_name/$compiler/$build_type
No problem, glad you found time at all!
Well that thought didn't even occur to me.
What do you suggest, that I hardcode
let g:cmake_build_dir_prefix = $HOME/workspace/build/$(basename $(git rev-parse --show-toplevel))/clang/
in e.g. ./.vim.custom
in each of my projects?
@mark2185 Yes it is exactly what I mean. Is it possible for you?
It can be more convenient because local vimrc files also allow to specialise different options (not only g:cmake_build_dir_prefix
) for example g:cmake_usr_args
or something else.
Sure it's possible, that solves most of my problems!
I just need to find a way how to get the cmake_cxx_compiler
in it and I'm all set!
Maybe you can use something like:
local vimrc:
let l:home = ...
let l:project_name=...
let g:cmake_cxx_compiler = 'compiler'
let g:cmake_build_dir_prefix = l:home . '/workspace/build/' . l:project_name . '/' . g:cmake_cxx_compiler . '/'
That almost solves it. I want to be able to choose different compilers, e.g. emscripten
, gcc
, clang
, so that the output dir is created automatically.
If I understood correctly, in order to use your suggestion I should explicitly source the local vimrc before each build, so the cmake_build_dir_prefix
is evaluated again? Although, that could easily be solved with a map
... I'll try this out and report back if it's not working! Thanks!
I think it really depends on a way how you choose the compiler.
As a variant you can define the function which will change the compiler and update cmake_build_dir_prefix
.
Great! Thanks so much for your help, consider this issue solved!