This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+tools/cmake
2019-05-27 01:23:35 +03:00
..
img
config.el Update change logs 2019-01-13 16:32:47 +02:00
packages.el Update change logs 2019-01-13 16:32:47 +02:00
README.org documentation formatting: Sun May 26 20:58:52 UTC 2019 2019-05-27 01:23:35 +03:00

CMake layer

/TakeV/spacemacs/media/commit/d3cb959e36580a11cf2b17c47ba72886668fecd0/layers/+tools/cmake/img/cmake.png

Description

This layer adds support CMake scripts.

Features:

  • Support for CMake configure/build (with limited support for other build systems), automatic generation of compile_commands.json (compile flags), on-the-fly configuration of flycheck, company-clang and RTags (if installed) with cmake-ide.
  • Run selected test using Helm interface via helm-ctest.

Install

Layer

To use this configuration layer, add it to your ~/.spacemacs. You will need to add cmake to the existing dotspacemacs-configuration-layers list in this file.

CMake-ide configuration

To enable CMake projects support set the layer variable cmake-enable-cmake-ide-support to t in the dotfile:

  (setq-default dotspacemacs-configuration-layers
    '((cmake :variables cmake-enable-cmake-ide-support t)))

cmake-ide plugin has several useful configuration options.

To configure project you need to create .dir-locals.el file. In case of using make as CMake backend you can use helm-make to select required build target.

Here is a sample configuration. This configuration forces cmake-ide to use the local directory and pass that directory to helm-make. Such config allows to build your project with SPC c c key binding.

Additionally it's possible to configure helm-ctest in the same way via defining helm-ctest-dir. Trailing slash is required.

  ((nil .
        ((cmake-ide-project-dir . "~/Project")
         (cmake-ide-build-dir . "~/Project/build")
         (cmake-ide-cmake-opts . "-DCMAKE_BUILD_TYPE=Debug")
         (helm-make-build-dir . "build")
         (helm-make-arguments . "-j7")
         (helm-ctest-dir . "~/Project/build/")
         )))

In case of projectile it's possible to configure project like:

  ((nil . ((eval . (setq
                    projectile-project-test-cmd #'helm-ctest
                    projectile-project-compilation-cmd #'helm-make-projectile
                    projectile-project-compilation-dir "build"
                    helm-make-build-dir (projectile-compilation-dir)
                    helm-ctest-dir (projectile-compilation-dir)
                    ))
           (projectile-project-name . "My Cool Project")
           (projectile-project-run-cmd . "./run.sh")
           (projectile-project-configure-cmd . "cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..")
           (helm-make-arguments . "-j7"))))

Key bindings

Key binding Description
SPC m p c Run CMake and set compiler flags for auto-completion and flycheck
SPC m p C Run CMake if compilation database JSON file is not found
SPC m p d Remove file connected to current buffer and kill buffer, then run CMake
SPC m p t Run CTest