A minor-mode integrating the CMake build process with the Emacs ecosystem.
Emacs Lisp
Latest commit 5212063 Jul 20, 2015 @alamaison Merge pull request #10 from syohex/remove-needless-code
Remove needless code
Failed to load latest commit information.
README.md Autoload `cmake-project-mode` correctly Jul 9, 2015
cmake-project.el Remove needless code Jul 19, 2015


Emacs CMake project mode

A minor-mode integrating the CMake build process with the Emacs ecosystem.


Emacs build tools for C/C++ generally assume a Makefile exists for the project but this isn't necessarily the case for projects managed by CMake which can generate many different types of project file. Integrates the CMake build process with the existing Emacs tools.

This mode is not for editing the CMakeLists.txt themselves; that is left to the major-mode cmake-mode.


Copy this file somewhere on your Emacs load path or use Marmalade and the package manager to install it.

Either auto-load the mode in your init file by adding the line:

(autoload 'cmake-project-mode "cmake-project" nil t)

Or simply require the library:

(require 'cmake-project)

Then use M-x cmake-project-mode in any buffer you wish to use the mode in. Alternatively, start the mode automatically for any C/C++ file whose directory includes a CMakeLists.txt:

(defun maybe-cmake-project-hook ()
  (if (file-exists-p "CMakeLists.txt") (cmake-project-mode)))
(add-hook 'c-mode-hook 'maybe-cmake-project-hook)
(add-hook 'c++-mode-hook 'maybe-cmake-project-hook)


Configuring build tree

Use M-x cmake-project-configure-project to configure or reconfigure a CMake build tree. The function finds the source automatically based on the current buffer.

The compile command

This mode makes the compile command, M-x compile, build the project by default via CMake in a bin subdirectory of the project source root directory.


This mode integrates with Flymake so that, when flymake-mode is enabled, the entire project is built whenever the buffer is saved and any errors are higlighted in the buffer. This is different from Flymake's typical behaviour which builds only the file for the buffer in question. CMake doesn't provide a way to build one file at a time (or at least we don't know of a way) so we must build everything.