doomemacs/modules/lang/cc/README.org

127 lines
4.6 KiB
Org Mode
Raw Normal View History

2019-01-05 19:46:14 -05:00
#+TITLE: lang/cc
#+DATE: January 16, 2017
#+SINCE: v2.0
#+STARTUP: inlineimages
* Table of Contents :TOC_3:noexport:
- [[Description][Description]]
- [[Module Flags][Module Flags]]
- [[Plugins][Plugins]]
- [[Prerequisites][Prerequisites]]
- [[irony-server][irony-server]]
- [[MacOS][MacOS]]
- [[Arch Linux][Arch Linux]]
- [[rtags][rtags]]
- [[Configure][Configure]]
- [[Project compile settings][Project compile settings]]
* Description
2017-05-25 20:08:50 +02:00
This module adds support for the C-family of languages: C, C++, and Objective-C.
2017-05-25 20:08:50 +02:00
+ Code completion (~company-irony~)
+ eldoc support (~irony-eldoc~)
+ Syntax-checking (~flycheck-irony~)
2017-12-27 00:32:11 -05:00
+ Code navigation (~rtags~)
2017-05-25 20:08:50 +02:00
+ File Templates ([[../../feature/file-templates/templates/c-mode][c-mode]], [[../../feature/file-templates/templates/c++-mode][c++-mode]])
+ Snippets ([[https://github.com/hlissner/emacs-snippets/tree/master/cc-mode][cc-mode]], [[https://github.com/hlissner/emacs-snippets/tree/master/c-mode][c-mode]], [[https://github.com/hlissner/emacs-snippets/tree/master/c++-mode][c++-mode]])
2017-08-21 20:07:07 +02:00
+ Several improvements to C++11 indentation and syntax highlighting.
2019-01-05 19:46:14 -05:00
** Module Flags
+ ~+irony~ Enable Irony as a backend for code completion, syntax checking, and
eldoc support. This must be disabled to use LSP or another backend.
+ ~+rtags~ Enable rtags integration. A daemon will be spawned the first time you
open a C/C++/ObjC buffer, if one hasn't already.
** Plugins
+ [[https://github.com/Kitware/CMake][cmake-mode]]
+ [[https://github.com/chachi/cuda-mode][cuda-mode]]
+ [[https://github.com/liblit/demangle-mode][demangle-mode]]
+ [[https://github.com/jart/disaster][disaster]]
+ [[https://github.com/ludwigpacifici/modern-cpp-font-lock][modern-cpp-font-lock]]
+ [[https://github.com/salmanebah/opencl-mode][opencl-mode]]
+ [[https://github.com/jimhourihan/glsl-mode][glsl-mode]]*
+ [[https://github.com/guidoschmidt/company-glsl][gompany-glsl]]*
+ [[https://github.com/Sarcasm/irony-mode][irony]]*
+ [[https://github.com/ikirill/irony-eldoc][irony-eldoc]]*
+ [[https://github.com/Sarcasm/flycheck-irony][flycheck-irony]]*
+ [[https://github.com/Sarcasm/company-irony][company-irony]]*
+ [[https://github.com/hotpxl/company-irony-c-headers][company-irony-c-headers]]*
+ [[https://github.com/Andersbakken/rtags][rtags]]*
+ [[https://github.com/Andersbakken/rtags][ivy-rtags]] or [[https://github.com/Andersbakken/rtags][helm-rtags]]*
* Prerequisites
This module requires
+ irony-server (if ~+irony~ is enabled)
+ rtags (if ~+rtags~ is enabled)
2017-12-27 00:32:11 -05:00
** irony-server
Irony powers the code completion, eldoc and syntax checking systems.
2019-01-05 19:46:14 -05:00
After installing its dependencies, run ~M-x irony-install-server~ in Emacs.
2017-12-27 00:32:11 -05:00
*** MacOS
2017-05-25 20:08:50 +02:00
Due to linking issues, MacOS users must compile irony-server manually:
2019-01-05 19:46:14 -05:00
#+BEGIN_SRC sh
brew install cmake
2017-05-25 20:08:50 +02:00
brew install llvm # 1gb+ installation! May take a while!
git clone https://github.com/Sarcasm/irony-mode irony-mode
mkdir irony-mode/server/build
pushd irony-mode/server/build
DEST="$HOME/.emacs.d/.local/$(hostname)/etc/irony-server/"
cmake -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON \
-DCMAKE_INSTALL_PREFIX="$DEST" ../
cmake --build . --use-stderr --config Release --target install
install_name_tool -change @rpath/libclang.dylib \
/usr/local/opt/llvm/lib/libclang.dylib \
"$DEST/bin/irony-server"
# cleanup
popd
rm -rf irony-mode
#+END_SRC
2017-12-27 00:32:11 -05:00
*** Arch Linux
2019-01-05 19:46:14 -05:00
#+BEGIN_SRC sh
pacman -S clang cmake
#+END_SRC
2017-05-25 20:08:50 +02:00
2017-12-27 00:32:11 -05:00
** rtags
2019-01-05 19:46:14 -05:00
Code navigation requires an [[https://github.com/Andersbakken/rtags][rtags]] server (~rdm~) installed. This should be
available through your OS's package manager.
2017-12-27 00:32:11 -05:00
This module will auto-start ~rdm~ when you open C/C++ buffers (so long as one
2019-01-05 19:46:14 -05:00
isn't already running). If you prefer to run it yourself:
2017-12-27 00:32:11 -05:00
#+BEGIN_SRC sh
rdm &
rc -J $PROJECT_ROOT # loads PROJECT_ROOT's compile_commands.json
#+END_SRC
* Configure
2019-01-05 19:46:14 -05:00
** Project compile settings
2017-12-27 00:32:11 -05:00
By default, a set of default compile settings are defined in
~+cc-default-compiler-options~ for C, C++ and Objective C. Irony, rtags and
flycheck will fall back to these.
2017-12-27 00:32:11 -05:00
To make these tools aware of project specific build settings, you need a JSON
[[https://sarcasm.github.io/notes/dev/compilation-database.html#ninja][compilation database]] present (i.e. a ~compile_commands.json~ file).
2019-01-05 19:46:14 -05:00
There are [[https://sarcasm.github.io/notes/dev/compilation-database.html][many ways to generate one]]. I use [[http://www.cmake.org/][CMake]] or [[https://github.com/rizsotto/Bear][bear]]:
2017-12-27 00:32:11 -05:00
#+BEGIN_SRC sh
# For CMake projects
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .
# For non-CMake projects
make clean
bear make
#+END_SRC
Use ~M-x +cc/reload-compile-db~ to reload your compile db in an already-open
C/C++/ObjC buffer.