ninja automoc rules not updated after moving source files
To reproduce, try the following attached project:
First, unpack it and then checkout the root commit and build the project with ninja:
tar -xvf cmake-automoc-bug.tar.bz2
cd cmake-automoc-bug
git checkout HEAD^
mkdir build
cd build
cmake -GNinja ..
ninja
Then checkout master again to move the myclass.*
files from foo
to bar
and try to build the project again:
git checkout master
ninja
For me with Qt 5.15 and CMake 3.18.2 and ninja 1.10.1 I reproducibly get this unexpected compile error:
[0/1] Re-running CMake...
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/cmake-automoc-bug/build
[4/5] Building CXX object bar/CMakeFiles/bar.dir/myclass.cpp.o
FAILED: bar/CMakeFiles/bar.dir/myclass.cpp.o
/home/milian/.bin/g++ -DQT_CORE_LIB -DQT_NO_DEBUG -Ibar -I../bar -Ibar/bar_autogen/include -isystem /usr/include/qt -isystem /usr/include/qt/QtCore -isystem /usr/lib/qt/mkspecs/linux-g++ -fPIC -MD -MT bar/CMakeFiles/bar.dir/myclass.cpp.o -MF bar/CMakeFiles/bar.dir/myclass.cpp.o.d -o bar/CMakeFiles/bar.dir/myclass.cpp.o -c ../bar/myclass.cpp
../bar/myclass.cpp:21:10: fatal error: myclass.moc: No such file or directory
21 | #include "myclass.moc"
| ^~~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
The only way to workaround this problem seems to be this (in the build dir):
rm -Rf bar
cmake .
ninja
But obviously this isn't ideal at all - can this be improved please?