• Stars
    star
    714
  • Rank 63,413 (Top 2 %)
  • Language
    Emacs Lisp
  • License
    BSD 3-Clause "New...
  • Created over 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Use Emacs as a C/C++ IDE

cmake-ide

Build Status Coverage Status Melpa Status

CppCon 2015 Lightning talk on cmake-ide:

CppCon 2015 Lightning talk on cmake-ide

Introduction

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 compilation database 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 combination of:

cmake-ide will set variables and call functions for the installed dependent packages.

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.

Features

  • Sets variables for auto-complete-clang, flycheck and 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-dir to be set.
  • cmake-ide-delete-file allows 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.
  • If cmake-ide-build-dir is set, it is considered to be the build directory to run CMake in. Additionally, this will cause cmake-ide-compile to 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-compile-command variable.
  • cmake-ide can 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 -J to index the project files for 0-config "jump to definition" and everything else rtags offers. This only works if both rdm and rc and in the system path or if cmake-ide-rdm-executable and cmake-ide-rc-executable are 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 setting 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 cmake-ide-build-pool-dir and cmake-ide-build-pool-use-persistent-naming, you can fully do away with the need to configure a build directory per project with directory local variables (for example).

Non-CMake projects

Use .dir-locals.el to set the cmake-ide-project-dir and cmake-ide-build-dir variables (use absolute paths).

.dir-locals.el: ((nil . ((cmake-ide-build-dir . "/path/to/build/dir") (cmake-ide-project-dir . "/path/to/project/dir"))))

If a file called compile_commands.json exists in cmake-ide-build-dir, it will work just as well as for CMake projects. Bear (https://github.com/rizsotto/Bear) can be used to generate a compile_commands.json from a make command.

Installation

Install from MELPA or MELPA Stable with:

M-x package-install RET cmake-ide.

Usage

Add this to your .emacs / init.el:

(require 'rtags) ;; optional, must have rtags installed
(cmake-ide-setup)

If cmake-ide-flags-c or cmake-ide-flags-c++ are set, they will be added to ac-clang-flags and company-clang-arguments. These 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.

Related Projects:

More Repositories

1

dpp

Directly include C headers in D source code
D
229
star
2

reggae

Build system in D, Python, Ruby, Javascript or Lua
D
183
star
3

unit-threaded

Advanced unit test framework for D
D
121
star
4

cerealed

Powerful binary serialisation library for D
D
91
star
5

automem

C++-style automatic memory management smart pointers for D
D
85
star
6

mqtt

MQTT broker written in D, using vibe.d
D
58
star
7

fearless

Safe concurrency in D (`shared` made easier)
D
50
star
8

mqttcpp

MQTT broker in C++11
C++
41
star
9

premock

Mock C functions using the preprocessor
C++
32
star
10

python-dpp-nanomsg

Automagically call nanomsg from Python with 2 lines of D code
Makefile
31
star
11

tardy

Runtime polymorphism without inheritance (structs, ints, classes, ...)
D
25
star
12

concepts

Concepts for d
D
22
star
13

mqtt_rs

MQTT broker in Rust
Rust
22
star
14

genomego

Multi-threaded Genetic Algorithms library for Go.
Go
21
star
15

ac-dcd

Auto completion for Emacs using DCD: the D completion daemon
Emacs Lisp
20
star
16

nogc

Utilities to write `@nogc` code
D
17
star
17

unencumbered

Enencumbered allows Cucumber to support step definitions written in D
D
15
star
18

flycheck-dmd-dub

flycheck and DCD dub support to enable D IDE features in Emacs
Emacs Lisp
14
star
19

mirror

Run and compile time reflection for D
D
10
star
20

libclang

libclang binding / wrapper for D
D
8
star
21

pythagoras

Pythagorean triples
D
8
star
22

cmake_modules

Modules for CMake
6
star
23

monty

Python C API for D
D
4
star
24

kwargs

Mimic keyword function arguments with types
D
4
star
25

genomed

Genetic Algorithms library for D
D
4
star
26

mqtt_hs

MQTT broker in Haskell
Haskell
4
star
27

dtest

Utility executable to be used with unit-threaded
D
3
star
28

felix

Category theory types inspired from Haskell
D
2
star
29

cereal

C++
1
star
30

scheme_hs

Write yourself a Scheme in Haskell
Haskell
1
star
31

test_allocator

D
1
star
32

all-dub-packages

Utility to get all dub packages that still build
D
1
star
33

unit-thread

C++
1
star
34

ldc-xcompile-windows

Scripts and tips to cross-compile D source files into Windows binaries from Linux using LDC
Shell
1
star