Remix.run Logo
starkrights 2 months ago

Is there a ‘right’ (or simple/direct) way to generate this using various buildchains? I remember setting this up so I could use Sublime with intellisense a while ago, and finding that I could only get it to generate with a specific compiler chain on windows (ninja I think?)

Minor annoyance to have to make my c make project generate buildchain files for a compiler I’m not using & copy that file into my project root to commit it- unrelated to the original question, but also annoying that I have to manually generate it every time I make significant codebase changes.

TuxSH 2 months ago | parent [-]

> and finding that I could only get it to generate with a specific compiler chain on windows (ninja I think?)

Yes, you're right about that.

Basically, it boils down to "use CMake with Ninja/Makefile" (even if you don't strictly have to, you could write a script that creates the json yourself, for example). When cross-compiling, you may also have to whitelist compiler paths.

Add -DCMAKE_EXPORT_COMPILE_COMMANDS=ON as command-line arg during the config step, or add the equivalent "set" call to your CMakeLists.txt, restart clangd (ctrl+p, restart clangd), and you're good to go.

There are minor annoyances when cross-compiling (it using clang -- some compile options are incompatible and need to be removed in global user config, and it not extracting default compiler defines from compilers) but they are very easily worked around

I more or less use this as config: https://gist.github.com/TuxSH/0220d1235dace77f82738c96718011...