ilyachur/cmake4vim

CMakeGenerateAndBuild / CMakeGenerateBuildAndRun + automatic target selection

Dich0tomy opened this issue · 7 comments

Hey. Your plugin is awesome and I really apprieciate your work, I think it's the best CMake integration plugin for vim out there, although it lacks two features. Right now when we want to generate, build and run the project we need to do :CMake :CMakeBuild and :CMakeRun separately. Using | with them is not possible, I also tried a few other hacks (with mappings, custom commands, functions, exec, etc.) and nothing worked. I didn't find any solution to it till now.

It would be awesome if you could provide commends that would

  1. Generate files and build at the same time
  2. Generate files, build and run the executable

Additionally - seems like one needs to specify the target by hand everytime. Isn't it possible to detect the target based on add_executable in the cmake?

  1. Generate files and build at the same time

I can see your point, but how often do you really run :CMake? (not a rhetoric question)
Note that it's run automatically by :CMakeBuild if something regarding cmake changes because the CMakeCache.txt is outdated.

  1. Generate files, build and run the executable

That's a fair request, the reason why it doesn't work with pipes and such is that the current implementation runs such commands as jobs (I presume you're using g:cmake_build_executor='job' or g:cmake_build_executor='dispatch') and the plugin currently supports only 1 asynchronous job at a time. Chaining them is not supported.

Technically a command :CMakeBuildAndRun could be added, that sounds like it would solve all/most of your problems.

Additionally - seems like one needs to specify the target by hand everytime. Isn't it possible to detect the target based on add_executable in the cmake?

Well the autocomplete for :CMakeSelectTarget takes into consideration what cmake considers targets, and it stays cached for the next invocations:CMakeBuild and :CMakeRun, you don't have to specify the target every time.
It's stored in the g:cmake_build_target variable.

Hi @B4mbus,

Thank you for this awesome feedback!
Yes, at the current moment the | doesn't work because all commands are executed in the async mode.
Honestly, I don't want to introduce new commands like :CMakeGenerateAndBuild or :CMakeGenerateBuildAndRun because if I try to cover all user combinations it can cause combinatorial explosion 😄
But I got your point, and maybe I need to investigate how pipe works in async modes (job or dispatch modes). I don't have any information about possibility to use pipes in such modes.

If we are talking about targets, you don't need to specify it every time, only before the first execution. After that plugin has information about selected target.

@mark2185
Thinking of it - you are right. Having something like CMakeGenerateAndBuild seems useless, although CMakeBuildAndRun is somethin I'd still be glad to see. I didn't know about the CMakeSelectTarget's autocomplete, thanks for the info.

@ilyachur
I don't want you to cover all the possible combinations, although Build and Run seems like a thing that's done extremely often.

Thanks for the help!

Thinking of it - you are right. Having something like CMakeGenerateAndBuild seems useless, although CMakeBuildAndRun is somethin I'd still be glad to see.

Which g:cmake_build_executor are you using?

I didn't know about the CMakeSelectTarget's autocomplete, thanks for the info.

Oh boy, wait until you discover fzf.

I think will be better if :CMakeRun command triggers build before the run, because looks like CMakeRun always should work on the latest binaries.
I will think how to implement it.

Created PR #135 to support build+run case in the :CMakeRun command.

@B4mbus PR #135 was merged. :CMakeRun command should build and run executable target.