Generate compilation database (compile_commands.json)
Clangd-based code-completion engines require a compile_commands.json
file to be in the root of the project. With CMake we can easily
generate this file with the CMAKE_EXPORT_COMPILE_COMMANDS directive:
https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html
Tested with vim and YCM (https://github.com/ycm-core/YouCompleteMe), and the code navigation, refactoring, and autocompletion works a treat once the compile_commands.json file is in place.
Sample usage with vim+YCM (vscode and many other tools will work similarly):
$ mkdir build $ cd build && cmake ../ && make -j$(nproc) && cd .. $ mv build/compile_commands.json . $ vim src/krenamewindow.cpp # enjoy code completion at this point