Automoc always runs moc

I would expect automoc to only run moc if the input files have changed.

In the documentation https://cmake.org/cmake/help/latest/prop_tgt/AUTOMOC.html it says “The header will be moc compiled again if a file from the additional file dependencies changes.”

This is currently not working for us. When i build the target, it runs moc on every one of the 210 files. Even if nothing changes this triggers a rebuild of all the .cpp files that include a moc file.

This is on Windows, Visual Studio 17 2022.

The dependencies of the _autogen.rule file look wrong to me. The description reads “Automatic MOC for target …” My understanding is that this rule file is responsible for running moc. In addition to running moc, there are additional files generated by this target. All these files are added as dependencies to the _autogen.rule file.
But even if I remove these dependencies manually, cmake -E cmake_autogen still always runs moc for all files.

We have set the CMAKE_AUTOMOC_EXECUTABLE to make sure that CMake uses the correct moc executable. But I would not expect this to have any effect on the dependency checks.

How would I debug this? The cmake_autogen command is apparently not documented https://cmake.org/cmake/help/latest/manual/cmake.1.html#run-a-command-line-tool. I tried --trace, whatever that does, but neither cmake --trace -E cmake_autogen... nor cmake -E cmake_autogen --trace ... works.

I figured out the issue thanks to CMAKE_AUTOGEN_VERBOSE. It’s a great tool to see what’s going on with automoc.