Unnecessary recompilation of out of tree sources


I have multiple projects, where each project needs some common files. Before, those files have been in each project separately.
After changing these files to a common location outside of each project, ninja keeps recompiling the common files, although they haven’t been changed, which can take up to 10 minutes.
Is this a problem with ninja, when using sources outside of the source directory? How can I structure the project to avoid the recompilation? The projects are all compiled separately and should be kept separate.

Thanks in advance!

When debugging ninja builds, ninja -d explain can have it tell you why it thinks it needs to recompile things. I suggest using it to see why it is recompiling it. I suspect it has to do with inaccurate timestamps, but can’t be sure.

It says output path/to/file.c of phony edge with no inputs doesn't exist.

That means (I think) that there’s a custom command declaring that it writes path/to/file.c but doesn’t actually do so. Or there’s more output that’s relevant here.

It is a rather large project and I don’t have the overview of every custom command or other outputs. I’m also not really familiar with ninja and its syntax. I guess having source files outside of the source directory is a really uncommon usecase, so it just isn’t supported?

Having sources outside the source tree isn’t uncommon (basically any code generator will do so). I suspect it is more that the output paths and dependencies of things aren’t matching enough for CMake to be able to detect an actual dependency link, so it depends on what the actual logic around the add_custom_command calls are doing.

I can’t find an add_custom_command. Would it help to upload the cmake file?

cmake --trace-expand will output (very) verbose logging of every command CMake runs. You can search its output to figure out where to look in the sources.

Okay, I will try this, thanks.