reddit / emacs

Emacs + project + eglot + cmake + clangd language serv

jjgarciaripoll · 2022-02-27 16:05
After some experimentation, I have finished a new [Emacs feature](https://github.com/juanjosegarciaripoll/project-cmake) for personal use that teaches Emacs' `project` and `eglot` packages how to understand a CMake project structure. It facilitates the following tasks: - Informing `clangd` about the project sources for better finding include files - Finding compilation toolkits for MSYS2 (Windows), Windows Subsystem for Linux and Unix variants (in progress) - Configuration of the project via cmake - Building (compiling) the project with highlighting of errors - Installing - Unit testing with `ctest` - Configuration of project-local flags, such as default kit and build flags. As usual, this is provided with no guarantees. It seems to be working on my Windows machine (with native Emacs, no WSL), but your mileage may vary. Feedback and pull requests welcome. Also help in integrating MSVC compilers and other toolkits.
jjgarciaripoll · 2022-02-28 22:11
BTW, I just added support to detect WSL (Windows Subsystem for Linux) distributions and use them to build and test the CMake project. It was not easy, because WSL uses a UTF-16LE encoding that blocked me for some time, but once you realize that is the source of so many weird characters, Emacs is very good at correcting it. In order to use this or other compilation kits, run `project-cmake-scan-kits` and set the variable `project-cmake-default-kit` to the right value. For instance, on my system I have WSL Debian distributions, and thus I set it to `wsl-debian` when I want to build Linux software and `msys2-ucrt64` when I want to compile native code.
lcvas · 2022-03-01 15:18
This is a constant gripe I get with eglot, though not just for clangd. I'd be very interested in a general solution, perhaps using a hack like projectile's `.projectile`
jjgarciaripoll · 2022-03-01 17:25
My experience is that eglot identifies properly the project. Indeed, it uses internally Emacs' project package. However, it does not pass information about the project to the language servers. project-cmake's approach is a workaround to complement Eglot's arguments with information that is specific to one language server, but can be extended to others without much difficulty. I have also added a module to project-cmake that defines [project-local variables](https://github.com/juanjosegarciaripoll/project-cmake/blob/main/project-local.el) which can help in doing a separate customisation for each project, also of the language servers themselves.