Generating compile commands with cmake


cmake offers the option to generate a compilation database in json format using the option CMAKE_EXPORT_COMPILE_COMMANDS=YES. The database holds essentially the command, paths and compilers flags used to compile each file of a project. The generated file (usually called compile_commands.json) can be used in conjunction with various code completion tools like YouCompleteMe and Visual Studio’s IntelliSense in order to offer more complete information, completion and errors about the code.