CMake not generating compile_commands.json CMake not generating compile_commands.json json json

CMake not generating compile_commands.json


This ended up being an issue with using an old version of CMake. I ended up installing the newest version and it worked as expected.

According to Clang docs

"Currently CMake (since 2.8.5) supports generation of compilation databases for Unix Makefile builds (Ninja builds in the works) with the option CMAKE_EXPORT_COMPILE_COMMANDS."


I had the same problem, compile_commands.json was not generated with cmake, version 3.16.0.It was generated when I used the Ninja generator, but not Unix Makefiles.

That discussion gave me the fix:

set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # does not produce the json fileset(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") # works


I also encountered the same problem as you.According to CMake doc

This option (CMAKE_EXPORT_COMPILE_COMMANDS) is implemented only by Makefile Generators and the Ninja. It is ignored on other generators.

Thus, there is no solution to generate compile_commands.json file when using MSVC.