Hi, I'm Civitasv, a passionate C++ developer. 💬 Ask me about anything, I am happy to help.
civitasv / cmake-tools.nvim Goto Github PK
View Code? Open in Web Editor NEWCMake integration in Neovim
License: GNU General Public License v3.0
CMake integration in Neovim
License: GNU General Public License v3.0
Hi,
Your commit 14603f0 broke the plugin, I can't use CMakeBuild
, CMakeGenerate
didn't test other commands, but I think they are on the same boat.
Error executing Lua callback: .../.nvim/plugged/cmake-tools.nvim/lua/cmake-tools/init.lua:99: attempt to index upvalue 'config' (a nil value)
stack traceback:
.../.nvim/plugged/cmake-tools.nvim/lua/cmake-tools/init.lua:99: in function <.../.nvim/plugged/cmake-tools.nvim/lua/cmake-tools/init.lua:87>
Anyway, I really like your work, this excellent plugin :D
Regards,
Lucas
Bug description
I'm not sure if there are some undocumented pre-reqs or anything?
Run :Telescope cmake_tools
gives:
Error executing Lua callback: ...ta/lazy/cmake-tools.nvim/lua/cmake-tools/file_picker.lua:18: bad argument #1 to 'ipairs
' (table expected, got nil)
stack traceback:
[C]: in function 'ipairs'
...ta/lazy/cmake-tools.nvim/lua/cmake-tools/file_picker.lua:18: in function 'get_files_from_target'
...ta/lazy/cmake-tools.nvim/lua/cmake-tools/file_picker.lua:51: in function 'get_source_files'
...ake-tools.nvim/lua/telescope/_extensions/cmake_tools.lua:30: in function 'fn'
...ake-tools.nvim/lua/telescope/_extensions/cmake_tools.lua:16: in function <...ake-tools.nvim/lua/telescope/_ex
tensions/cmake_tools.lua:8>
.../nvim-data/lazy/telescope.nvim/lua/telescope/command.lua:193: in function 'run_command'
.../nvim-data/lazy/telescope.nvim/lua/telescope/command.lua:253: in function 'load_command'
...Local/nvim-data/lazy/telescope.nvim/plugin/telescope.lua:108: in function <...Local/nvim-data/lazy/telescope.
nvim/plugin/telescope.lua:107>
Steps to reproduce
I have telescope and cmake_tools plugins loaded. My current dir is a small c++/cmake repo. I run.
:Telescope cmake_tools
Expected behavior
The telescope command executed ok.
Screenshots
Environment
Bug description
I wrote a cmake-variants.yaml ...
then I tried to use it. CMakeSelectBuildType, set.
CMakeRun
then i discovered that no comment ( # line ) in yaml supported ( some really strange cmake errors ).
ok, delete comments, try again.
and interesting new folder names ( cmake_build_Debug + ... ) :
Ok, let's rename options from "cpm_modules" to just cpm_modules.
Ok, it works.
Though, folder name is cursed.
Then, if type :CMakeRun
and build an executable it will fail because of cursed names:
also it makes cpm_modules folder in the way: "cpm_modules
and ;cpm_modules
if it's written in cmake-variants.yaml as "cpm_modules"
.
I'll put here my cmake-variants.yaml:
buildType:
default: debug
choices:
debug:
short: Debug
long: Emit debug information
buildType: Debug
release:
short: Release
long: Optimize generated code
buildType: Release
asan:
short: Asan
long: Instrument with Address Sanitizer
buildType: Asan
tsan:
short: Tsan
long: Instrument with Thread Sanitizer
buildType: Tsan
cacheCPMPackages:
default: cpm_modules
choices:
dotcache:
short: .cache_cpm_modules
long: Save modules in .cache/cpm_modules
settings:
CPM_SOURCE_CACHE: .cache/cpm_modules
cpm_modules:
short: cpm_modules
long: Save modules in cpm_modules
settings:
CPM_SOURCE_CACHE: cpm_modules
useLocalPackages:
default: uselocal
choices:
onlylocal:
short: Onlylocal
long: Use only local packages. (not recommended)
settings:
CPM_LOCAL_PACKAGES_ONLY: ON
CPM_USE_LOCAL_PACKAGES: OFF
CPM_DOWNLOAD_ALL: OFF
uselocal:
short: UseLocal
long: Use local packages, if they exist on system, and if not, download them.
settings:
CPM_LOCAL_PACKAGES_ONLY: OFF
CPM_USE_LOCAL_PACKAGES: ON
CPM_DOWNLOAD_ALL: OFF
downloadall:
short: downloadAll
long: Download all packages, no use of local packages ( except some CPMFindPackage stuff ).
settings:
CPM_LOCAL_PACKAGES_ONLY: OFF
CPM_USE_LOCAL_PACKAGES: OFF
CPM_DOWNLOAD_ALL: ON
I guess, this can be used at ModernCppStarter to reproduce
Expected behavior
cd ./cmake_build_UseLocal\ +\ Debug\ +\ cpm_modules\(Use\ local\ packages,\ if\ they\ exist\ on\ sy...\)/
or something like.Environment
This is not a bug report but more of a question of whether the following is possible:
Is this possible and something I missed?
May I ask which plugin is used for the build button in the demo video?
First: thanks for the plugin, love it 👍
Here my little issue:
I start neovim from my home directory, I open a c file from my dev folder (I use fzf-lua). I have an autocommand that change into this directory and !pwd is returning the right path.
But when I run Cmake generate, the build directory is created in home.
This behaviour does not occur with shaturs neovim-tasks. Here the build dir is always right.
Describe the problem or limitation you are having
I sometimes need to run executables with specific environment variables.
This could also be useful for generating and building as some compilers (qnx?) require specific env-vars to compile.
Describe the solution you'd like
Inspired by how QtCreator handles environment variables I think it would be useful to be able to configure env-vars for the generate/configure/build step and for individual targets.
My idea is that the env-vars could be configured in a regular vim buffer using lua code. (Similar to the quick window of harpoon)
For example. CMakeConfigureBuildEnvironment
would open up a floating window with:
return {
env {
VERBOSE = 1,
}
}
This would add VERBOSE=1
to env-vars for the generate and build steps
And CMakeConfigureRunEnvironment {target_or_current}
for target specific env-vars.
return {
inherit_build_environment = true,
env {
log_file = "/tmp/log.txt",
log_level = "trace",
}
}
This would add VERBOSE=1 log_file = "/tmp/log.txt" log_level = "trace"
to env-vars when running the specific target.
This would also be nice since cmake-tools
could persist these similar to session.
Describe alternatives you've considered
I can just close nvim set env-vars.
Given CMakePresets.json:
{
"version": 3,
"configurePresets": [
{
"name": "example",
"binaryDir": "example_build_directory"
}
]
}
Running:
:CMakeSelectConfigurePreset
" Select example
:CMakeBuild
Outputs:
Error: could not load cache
Error: could not load cache
Right now if use cmake-variants, you still is requested to choose among a lot of options, but there's no default option, though in cmake-variants we write it.
A possible solution: add the default option to the list from :CMakeSelectBuildType to position 1
Alternative solution: if entered no number, choose default.
Possible problems: checking if there's default for every choice.
like
cmake -B build -G "MinGW Makefiles"
I have been working on a PR for two output buffers. One for all cmake tasks except run, and another exclusively for run/launch tasks.
The intention for this is to keep track of outputs from all the previous commands that cmake tools generates and provide an additonal way to view the outputs not just with quickfix lists.(... As nature intended.. XD)
I have setup the window/buffer handling in way that launches a buffer first (if not already exists) that has a unique id that persists across the neovim instance.
The following shortened piece of code is intended to launch a job (using native vim/neovim api) and append to an exisint buffer. Here, the problem is in sending lines to the job with stdin. I would appreciate it, if someone can help on this:
Kindly run it and see the output:
local function on_stdout(id, data, event) vim.fn.append(vim.fn.line('$') - 1, data) end
local job_id = vim.fn.jobstart({ "pwsh", "-noprofile" }, { on_stdout = on_stdout })
local function callback(input) vim.fn.chansend(job_id, { input, "" }) end
local function goto_buffer_across_all_tabs(bufname)
for _, tabpage in ipairs(vim.api.nvim_list_tabpages()) do
vim.api.nvim_set_current_tabpage(tabpage)
for _, window in ipairs(vim.api.nvim_tabpage_list_wins(tabpage)) do
local win_bufname = vim.api.nvim_buf_get_name(vim.api.nvim_win_get_buf(window))
if win_bufname:match(bufname) then
vim.api.nvim_set_current_win(window)
return
end
end
end
end
-- vim.cmd([[command! -nargs=* WinGo2 lua goto_buffer_across_all_tabs(<q-args>)]])
local bufnr = vim.api.nvim_create_buf(true, true)
vim.api.nvim_buf_set_name(bufnr, "new")
vim.cmd('vs' .. bufnr)
goto_buffer_across_all_tabs('new')
vim.bo.buftype = "prompt"
vim.api.nvim_get_current_buf()
vim.api.nvim_set_current_buf(bufnr)
vim.fn.prompt_setcallback(bufnr, callback)
vim.keymap.set("n", "<esc>", ":bw!<cr>")
vim.cmd.startinsert()
For testing in unix change pwsh to /bin/sh
Currently this is the output:
Bug description
The following error appears when I run the CMakeGenerate
command.
Steps to reproduce
CMakeGenerate
command .I used the example config:
require("cmake-tools").setup {
cmake_command = "cmake",
cmake_build_directory = "",
cmake_build_directory_prefix = "cmake_build_", -- when cmake_build_directory is "", this option will be activated
cmake_generate_options = { "-D", "CMAKE_EXPORT_COMPILE_COMMANDS=1" },
cmake_build_options = {},
cmake_console_size = 10, -- cmake output window height
cmake_show_console = "always", -- "always", "only_on_error"
cmake_dap_configuration = { name = "cpp", type = "codelldb", request = "launch" }, -- dap configuration, optional
cmake_variants_message = {
short = { show = true },
long = { show = true, max_length = 40 }
}
}
I also tried setting cmake_command = "D:/Program Files/CMake/bin/cmake"
but I get the same error.
Expected behavior
I expected the CMake executable to be found automatically from my PATH environment variable.
However it seems to try to search it in /usr/bin/cmake
, but I'm on Windows and I don't see an option to set the CMake Executable path in the plugin config. Is there one?
Environment
Currently, the build directory name needs to be hard coded in the configuration. It would be helpful to have a more flexible approach wherein a build_dir_prefix
strings is provided to be user configurable. This will enable C++ developers to have access to multiple type of builds.
Examples:
build_dir_prefix
: cmake_build_
In the above example, the build directory will become cmake_build_Debug
, cmake_build_Release
, wherein the appropriate suffix is chosen by the build type
build_dir_prefix
: build/
In this above example with the trailing /
, a classical nested hierarchical structure of various types of builds can be facilitated
build
├── Debug
├── MinRelease
├── Release
└── RelwithDebInfo
The above is a classical build tree for multiple type of builds, and is easily done through cmake invocations at the command-line, but this is not currently possible with this plugin.
The vimscript plugin, [cmake4vim](https://github.com/ilyachur/cmake4vim)
already supports this, and I am using it now in my projects, but I'd like to move to this lua-based plugin, mainly for its integration with nvim-dap
.
Of course, to prevent breaking changes to existing users' configurations, the build_dir_prefix
behaviour should be activated only when cmake_build_directory
is set explicitly to an empty string. Otherwise, we simply ignore the build_dir_prefix
setting, and simply overwrite builds each time to the folder configured in cmake_build_directory
(the current behaviour).
It could be good to be able to configure directly the kits in lua or at least be able to define a custom path for the json file to avoid to copy/paste the kits in each project.
Useful Link:
Still have problems in my computer.
Keep notifying can't open file.
Originally posted by @Civitasv in #5 (comment)
Hi!
I cannot find what icon plugin do you use in example lualine config, in this line:
cmake-tools.nvim/docs/howto.md
Line 50 in 08cb757
Thanks for creating this plugin, it works very good in my workflow
Would be great to have smth like that
No output from Windows OS, but good output from WSL with the exact same config:
My full config: rohit-kumar-j/nvim
Possible Issue: On windows, the command is CMakeRun command is generated like this:
D:\VS2022\Koala\build\src/Debug/hello.exe
require("cmake-tools").setup {
cmake_command = "cmake", -- cmake command path
cmake_build_directory = "build", -- cmake generate directory
-- cmake_build_directory_prefix = "cmake_build_", -- when cmake_build_directory is "", this option will be activated
cmake_generate_options = { "-DCMAKE_EXPORT_COMPILE_COMMANDS=1" }, -- it will be activated when invoke `cmake.generate`
cmake_build_options = {}, -- it will be activated when invoke `cmake.build`
cmake_console_position = "belowright", -- "bottom", "top"
cmake_console_size = 10,
cmake_show_console = "always", -- "always", "only_on_error"
cmake_focus_on_console = false, -- true, false
cmake_variants_message = {
short = { show = true },
long = { show = true, max_length = 40 }
},
cmake_dap_configuration = {
name = "cpp",
type = "codelldb",
request = "launch",
stopOnEntry = false,
runInTerminal = true,
console = "integratedTerminal",
},
}
Environment
I forgot to add this in the Multiple Buffers PR:
For users that are using nvim-tree, they need to add this for preserving the size of window when opening or closing the tree and avoid resizing. Otherwise the constant resizing can get very annoying.
require("nvim-tree").setup {
--
view = {
preserve_window_proportions = true,
---
},
}
Can you add this in the docs?
Hello, thank you for making this plugin! I am sure this is a super basic question, but I am very new to using VIM so please forgive me lol. I followed the instructions in the ReadMe, but I end up getting this error when I try to run CMake commands: " Cannot find CMakeLists.txt at cwd. Are we supposed to create the CMake files manually? Sorry again for the extremely basic question.
I think the quickfix window should stop auto scrolling if the window is currently not at the bottom.
For example while a longer operation is running I notice something and scroll up to take a look. But the window keeps scrolling down. I think the auto scrolling should stop in this case and only continue once I manually scroll back to bottom.
What do you think? I think it would be useful option (or even be the default)
The first question, when I am in a Chinese environment, it will not be able to display Chinese, is there any way to deal with this?
When there are multiple compilers on my PC, such as the MSVC compiler and MinGW exist at the same time, I specify the MinGW compiler, but it cannot recognize it (MinGW has added environment variables and can be specified directly using the console)
After CMakeRun i see output on the bottom of output, but if i moved to "code window" my output closed.
Bug description:
I can escape from terminal mode in output window and then move to code window. But often i need to get rid of window for a while, write some code, and then return to it.
Expected behavior:
Toggle output window keymap
BTW
Thanks for an awesome plugin especially after 2 years vscode experience
because I use MSVC compiler,so the default generate style can't export the compile_commands.json file,and the clangd can't user this file.
Describe the problem or limitation you are having
CMakePresets.json
and CMakeUserPresets.json
can include other files with the include field in file version 4 and later. Files included by these files can also include other files. If CMakePresets.json
and CMakeUserPresets.json
are both present, CMakeUserPresets.json
implicitly includes CMakePresets.json
, even with no include field, in all versions of the format.
Users may leverage that feature to have common definitions across different projects.
The conan package manager uses that when generating multiple build configurations, for example:
CMakeUserPresets.json
:
{
"version": 4,
"vendor": {
"conan": {}
},
"include": [
"~/project/build/CMakePresets.json"
]
}
~/project/build/CMakePresets.json
:
{
"version": 3,
"vendor": {
"conan": {}
},
"cmakeMinimumRequired": {
"major": 3,
"minor": 15,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "'default' config",
"description": "'default' configure using 'Ninja Multi-Config' generator",
"generator": "Ninja Multi-Config",
"cacheVariables": {
"CMAKE_POLICY_DEFAULT_CMP0091": "NEW"
},
"toolchainFile": "~/project/build/conan_toolchain.cmake",
"binaryDir": "~/project/build"
}
],
"buildPresets": [
{
"name": "release",
"configurePreset": "default",
"configuration": "Release"
},
{
"name": "debug",
"configurePreset": "default",
"configuration": "Debug"
},
{
"name": "relwithdebinfo",
"configurePreset": "default",
"configuration": "RelWithDebInfo"
}
],
"testPresets": [
{
"name": "release",
"configurePreset": "default",
"configuration": "Release"
},
{
"name": "debug",
"configurePreset": "default",
"configuration": "Debug"
},
{
"name": "relwithdebinfo",
"configurePreset": "default",
"configuration": "RelWithDebInfo"
}
]
}
The plugin current behavior cannot detect the presets coming from the included file.
Describe the solution you'd like
As a CMake user who often works with including presets into other presets file, I'd like to have at list the first inclusion handled automatically by the plugin, so that it can see and work with every preset defined in the files included in the top level CMake[User]Presets.json
.
Describe alternatives you've considered
A more complete solution would be handling the inclusion recursively, but that would be more complicated. I guess most cases of preset inclusion happens on the first level only. I don't have data to support that assumption, though.
Additional context
Conan users will appreciate the solution.
Yes, I think it is okay to read it from a file, just like JSON and YAML format. It's natural to me.
Originally posted by @Civitasv in #2 (comment)
Describe the problem or limitation you are having
I need to set the working directory of some cmake targets to something else. I'm not sure on how to do this right now as it will always choose the build folder where the executable is run with CMakeRun as the working directory.
Describe the solution you'd like
Something similiar to CMakeLaunchArgs, like CMakeLaunchDir where an absolute or relative (eg ../) path to the build folder can specified for both simply running the executable or debugging with nvim-dap.
Describe alternatives you've considered
Right now I have no real alternative but to manually run with the adopted working dir, but eg for debugging it would be really nice to have it just working out of the box.
Describe the problem or limitation you are having
Sometimes we're configuring with certain project specific settings like -DXXX_ROOT=<...>
. Such settings might be dependent on host computer environments therefore they are not suitable to directly hard coded in CMakeLists.txt
.
Describe the solution you'd like
Support (partially) parsing CMakeSettings.json
or CMakePresets.json
like VS/VSC to add or override some global cmake settings.
In the Run/Launch terminal, when build commands are chained(default build before run), it does not move out of build directory to build, but builds in the same directory, and errors!
D:/Koala/build ~$ cmake --build build --target testing_ptr && cd "D:\Koala\build" && .\testing_ptr.exe
Error: D:/Koala/build/build is not a directory
It should be:
D:/Koala/build ~$ cd "D:\Koala" cmake --build build --target testing_ptr && cd "D:\Koala\build" && .\testing_ptr.exe
...
...
However, this works the first time as there is no full cmd.
Bug description
I have a project on my external hard drive, and the drive is mounted as /run/media/eax_ebx/Verbatim Drive
. I can successfully generate and build my project, but when I run :CMakeRun
or click the Run button on lualine, select the executable, it gives the error zsh:1: no such file or directory: /run/media/eax_ebx/Verbatim
. This error does not appear, if the path to the executable does not contain spaces.
Steps to reproduce
/home/<username>/my project
.cmake_minimum_required(VERSION 3.15)
project(test LANGUAGES CXX)
add_executable(test "Test.cpp")
#include <iostream>
#include <cstdlib>
int main() {
std::cout << "Hello, World!\n";
return EXIT_SUCCESS;
}
test
project and run it. On my machine, I get the error zsh:1: no such file or directory: /home/eax_ebx/my
.my project
to my_project
and delete the build directory. Repeat the 4. step. But now, on my machine, I don't get the error and it successfully runs and I see "Hello, World!" in the console.Expected behavior
I think no matter what the path to the executable looks like (contains Unicode symbols, whitespaces, etc.), the plugin should run this executable without any problems.
Environment
Additional context
Configuration of cmake-tools in init.vim:
Plug 'Civitasv/cmake-tools.nvim'
lua << EOF
require("cmake-tools").setup {
cmake_command = "cmake",
cmake_build_directory = "build",
cmake_build_directory_prefix = "", -- when cmake_build_directory is "", this option will be activated
cmake_generate_options = { "-D", "CMAKE_EXPORT_COMPILE_COMMANDS=1", },
cmake_build_options = {},
cmake_console_size = 20, -- cmake output window height
cmake_console_position = "belowright", -- "belowright", "aboveleft", ...
cmake_show_console = "always", -- "always", "only_on_error"
cmake_dap_configuration = { name = "cpp", type = "codelldb", request = "launch" }, -- dap configuration, optional
cmake_variants_message = {
short = { show = true },
long = { show = true, max_length = 40 }
}
}
EOF
I think the problem may be somewhere in the code of the cmake.run
function, for example, the path to the executable is not wrapped by quotation marks.
CLion has a nice feature that allows you to configure cmake to automatically run in a docker container. In my work, I am developing on a mac, but am working on C/C++ code that needs to be build and deployed in a linux environment. The nice thing about CLion is that when I define the docker container to run, everything else is abstracted away. I can simply build the project without having to think about starting up a container.
Ideally I would like to be able to setup a docker image that cmake-tools can use to run all cmake commands in. That way code intelligence and built binaries would be created within the docker environment, not my laptop.
I tried doing this to simply change the command used to call cmake under the hood, but this doesn't seem to work.
require("cmake-tools").setup {
cmake_command = "bash -c docker run --rm -v $(pwd):/home/dev-repo -w /home/dev-repo ubuntu20-container cmake"
}
I also realize I could probably setup neovim to run in the docker container and develop from there.
Is there a way to achieve this behavior with the plugin as is? or would this need to be a new feature?
Bug description
using :CMakeGenerate
or :CMakeBuild
on an existing project produces the following error:
Error executing Lua callback: ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: attempt to concatenate field 'short' (a nil value)
stack traceback:
...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: in function 'format_item'
...\Local\Programs\Neovim\share\nvim\runtime/lua/vim/ui.lua:48: in function 'select'
...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: in function 'select_launch_target'
...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:467: in function <...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:422>
Error executing Lua callback: ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: attempt to concatenate field 'short' (a nil value)
stack traceback:
...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: in function 'format_item'
...\Local\Programs\Neovim\share\nvim\runtime/lua/vim/ui.lua:48: in function 'select'
...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: in function 'select_launch_target'
...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:467: in function <...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:422>
Error executing Lua callback: ...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: attempt to concatenate field 'short' (a nil value)
stack traceback:
...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: in function 'format_item'
...\Local\Programs\Neovim\share\nvim\runtime/lua/vim/ui.lua:48: in function 'select'
...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:673: in function <...k\packer\start\cmake-tools.nvim/lua/cmake-tools/init.lua:654>
The same is true for :CMakeRun
Steps to reproduce
Run either of the commands above in a cmake project.
Expected behavior
Expected to see the output window with the cmake generation and build output.
Environment
Additional context
Thank you so much for this awesome tool, this has made my C++ nvim experience really great.
Describe the problem or limitation you are having
error messages from compiler output are not parsed in quickfix list (windows, msbuild)
Describe the solution you'd like
Some 'windows users please note:' section in the readme/docs
The required action
-- MSBuild:
vim.opt.errorformat:append([[\ %#%f(%l\,%c):\ %m]])
-- cl.exe:
vim.opt.errorformat:append([[\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %m]])
Bug description
Hi! When the module gets imported, then an autocommand will be generated here, using default value for cmake_regenerate_on_save
(true). So, after config is created, cmake_regenerate_on_save
will have no effect.
Steps to reproduce
require("cmake-tools").setup {
cmake_regenerate_on_save = false,
}
Re-generation is still triggered, which is disturbing, when using auto-save plugin. If you're interested, I can make a PR.
In the Readme under the full configuraiton, there is require("user.icons")
, can you link it or directly add the symbols to the Readme? I have tried searching the evil.lua example but cannot find these symbols.
Bug description
I have just upgrade to the latest version and CMakeRun no longer executes the compiled binary
I have been using a simple CMakeLists file which use to work.
cmake_minimum_required(VERSION 3.26)
project(avl-tree)
set(CMAKE_CXX_STANDARD 20)
add_executable(avl-tree main.cpp)
target_link_libraries(avl-tree PRIVATE -fsanitize=undefined,address)
target_compile_options(avl-tree PRIVATE -fsanitize=undefined,address)
I also have a very simple cmake.lua plugin which has also worked before some recent changes in this project.
local M = {}
M.plugin = {
"Civitasv/cmake-tools.nvim",
config = function()
local cmake = require("cmake-tools")
cmake.setup({
cmake_command = "cmake",
cmake_build_directory = "",
cmake_build_directory_prefix = "cmake_build_",
cmake_generate_options = { "-D", "CMAKE_EXPORT_COMPILE_COMMANDS=1" },
cmake_generate_on_save = false,
cmake_build_options = {},
cmake_console_size = 10,
cmake_show_console = true,
cmake_variants_message = {
short = { show = true },
long = { show = true, max_length = 40 },
},
cmake_quickfix_opts = {
show = "always",
position = "belowright",
size = 10,
},
})
vim.keymap.set("n", "<leader>cg", function()
vim.cmd.CMakeOpen()
vim.cmd.CMakeGenerate()
end)
vim.keymap.set("n", "<leader>cb", function()
vim.cmd.CMakeOpen()
vim.cmd.CMakeBuild()
end)
vim.keymap.set("n", "<leader>cr", function()
vim.cmd.CMakeOpen()
vim.cmd.CMakeRun()
end)
vim.keymap.set("n", "<leader>cc", function()
vim.cmd.CMakeClose()
end)
vim.keymap.set("n", "<leader>cl", function()
vim.cmd.CMakeOpen()
vim.cmd.CMakeClean()
end)
end,
}
return M
When you run now a window opens with the following:
cd /usr/home/xxxx/projects/cpp/avl-tree/cmake_build_Debug &&
an the program no longer runs and outputs in this window.
Hope this helps.
Blair
Bug description
when you call :CMakeBuild -j32
, the plugin invokes cmake as cmake -j12 --build ...
which results in cmake erroring out. If you put -j12
in config.build_options
, the flags are appended at the end of the line and it works as expected though.
Steps to reproduce
in any cmake project, clean the build directory, open neovim and run :CMakeBuild j32
.
Expected behavior
I would expect the arguments of CMakeBuild to be passed after the --build
flag. So in my example, cmake would be called as cmake --build -j32 ...
.
Environment
Additional context
This seems to be where the argument order is mixed up: https://github.com/Civitasv/cmake-tools.nvim/blob/master/lua/cmake-tools/init.lua#L193
Thanks for an awesome plugin BTW!
Describe the problem or limitation you are having
Currently cmake_tools
only reacts to changes on CMakeLists.txt
files. But changes the other files such as .cmake
files or files used in configure_file
can can cause cmake to re-generate.
Describe the solution you'd like
Fortunately file_picker.get_cmake_files
should already contain all relevant files that can cause re-generation. Do you think it would be possible to also (or only) react to those files? It would have to be updated after each cmake.generate()
Recently I've been getting following sporadic errors when using CMakeRun
or similar.
stack traceback:
[C]: in function 'nvim_buf_get_var'
.../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:170: in function 'send_data_to_terminal'
.../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:461: in function 'execute'
...are/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/utils.lua:74: in function 'execute'
...hare/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/init.lua:417: in function 'callback'
...hare/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/init.lua:309: in function 'on_success'
.../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/quickfix.lua:44: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
Error executing Lua callback: .../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:10: Key not found: terminal_job_pid
Error executing Lua callback: .../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:10: Key not found: terminal_job_pid
stack traceback:
[C]: in function 'nvim_buf_get_var'
.../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:10: in function 'has_active_job'
...are/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/utils.lua:130: in function 'has_active_job'
...hare/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/init.lua:477: in function <...hare/nvim/lazy/cmake-tools.nvim/lua/cmake-tools/init.lua:474>
Error executing Lua callback: .../nvim/lazy/cmake-tools.nvim/lua/cmake-tools/terminal.lua:10: Key not found: terminal_job_pid
Steps to reproduce
It occurs randomly when trying to run a target. Sometimes right after starting nvim, sometimes after using nvim for a while. After getting the first error, the second error occurs consistently every time I try to run. I have to restart nvim at that point.
Environment
OS: Linux and Windows WSL (not sure about native windows)
Bug description
When exiting the current CMakeRun-terminal and cmd CMakeRun, an error occurs.
Steps to reproduce
Expected behavior
no errors, running the executor
Environment
Line 18 in d34c6d9
There is a missing quote surrounding the plugin.
I noticed that build_options
are saved in the session config
...
build_options = { "-j32" },
...
I looks like they take precedence over the config passed to setup
. E.g once saved the user has no way to change those.
Should build_options
be removed from session?
Alternatively should they be configurable via the config window? That would mean the config passed to setup
is then just the default.
Hi everyone,
First off I really appreciate this plugin, it's made the transition to nvim from vscode way more pleasant.
I ran into an issue while working on an existing CMake project in neovim for the first time. Configuring and building with cmake-tools works correctly, but the code is covered in erroneous warnings from clangd; it looks like compile_commands.json
isn't being generated anywhere in the build folder. My setup for cmake-tools
is exactly the same as the readme in this repo, and I set up clangd via Mason and lspconfig like so:
lspconfig["clangd"].setup({
capabilities = capabilities,
on_attach = on_attach,
on_new_config = function(new_config, new_cwd)
local status, cmake = pcall(require, "cmake-tools")
if status then
cmake.clangd_on_new_config(new_config)
end
end,
})
Am I misunderstanding something about how this works or where compile_commands.json
should be? Do I need to change the values of cmake_soft_link_compile_commands
or cmake_compile_commands_from_lsp
in the setup function? I'm on nvim version 0.9.0 and macOS Ventura 13.4 if that's relevant.
Any advice is much appreciated!
Currently, I use these codes to check if there is a process is finished, which is need to chain callback.
But this will block neovim instance, we should find a non-blocking or async way to check this.
Bug description
when cmake-tools starts, the message dtable::stdio_init couldn't make stderr distinct from stdout
flashes up.
Steps to reproduce
Config:
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
local plugins = {
-- cmake
{
'Civitasv/cmake-tools.nvim',
lazy = false,
config = function(plugin) require('cmake-tools').setup({}) end,
cmd = {'CMakeBuild', 'CMakeGenerate'},
-- keys = {
-- {"<leader>cc", ":CMakeBuild<CR>", desc = "CMake Configure"},
-- },
dependencies = {
'nvim-lua/plenary.nvim',
},
},
}
local opts = {}
require("lazy").setup(plugins, opts)
Start nvim (that's it)
Expected behavior
At best, no error message. Improvement would be the error being reported to a log with a call stack.
Environment
Bug description
cmake-tools.nvim/lua/cmake-tools/init.lua
Lines 108 to 118 in 2139329
As the code show, when config.cmake_always_use_terminal
is true, I call cmake.build(opt, callback)
with a callback function, the callbak will be called immediately without build
Steps to reproduce
require 'cmake-tools'.setup {
cmake_build_directory = 'build',
cmake_always_use_terminal = true,
cmake_soft_link_compile_commands = false,
}
add keymap to cmake.build with callback, such as
function()
require 'cmake-tools'.build({ bang = false }, function()
vim.notify("Cmake build success")
end)
end
Expected behavior
Build success, then call callabck
Environment
Another proposal
Another proposal, expose local variable config
in cmake-tools/init.lua
for conveniently obtaining information, e.g. target_binary_path
Describe the problem or limitation you are having
I am working on a C++ project which accesses files in a Resources
folder as if they were in the working directory. When running the project through CMakeRun
, the working directory is that of nvim, so it cannot load the files it needs.
Describe the solution you'd like
The ability to configure the working directory used when launching the program.
Describe alternatives you've considered
I found this issue in vscode-cmake-tools, but setting cwd
in the require("cmake-tools").setup
call did not appear to do anything. I might be doing this wrong, however, as I'm not sure how launch.json
settings translate to this project.
Hi, this plugin is very useful for me, but I want to change debug to cppdbg, however my configuration is not working.
When I use :CMakeDebug, it still calls codelldb.Then I tried to change other configurations, but it still did not work.
Here is my configuration code:
-- plugins.lua
use({
"Civitasv/cmake-tools.nvim",
config = function()
require("plugin-config.cmake-tools")
end,
})
-- plugin-config/cmake-tools.lua
local status, cmake = pcall(require, "cmake-tools")
if not status then
vim.notify("没有找到 cmake-tools")
return
end
cmake.setup({
cmake_command = "cmake",
cmake_build_directory = "build",
cmake_build_type = "Debug",
cmake_generate_options = { "-D", "CMAKE_EXPORT_COMPILE_COMMANDS=1" },
cmake_build_options = {},
cmake_console_size = 10, -- cmake output window height
cmake_show_console = "always", -- "always", "only_on_error"
cmake_dap_configuration = { name = "Launch file", type = "cppdbg", request = "launch" }, -- dap configuration, optional
cmake_dap_open_command = require("dap").repl.open, -- optional
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.