-
Notifications
You must be signed in to change notification settings - Fork 3
Building
Once the project is opened, typically the first step is to build it. Now obviously there are potentially many different buildable things, or targets within the project. EDE provides commands to initiate different types of builds, and standard key bindings for these. The default key prefix for EDE is @<kbd>C-c .@</kbd>, although I sometimes use additional bindings for more convenient access.
This is accessible through the @<kbd>C-c . C@</kbd> sequence. The mnemonic here is “C” for compile.
This builds the current source file, by consulting the compilation database for the current file and executing the appropriate command. Note that it does not invoke the Ninja build tool, and hence does not build any dependencies. This is accessible through the @<kbd>C-c . c@</kbd> sequence (note the use of lower-case ‘c’). In addition I have this bound to @<kbd>F8@</kbd>. In the event that the current file is a header file, the associated source file (see “other” file configuration below) will be built instead.
Typically source files are compiled and then linked into libraries and executables. These can be built independently using the standard EDE key binding @<kbd>C-c . C-c@</kbd>, or my customization @<kbd>Ctrl-F8@</kbd>. This will prompt for a target to build and then build it. Importantly, the set of valid targets is read from Ninja, so that tab completion of target names is provided.
The custom key bindings here are set up in an EDE hook function, as follows:
(defun my-ede-hook ()
;; These are a bit more convenient than default bindings
(local-set-key [f8] 'ede-compile-selected)
(local-set-key [(ctrl f8)] 'ede-compile-target)
;; ...
)
(add-hook 'ede-minor-mode-hook 'my-ede-hook)All of the build commands use the built-in emacs compilation library, which provides navigation for any errors and warnings detected. I have found that for Clang and GCC, the output is parsed correctly. There are several standard key bindings for this navigation, but I also like to set up my own:
(global-set-key [f5] 'next-error)
(global-set-key [(shift f5)] 'previous-error)It is fairly trivial in CMake to set up what is known as a “custom command” which can be used to run any executable. These custom commands are very useful for attaching to test executables, so that (for example) the run-fooTest target will build and run the fooTest executable. These targets are read from Ninja, so tab completion is available when invoking these (typically through @<kbd>Ctrl-F8@</kbd> as described above).
Depending on the unit test framework in use (I prefer Boost Test), the test failures may be detected as errors by the Emacs compilation mode, which means the navigation keys work the same way for unit test failures as for compilation failures.

It is important for some of my projects to use multiple build configurations. Generally this means a Debug and a Release build. As described in Opening Projects, when a project is opened, an appropriate build configuration is selected based on the presence of an associated build configuration directory.
Once the project is loaded it is sometimes necessary to switch to a new build configuration. For example, when performing performance testing a Release build is generally desirable, whereas a Debug build may be needed for debugging.
EDE provides the ede-project-configurations-set function to switch to a new build configuration for the project, which is bound to @<kbd>C-c . b@</kbd> by EDE-compdb (the mnemonic is ‘b’ for build). Similarly, EDE-compdb provides ede-compdb-set-configuration-directory to switch to a new directory for the current build configuration, and is bound to @<kbd>C-c . B@</kbd>.