A simple shell script for generating compile_commands.json files for clangd and other C++ LSP servers for R packages using C code.
NOTE: This currently only works with the clang compiler (>5.1).
You will need a different solution for gcc and other compilers.
Download the rcpp-compdb script into a location on your $PATH.
rcpp-cmpdb <path>
<path> defaults to the current R package directory.
- Copy
Makevarsto a temporary file. - Add a line like
PKG_CPPFLAGS += -MJ <tempdir>/$@.jsonto haveclangcreate individual compilation databases for each target as part of the R package build. - Build the R package in a temporary folder. While compiling, it will generate compilation databases for every C++ file.
- Combine all the individual compilation database files into a single file:
<path>/src/compilation_commands.json - Remove all temporary directories, and restore the original
Makevarsfile.