MantisBT - CMake
View Issue Details
0014159CMakeCMakepublic2013-05-21 11:302014-06-02 08:37
Janne Rönkkö 
Stephen Kelly 
normalminoralways
closedfixed 
LinuxArchlinux
CMake 2.8.10.2 
CMake 2.8.11 
0014159: qt4_wrap_cpp Creates Incorrect Dependencies When Ninja Generator Is Used
When using Ninja as generator qt4_wrap_cpp function generates incorrect dependencies causing all the wrapped source files to be rebuilt when any of the source is changed.

Due to extra dependencies the build with Ninja is much slower than it should be.
Extract the example.tar to get example project and in the build directory run
cmake .. -G Ninja
ninja -v
touch ../A.hpp
ninja -v

Also B.cpp and B_moc.cxx are build even though those files do not depend on A.hpp.
With GNUMake B.cpp and B_moc.cxx is not recompiled after modifying (touching) A.hpp:

.../cmake-qt-moc-bug/build $ cmake .. -G 'Unix Makefiles'
-- The C compiler identification is GNU 4.8.0
-- The CXX compiler identification is GNU 4.8.0
# ... snip ...
-- Found Qt4: /usr/bin/qmake-qt4 (found version "4.8.4")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/janne/tmp/cmake-qt-moc-bug/build
.../cmake-qt-moc-bug/build $ make
[ 16%] Generating moc_B.cxx
[ 33%] Generating moc_A.cxx
Scanning dependencies of target mylib
[ 50%] Building CXX object CMakeFiles/mylib.dir/A.cpp.o
[ 66%] Building CXX object CMakeFiles/mylib.dir/B.cpp.o
[ 83%] Building CXX object CMakeFiles/mylib.dir/moc_A.cxx.o
[100%] Building CXX object CMakeFiles/mylib.dir/moc_B.cxx.o
Linking CXX static library libmylib.a
[100%] Built target mylib
.../cmake-qt-moc-bug/build $ touch ../A.hpp
.../cmake-qt-moc-bug/build $ make
[ 16%] Generating moc_A.cxx
Scanning dependencies of target mylib
[ 33%] Building CXX object CMakeFiles/mylib.dir/A.cpp.o
[ 50%] Building CXX object CMakeFiles/mylib.dir/moc_A.cxx.o
Linking CXX static library libmylib.a
[100%] Built target mylib


But with Ninja also B.cpp and B_moc.cpp are rebuilt:

janne@kafir ~/tmp/cmake-qt-moc-bug/build $ cmake .. -G Ninja
-- The C compiler identification is GNU 4.8.0
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- works
# ... snip ...
-- Found Qt4: /usr/bin/qmake-qt4 (found version "4.8.4")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/janne/tmp/cmake-qt-moc-bug/build
.../cmake-qt-moc-bug/build $ ninja -v
[1/7] cd /home/janne/tmp/cmake-qt-moc-bug/build && /usr/lib/qt4/bin/moc -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -o /home/janne/tmp/cmake-qt-moc-bug/build/moc_B.cxx /home/janne/tmp/cmake-qt-moc-bug/B.hpp
[2/7] cd /home/janne/tmp/cmake-qt-moc-bug/build && /usr/lib/qt4/bin/moc -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -o /home/janne/tmp/cmake-qt-moc-bug/build/moc_A.cxx /home/janne/tmp/cmake-qt-moc-bug/A.hpp
[3/7] /usr/lib/colorgcc/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -MMD -MT CMakeFiles/mylib.dir/A.cpp.o -MF "CMakeFiles/mylib.dir/A.cpp.o.d" -o CMakeFiles/mylib.dir/A.cpp.o -c ../A.cpp
[4/7] /usr/lib/colorgcc/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -MMD -MT CMakeFiles/mylib.dir/B.cpp.o -MF "CMakeFiles/mylib.dir/B.cpp.o.d" -o CMakeFiles/mylib.dir/B.cpp.o -c ../B.cpp
[5/7] /usr/lib/colorgcc/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -MMD -MT CMakeFiles/mylib.dir/moc_A.cxx.o -MF "CMakeFiles/mylib.dir/moc_A.cxx.o.d" -o CMakeFiles/mylib.dir/moc_A.cxx.o -c moc_A.cxx
[6/7] /usr/lib/colorgcc/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -MMD -MT CMakeFiles/mylib.dir/moc_B.cxx.o -MF "CMakeFiles/mylib.dir/moc_B.cxx.o.d" -o CMakeFiles/mylib.dir/moc_B.cxx.o -c moc_B.cxx
[7/7] : && /usr/bin/cmake -E remove libmylib.a && /usr/bin/ar cr libmylib.a CMakeFiles/mylib.dir/A.cpp.o CMakeFiles/mylib.dir/B.cpp.o CMakeFiles/mylib.dir/moc_A.cxx.o CMakeFiles/mylib.dir/moc_B.cxx.o && /usr/bin/ranlib libmylib.a && :

.../cmake-qt-moc-bug/build $ touch ../A.hpp
.../cmake-qt-moc-bug/build $ ninja -v
[1/6] cd /home/janne/tmp/cmake-qt-moc-bug/build && /usr/lib/qt4/bin/moc -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -o /home/janne/tmp/cmake-qt-moc-bug/build/moc_A.cxx /home/janne/tmp/cmake-qt-moc-bug/A.hpp
[2/6] /usr/lib/colorgcc/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -MMD -MT CMakeFiles/mylib.dir/A.cpp.o -MF "CMakeFiles/mylib.dir/A.cpp.o.d" -o CMakeFiles/mylib.dir/A.cpp.o -c ../A.cpp
[3/6] /usr/lib/colorgcc/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -MMD -MT CMakeFiles/mylib.dir/B.cpp.o -MF "CMakeFiles/mylib.dir/B.cpp.o.d" -o CMakeFiles/mylib.dir/B.cpp.o -c ../B.cpp
[4/6] /usr/lib/colorgcc/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -MMD -MT CMakeFiles/mylib.dir/moc_A.cxx.o -MF "CMakeFiles/mylib.dir/moc_A.cxx.o.d" -o CMakeFiles/mylib.dir/moc_A.cxx.o -c moc_A.cxx
[5/6] /usr/lib/colorgcc/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -MMD -MT CMakeFiles/mylib.dir/moc_B.cxx.o -MF "CMakeFiles/mylib.dir/moc_B.cxx.o.d" -o CMakeFiles/mylib.dir/moc_B.cxx.o -c moc_B.cxx
[6/6] : && /usr/bin/cmake -E remove libmylib.a && /usr/bin/ar cr libmylib.a CMakeFiles/mylib.dir/A.cpp.o CMakeFiles/mylib.dir/B.cpp.o CMakeFiles/mylib.dir/moc_A.cxx.o CMakeFiles/mylib.dir/moc_B.cxx.o && /usr/bin/ranlib libmylib.a && :
No tags attached.
tar example.tar (10,240) 2013-05-21 11:30
https://public.kitware.com/Bug/file/4764/example.tar
Issue History
2013-05-21 11:30Janne RönkköNew Issue
2013-05-21 11:30Janne RönkköFile Added: example.tar
2013-05-23 01:44Janne RönkköNote Added: 0033118
2013-11-02 09:25Stephen KellyStatusnew => resolved
2013-11-02 09:25Stephen KellyFixed in Version => CMake 2.8.11
2013-11-02 09:25Stephen KellyResolutionopen => fixed
2013-11-02 09:25Stephen KellyAssigned To => Stephen Kelly
2014-06-02 08:37Robert MaynardNote Added: 0035982
2014-06-02 08:37Robert MaynardStatusresolved => closed

Notes
(0033118)
Janne Rönkkö   
2013-05-23 01:44   
Seems to be working in 2.8.11
(0035982)
Robert Maynard   
2014-06-02 08:37   
Closing resolved issues that have not been updated in more than 4 months.