Skip to content

automoc: Remove existing output file before invoking moc

Jason Haslam requested to merge jason3/cmake:automoc-case-change into master

Remove the output file before invoking moc in case the case of source file has changed on disk. Recent versions of clang warn when the case of the include directive (which does change) doesn't match the case of the file on disk.

For example, for a file called test.h changed to Test.h, clang warns:

.../test/build/test_autogen/mocs_compilation.cpp:2:10: warning: non-portable path to file '"EWIEGA46WW/moc_test.cpp"'; specified path differs in case from file name on disk [-Wnonportable-include-path]
#include "EWIEGA46WW/moc_Test.cpp"
         ^~~~~~~~~~~~~~~~~~~~~~~~~
         "EWIEGA46WW/moc_test.cpp"
1 warning generated.

The moc doesn't change the case of the file when it overwrites it. This is especially annoying for -Werror builds. The manual fix is to remove the generated moc file with the wrong case and then touch the input file.

Merge request reports