CMake compile_commands.json and add_custom_command generated header interoperability
0 reputation · 13 Mar 2021, 21:14 UTC
Goal
Clarify the interoperability boundary between CMake's compile_commands.json export and sources generated by add_custom_command that are later included by compiled targets.
When CMAKE_EXPORT_COMPILE_COMMANDS is enabled, CMake writes compiler invocations for target sources at configure time. Entries for add_custom_command or add_custom_target are not emitted, even when their outputs become generated headers consumed by normal sources. Because the compilation database schema lacks a standard field for generated-file provenance, language servers cannot resolve symbols from those headers until after a build runs.
This leaves an unresolved design boundary: whether the JSON contract should cover generated outputs or leave build-graph inference to external tools. Assume CMake 3.x behavior with the Ninja or Unix Makefiles generator.
- Does CMake intend compile_commands.json to represent compiler invocations for files produced by add_custom_command?
- Should language servers treat missing generated-header entries as a CMake configuration gap or as external tooling responsibility?
- Is a prior build required before compile_commands.json can support symbol resolution for generated headers?