Nova/C-Dragon: better clangd compiler flag integration for intellisense/warnings?

I'm working on a Playdate Lua wrapper for the (C-based) Chipmunk2D physics library. After spending most of my time fighting cmake and the build environment on Windows I switched over to Nova on Mac, and now building has become remarkably painless.

However, the C language server (C-Dragon/clangd) doesn't get visibility into the compiler flags that are produced by make using C_API/buildsupport/ I was able to set things right by manually transcribing the gcc flags from the build log to .clangd as follows:

		- "-g"
		- "-c"
		- "-mthumb"
		- "-mcpu=cortex-m7"
		- "-I/Users/alex/Developer/PlaydateSDK/C_API"
		- "-I/Users/alex/Documents/GitHub/playdate-chipmunk-lib"
		- "-I/Users/alex/Documents/GitHub/playdate-chipmunk-lib/chipdx"
		- "-I/Users/alex/Documents/GitHub/playdate-chipmunk-lib/chipmunk/include"
		- "-I/Users/alex/Documents/GitHub/playdate-chipmunk-lib/chipmunk/include/chipmunk"

This is a pain though and needs to be updated by hand alongside the makefile, and seems to only take explicit, literal paths. Best practices for clangd seem to be to use cmake and add the following to CMakeLists.txt:


Which will produce a compiler_commands.json file that clangd can read. Whenever you build, that file gets updated.

Any makefile experts (couldn't be me) have an idea how to coax make to achieve a similar thing? Or have some other way to get clangd/C-Dragon able to actually read your Playdate C projects?

To my knowledge there isn't a way to get make to export a compiler_commands.json file automatically. What's wrong with using CMake and set(CMAKE_EXPORT_COMPILE_COMMANDS ON)?

That was the first part of the post -- I found I was not smart enough to understand CMake's documentation (and the Playdate C API docs) well enough to get reliable builds on the command line. Nova's shiny Playdate build integration worked first time, every time, but it's built around Make and not CMake.

Sure, if the Just Works parts of Nova+Playdate don't just work in depth (which is what it's starting to look like) I'm still within the refund window and I can pursue getting more expert with CMake and VS Code to have a more painless build process there, but other pieces of my current project are awkward and irritating enough I was hoping to avoid that.

CMake, by default, simply generates a make file. At that point, you can use the Nova build system. If you add files to your project, you need to update the CMake file and regenerate the make file by running cmake again. So for our example apps, it's as simple as changing in to the project dir in the terminal and running:

cmake .

That will generate a new make file at the root of the project which the Nova task will see and use but have the upside of also generating you a compiler_commands.json file automatically.

Thanks - that clarifies things a bit; I was only messing with CMake previously because my Windows machine is a bit more generously appointed and (understandably) the Windows C API build only works with CMake. The simple provided CMakeLists.txt work great on Windows and Mac/Linux for the samples, but Chipmunk2D drags the build process into the weeds, especially on Windows.

I was able to work out generally what needs to happen, but between the nature of the documentation on, the gnarl that occurs when you actually try to support cross-platform building, and the opacity of the outputs that CMake spits out, I felt like I was following a vision that I could not subscribe to. CMake feels like a prayer for simplicity and elegance that just doesn't quite survive in the real world, and I felt like I'd be spending all my time fighting that. Makefiles may not be portable, and they can get hideous (ask me about my first assignment at Microsoft sometime), but I find them a bit easier to muddle through.