Generate Build Database is Empty

I am attempting to experiment with the experimental CMAKE_EXPORT_BUILD_DATABASE flag. I think I got it up and running to the point where the cmake_build_database target is generating a build_database.json. However the sets list is empty. Is there something I am missing to make sure this database includes all of my targets?

Repro:

Dowload cmake 4.3.2

Install clang-22

mkdir build
cd build
cmake .. -G Ninja
cd ..
cmake --build build --target cmake_build_database app

@ben.boeckel

Hmm. The per-target databases are fine. The _CXX database’s `merge command has no inputs though. Something is getting lost in translation here…

Thanks for the report!

If you set a non-empty CMAKE_BUILD_TYPE, it shows up. I’ll look at what the problem is with empty configs…

MR filed: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/12101

Hi,

as a side question as it’s not clear for me from the documentation or naming:

What’s the difference between a compilation database and a build database?

A compilation database is “just” a list of JSON objects with:

  • output path (optional)
  • source path
  • working directory
  • command

There’s no high-level structure here. If a source path is compiled multiple times, what does one do? It could be in multiple targets or the build could be multi-config and have one rule per configuration.

When completing an import, one needs to know the target-level dependency to know what modules are eligible for completion. While there might exist a module M, offering to import it in a file which lives in a library that the M provider links to is invalid. The build database provides enough context to provide such assistance.

See my talk (which I need to pull back into the docs): https://www.youtube.com/watch?v=GUqs_CM7K_0

@ben.boeckel It would probably also help to contrast what the build database provides that is not already provided by the CMake file API. Right now, it seems like it is duplicating the same details, just in a different format (i.e. a single file).

One could probably get a build database from a file-api query. The main difference is that it is a CMake-agnostic file format. I really need to improve the docs based on my talk so I can stop pointing at it as the best source of information :slight_smile: .