not able to generate compile_commands.json on cmake 3.22.1

(I’m fairly new to cmake) I’ve tried turning on this setting a few different ways, and from reading some Stackoverflow posts it seems like this was mostly an issue in older cmake versions.

I’ve tried:

  • cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1
  • export CMAKE_EXPORT_COMPILE_COMMANDS=1
  • set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  • set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL “”)

But none of those settings cause cmake to produce the file. I’m trying to get the file generated so I can use clangd. I’ve also tried running clean and then re-run cmake but it still does not create the file.

Issue resolved: I removed the other settings, deleted the build directory, and just used cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1. Not quite sure what the root issue was.