compile_commands.json is not created when no commands exist

currently, CMake does not create the file compile_commands.json if the project has no compile commands:

cmake_minimum_required( VERSION 3.17.0 )
project(ExportCompileCommands)
# workaround for CMake 3.17.0
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")

as a first time user of this feature I did not expect this.

If CMAKE_EXPORT_COMPILE_COMMANDS is enabled and no commands exist I suggest that compile_commands.json should still be generated. For both human and machine processing the expected file content should be

[
]
2 Likes

Yes, that should be fixed. See CMake Issue 19758.

2 Likes