CppCon 2015 Lightning talk on cmake-ide:
cmake-ide is a package to enable IDE-like features on Emacs for
CMake projects. It also supports non-CMake
projects as long as a
is generated out-of-band.This includes autocompletion and on-the-fly
syntax checking in Emacs for CMake projects with minimal
configuration. It uses other packages to do its heavy lifting, in a
cmake-ide will set variables and call functions for the installed
It works by running CMake in Emacs in order to obtain the necessary compiler flags to pass to the other tools. Since all the dependencies are specified in the CMake scripts, there is no need to maintain a parallel dependency tracking system for Emacs. Just ask CMake.
- Sets variables for
flycheckand others for a CMake project automagically. Hardly any configuration necessary.
- Automatically reruns CMake when a file is saved. Great when using
CMake file globs to pick up newly created files, but needs
cmake-ide-build-dirto be set.
cmake-ide-delete-fileallows you to have the same convenience when deleting files. I can't figure out a better way to do this. Obviously simply deleting the file means having to run CMake again manually for it to register the change in the list of files to be compiled.
cmake-ide-build-diris set, it is considered to be the build directory to run CMake in. Additionally, this will cause
cmake-ide-compileto compile the project there. It automatically detects Ninja and Make builds and sets the compile command accordingly. The command to use can be customised by setting the
cmake-idecan make usage of rtags for finding definitions, also using clang. If
(require 'rtags)is called before
cmake-ide-setup, it will automatically start the rtags server (
rdm) and call
rc -Jto index the project files for 0-config "jump to definition" and everything else rtags offers. This only works if both
rcand in the system path or if
cmake-ide-rc-executableare customized correctly.
Build Pool Directories and Persistent Naming of Automatic Build Directories
cmake-ide can automatically create build directories for you -- either in the system's
tmp-directory or under
cmake-ide-build-pool-dir (if set). By default, all automatically
created build directories (no matter where created) will have temporary and unique names,
that will change with each new session and are thus not reusable. You can, however, by
cmake-ide-build-pool-use-persistent-naming use a reproducible naming scheme that
is based on the project's path and will not change as long as the project's path is the
same. This way, you can reuse the build directory.
By using both
you can fully do away with the need to configure a build directory per project with directory
local variables (for example).
.dir-locals.el to set the
(use absolute paths). If a file called
compile_commands.json exists in
it will work just as well as for CMake projects.
M-x package-install RET cmake-ide.
Add this to your
(require 'rtags) ;; optional, must have rtags installed (cmake-ide-setup)
cmake-ide-flags-c++ are set, they will be
variables should be set. Particularly, they should contain the system
include paths (e.g.
'("-I/usr/include/c++/4.9.1" "..."). For a
system with gcc, you can get this information by running
gcc -v -xc++ /dev/null -fsyntax-only (it's the same prerequisite for
auto-complete-clang to work, since that's how clang itself works).
And... that's it. It works by calling cmake and parsing the resulting
JSON file with compiler flags. Set
cmake-ide-build-dir to where your
project is being built and you won't have to call CMake manually again (except
for the first time to specify options). Best done with
directory local variables.