CMAKE_OPTIMIZE_DEPENDENCIES increases the number of deps for a target

I am trying out CMAKE_OPTIMIZE_DEPENDENCIES.

I did an experiment where I configured twice, once with COD=0, and again with COD=1. Then I wrote a little tool in Python that parsed the cmake-file-api reply for the codemodel, and went through every target and printed out the list of dependencies, as reported in the “dependencies” object of the target-xxx.json file.

When I do this, there are some targets where the dependency count increases with COD=1. I’ve read the documentation and I don’t see how this is possible. The documentation says that COD first removes all dependencies, and then only adds them back if certain conditions are met. This reads to me as though the number of direct + indirect dependencies must necessarily be less with COD=1 than it is with COD=0.

The only thing I’m not sure about is whether the dependencies reported in the file-api reply includes both direct + indirect, and the file-api documentation doesn’t make this clear either. If it reports direct+indirect, then I think this is a bug in the implementation of COD. If it only reports direct, then the behavior is probably correct.

Any advice appreciated.

Please post a minimum reproducible example which causes the number of dependencies to increase.

Do you have any suggestions about how to minimize my repro? This is a pretty large application with a few thousand targets, and the problem only happens on some of them. It’s closed source, so I can’t just link to the repository and tell you the configure steps either.

You can strip out those that don’t change first. Once you have that minimized, replacing sources and such with dummy files would be the next thing I’d do.

I think cod may increase the number of dependencies if the build system has cycles and missing dependencies.