# Automoc always runs moc

**URL:** https://discourse.cmake.org/t/automoc-always-runs-moc/11660
**Category:** Usage
**Created:** [September 12, 2024, 1:39pm UTC](https://discourse.cmake.org/t/automoc-always-runs-moc/11660 "2024-09-12T13:39:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Andreas](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@Andreas](https://discourse.cmake.org/u/Andreas)
#### Post date: [September 12, 2024, 1:39pm UTC](https://discourse.cmake.org/t/automoc-always-runs-moc/11660/1 "2024-09-12T13:39:19Z")

</div>

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](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](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.

---

<div class="post-metadata">

### Author: ![Andreas](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/ee7513/32.png) [@Andreas](https://discourse.cmake.org/u/Andreas)
#### Post date: [September 19, 2024, 2:42pm UTC](https://discourse.cmake.org/t/automoc-always-runs-moc/11660/2 "2024-09-19T14:42:19Z")

</div>

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

---

<div class="post-metadata">

### Author: ![rschaub](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/9fc348/32.png) [@rschaub](https://discourse.cmake.org/u/rschaub)
#### Post date: [April 16, 2025, 3:05pm UTC](https://discourse.cmake.org/t/automoc-always-runs-moc/11660/3 "2025-04-16T15:05:28Z")

</div>

I have the exact same issue when switching from Qt5.9 to Qt6.5. CMAKE\_AUTOGEN\_VERBOSE didn’t really shed any light on the issue other than that the deps file gets changed, over which I have no influence.

What was the solution to your issues?
