2018-01-20 16:08:51 +00:00
|
|
|
|
#+TITLE: CMake layer
|
2018-07-10 10:57:25 +00:00
|
|
|
|
|
2019-05-02 21:49:30 +00:00
|
|
|
|
#+TAGS: layer|tool
|
|
|
|
|
|
2018-01-20 16:08:51 +00:00
|
|
|
|
[[file:img/cmake.png]]
|
|
|
|
|
|
2019-05-07 20:05:06 +00:00
|
|
|
|
* Table of Contents :TOC_5_gh:noexport:
|
2018-01-20 16:08:51 +00:00
|
|
|
|
- [[#description][Description]]
|
|
|
|
|
- [[#features][Features:]]
|
|
|
|
|
- [[#install][Install]]
|
|
|
|
|
- [[#layer][Layer]]
|
|
|
|
|
- [[#cmake-ide-configuration][CMake-ide configuration]]
|
2018-12-05 03:03:03 +00:00
|
|
|
|
- [[#key-bindings][Key bindings]]
|
2018-01-20 16:08:51 +00:00
|
|
|
|
|
|
|
|
|
* Description
|
|
|
|
|
This layer adds support [[https://cmake.org/][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
|
2018-09-19 03:54:47 +00:00
|
|
|
|
of flycheck, company-clang and RTags (if installed) with [[https://github.com/atilaneves/cmake-ide][cmake-ide]].
|
2018-01-20 16:08:51 +00:00
|
|
|
|
- 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:
|
|
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
|
(setq-default dotspacemacs-configuration-layers
|
|
|
|
|
'((cmake :variables cmake-enable-cmake-ide-support t)))
|
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
|
|
=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.
|
|
|
|
|
|
2018-09-19 03:54:47 +00:00
|
|
|
|
Additionally it’s possible to configure =helm-ctest= in the same way via defining ~helm-ctest-dir~.
|
2018-01-24 13:49:06 +00:00
|
|
|
|
Trailing slash is required.
|
|
|
|
|
|
2018-01-20 16:08:51 +00:00
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-01-24 13:49:06 +00:00
|
|
|
|
((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/")
|
|
|
|
|
)))
|
2018-01-20 16:08:51 +00:00
|
|
|
|
#+END_SRC
|
|
|
|
|
|
2018-11-12 22:12:39 +00:00
|
|
|
|
In case of projectile it’s possible to configure project like:
|
|
|
|
|
|
2018-11-09 07:09:41 +00:00
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-11-12 22:12:39 +00:00
|
|
|
|
((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"))))
|
2018-11-09 07:09:41 +00:00
|
|
|
|
#+END_SRC
|
|
|
|
|
|
2018-12-05 03:03:03 +00:00
|
|
|
|
* Key bindings
|
2018-01-20 16:08:51 +00:00
|
|
|
|
|
2018-12-05 03:03:03 +00:00
|
|
|
|
| Key binding | Description |
|
2018-01-20 16:08:51 +00:00
|
|
|
|
|-------------+-------------------------------------------------------------------------|
|
|
|
|
|
| ~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 |
|