{"id":13682106,"url":"https://github.com/Shatur/neovim-cmake","last_synced_at":"2025-04-30T06:33:54.569Z","repository":{"id":37023874,"uuid":"259476212","full_name":"Shatur/neovim-cmake","owner":"Shatur","description":"CMake integration for Neovim","archived":true,"fork":false,"pushed_at":"2022-09-10T14:58:46.000Z","size":190,"stargazers_count":87,"open_issues_count":9,"forks_count":19,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-02T13:33:30.066Z","etag":null,"topics":["cmake","debug","neovim","quickfix","telescope"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Shatur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-27T22:59:51.000Z","updated_at":"2024-07-04T03:40:42.000Z","dependencies_parsed_at":"2023-01-17T13:16:25.455Z","dependency_job_id":null,"html_url":"https://github.com/Shatur/neovim-cmake","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shatur%2Fneovim-cmake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shatur%2Fneovim-cmake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shatur%2Fneovim-cmake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shatur%2Fneovim-cmake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shatur","download_url":"https://codeload.github.com/Shatur/neovim-cmake/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224201865,"owners_count":17272655,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","debug","neovim","quickfix","telescope"],"created_at":"2024-08-02T13:01:40.831Z","updated_at":"2024-11-12T01:31:05.816Z","avatar_url":"https://github.com/Shatur.png","language":"Lua","funding_links":[],"categories":["Lua"],"sub_categories":[],"readme":"# Neovim CMake\n\n**This plugin has been deprecated in favor of [neovim-tasks](https://github.com/Shatur/neovim-tasks)**. I realized that having separate plugins for each build system is inconvenient, so I decided to write a general purpose plugin that could support support any build system. If you don't like this idea don't worry, there is a maintained hard fork called [cmake-tools.nvim](https://github.com/Civitasv/cmake-tools.nvim) with some additional features.\n\nA Neovim 0.7+ plugin that uses [cmake-file-api](https://cmake.org/cmake/help/latest/manual/cmake-file-api.7.html#codemodel-version-2) to provide integration with building, running and debugging projects with output to quickfix.\n\n## Dependencies\n\n- Necessary\n  - [cmake](https://cmake.org) for building and reading project information.\n  - [plenary.nvim](https://github.com/nvim-lua/plenary.nvim) for internal helpers.\n- Optional\n  - [nvim-dap](https://github.com/mfussenegger/nvim-dap) - for debugging.\n\n## Commands\n\nUse the command `:CMake` with one of the following arguments:\n\n| Argument               | Description                                                                                                                                                                                                                                 |\n| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `configure ...`        | Configure project. It uses `g:cmake_build_dir` as a build folder. It will also generate `compile_commands.json` and symlink it to the project directory. Additional arguments will be passed to CMake. Example: `CMake configure -G Ninja`. |\n| `build ...`            | Compile selected target (via `--build`). Additional arguments will be passed to CMake.                                                                                                                                                      |\n| `build_all ...`        | Same as above, but will build `all` rule.                                                                                                                                                                                                   |\n| `run ...`              | Run selected target. Additional arguments will be passed to the target being launched.                                                                                                                                                      |\n| `debug ...`            | Run debugging on selected target. Additional arguments will be passed to the target being launched.                                                                                                                                         |\n| `clean ...`            | Execute `clear` target. Additional arguments will be passed to CMake.                                                                                                                                                                       |\n| `build_and_run ...`    | Execute `CMake build` and, if build successful, then `CMake run`. Additional arguments will be passed to CMake.                                                                                                                             |\n| `build_and_debug ...`  | Execute `CMake build` and, if build successful, then `CMake debug`. Additional arguments will be passed to CMake.                                                                                                                           |\n| `set_target_arguments` | Set arguments for running / debugging target.                                                                                                                                                                                               |\n| `clear_cache`          | Remove `CMakeCache.txt` file from the build directory.                                                                                                                                                                                      |\n| `open_build_dir`       | Open current build folder via `xdg-open` (Linux) or `start` (Windows).                                                                                                                                                                      |\n| `select_build_type`    | Select build type (Release, Debug, etc.).                                                                                                                                                                                                   |\n| `select_dap_config`    | Select a project sepecific DAP configuration. You can configure the options in `require('cmake').setup({ dap_configurations = { ... } })`                                                                                                   |\n| `select_target`        | Select target for running / debugging.                                                                                                                                                                                                      |\n| `create_project`       | Create new CMake project.                                                                                                                                                                                                                   |\n| `cancel`               | Cancel current running CMake action like `build` or `run`.                                                                                                                                                                                  |\n\nIf no arguments are specified, then `configure` will be executed.\n\nAlso the corresponding Lua functions with the same names as the arguments are available from [`require('cmake')`](lua/cmake/init.lua).\n\nCommands `select_build_type`, `select_target` and `create_project` use `vim.ui.select()`. To use your favorite picker like Telescope, consider installing [dressing.nvim](https://github.com/stevearc/dressing.nvim) or [telescope-ui-select.nvim](https://github.com/nvim-telescope/telescope-ui-select.nvim).\n\n## Simple usage example\n\n1. Create a new project (`:CMake create_project`) or open folder with an existing.\n2. Configure project (`:CMake configure`, you can pass any additional CMake arguments) to create build folder and get targets information.\n3. Select target to execute (`:CMake select_target`).\n4. Set target arguments (`:CMake set_target_arguments`, they will be added automatically for running and debugging).\n5. Build and run (`:CMake build_and_run`) or build and debug (`:CMake build_and_debug`) to execute the selected target. You can pass additional arguments to these commands, which will be temporarily added to the arguments from 4.\n\n## Configuration\n\nTo configure the plugin, you can call `require('cmake').setup(values)`, where `values` is a dictionary with the parameters you want to override. Here are the defaults:\n\n```lua\nlocal Path = require('plenary.path')\nrequire('cmake').setup({\n  cmake_executable = 'cmake', -- CMake executable to run.\n  save_before_build = true, -- Save all buffers before building.\n  parameters_file = 'neovim.json', -- JSON file to store information about selected target, run arguments and build type.\n  default_parameters = { args = {}, build_type = 'Debug' }, -- The default values in `parameters_file`. Can also optionally contain `run_dir` with the working directory for applications.\n  build_dir = tostring(Path:new('{cwd}', 'build', '{os}-{build_type}')), -- Build directory. The expressions `{cwd}`, `{os}` and `{build_type}` will be expanded with the corresponding text values. Could be a function that return the path to the build directory.\n  samples_path = tostring(script_path:parent():parent():parent() / 'samples'), -- Folder with samples. `samples` folder from the plugin directory is used by default.\n  default_projects_path = tostring(Path:new(vim.loop.os_homedir(), 'Projects')), -- Default folder for creating project.\n  configure_args = { '-D', 'CMAKE_EXPORT_COMPILE_COMMANDS=1' }, -- Default arguments that will be always passed at cmake configure step. By default tells cmake to generate `compile_commands.json`.\n  build_args = {}, -- Default arguments that will be always passed at cmake build step.\n  on_build_output = nil, -- Callback that will be called each time data is received by the current process. Accepts the received data as an argument.\n  quickfix = {\n    pos = 'botright', -- Where to open quickfix\n    height = 10, -- Height of the opened quickfix.\n    only_on_error = false, -- Open quickfix window only if target build failed.\n  },\n  copy_compile_commands = true, -- Copy compile_commands.json to current working directory.\n  dap_configurations = { -- Table of different DAP configurations.\n    lldb_vscode = { type = 'lldb', request = 'launch' },\n    cppdbg_vscode = { type = 'cppdbg', request = 'launch' },\n  },\n  dap_configuration = 'lldb_vscode', -- DAP configuration to use if the projects `parameters_file` does not specify one.\n  dap_open_command = function(...) require('dap').repl.open(...) end, -- Command to run after starting DAP session. You can set it to `false` if you don't want to open anything or `require('dapui').open` if you are using https://github.com/rcarriga/nvim-dap-ui\n})\n```\n\nThe mentioned `parameters_file` will be created for every project using `default_parameters` as defaults:\n\n```jsonc\n{\n  \"args\": {\"target_name\": [\"arg1\", \"arg2\"]}, // A dictionary with target names and their arguments specified as an array.\n  \"current_target\": \"target_name\", // Current target name.\n  \"build_type\": \"Debug\", // Current build type, can be Debug, Release, RelWithDebInfo or MinSizeRel.\n  \"run_dir\": \"build/my_folder\", // Default working directory for targets. Can be absolute or relative to the current Neovim working directory. By default is missing, in this case current target directory will be used.\n  \"dap_configuration\": \"cppdbg_vscode\" // A string specifying a specific dap configuration to use for this project. If absent then the `dap_configuration` from `require('cmake').setup` will be used, which is the default behaviour.\n}\n```\n\nUsually you don't need to edit it manually, you can set its values using the `:CMake \u003csubcommand\u003e` commands.\n\n### CodeLLDB DAP configuration example\n\n```lua\nrequire('cmake').setup({\n  dap_configuration = {\n    type = 'codelldb',\n    request = 'launch',\n    stopOnEntry = false,\n    runInTerminal = false,\n  }\n})\n```\n\n### Advanced usage examples\n\n```lua\nprogress = \"\"  -- can be displayed in statusline, updated in on_build_output\n\nrequire('cmake').setup({\n  quickfix = {\n    only_on_error = true,\n  },\n  on_build_output = function(lines)\n    -- Get only last line\n    local match = string.match(lines[#lines], \"(%[.*%])\")\n    if match then\n      progress = string.gsub(match, \"%%\", \"%%%%\")\n    end\n  end\n})\n```\n\nAdditionally all `cmake` module functions that runs something return `Plenary.job`, so one can also set callbacks:\n\n```lua\nfunction cmake_build()\n  local job = require('cmake').build()\n  if job then\n    job:after(vim.schedule_wrap(\n      function(_, exit_code)\n        if exit_code == 0 then\n          vim.notify(\"Target was built successfully\", vim.log.levels.INFO, { title = 'CMake' })\n        else\n          vim.notify(\"Target build failed\", vim.log.levels.ERROR, { title = 'CMake' })\n        end\n      end\n    ))\n  end\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShatur%2Fneovim-cmake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FShatur%2Fneovim-cmake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShatur%2Fneovim-cmake/lists"}