CMAKE_AUTOMOC_MACRO_NAMES: Leads to problems when both header and implementation use macros requiring moc to be run on the file(s)
CMake 3.10.0 (or master) causes build failures in case one uses CMAKE_AUTOMOC_MACRO_NAMES
.
If I understand correctly, then CMAKE_AUTOMOC_MACRO_NAMES
should never cause this.
% ~/opt/cmake-master/bin/cmake --version
cmake version 3.10.20171024-g48c713
CMake suite maintained and supported by Kitware (kitware.com/cmake).
See attached minimal working example: test_cmakemacronames_bug.tar.gz
If using CMake without setting CMAKE_AUTOMOC_MACRO_NAMES
:
% ~/opt/cmake-master/bin/cmake -G Ninja .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kfunk/tmp/test_cmakemacronames_bug
% ninja clean
[1/1] Cleaning all built files...
Cleaning... 5 files.
% ninja
[1/5] Automatic MOC for target helloworld
AutoMoc warning:
"/home/kfunk/tmp/test_cmakemacronames_bug/mainwindow.cpp"
The file includes the moc file "mainwindow.moc", but does not contain a Q_OBJECT, Q_GADGET or Q_NAMESPACE macro.
[5/5] Linking CXX executable helloworld
[kfunk@kerberos ~/tmp/test_cmakemacronames_bug 184K]%
=> Produces the "does not contain a Q_OBJECT, ..." warning. Wrong in that case, but fair enough -- this is what #17176 (closed) is about.
CMAKE_AUTOMOC_MACRO_NAMES
is supposed to fix this, so let's set it:
% ~/opt/cmake-master/bin/cmake -G Ninja -DSET_CMAKE_AUTOMOC_MACRO_NAMES=1 .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kfunk/tmp/test_cmakemacronames_bug
% ninja
[3/3] Linking CXX executable helloworld
FAILED: helloworld
: && /usr/lib/ccache/c++ -rdynamic CMakeFiles/helloworld.dir/mainwindow.cpp.o CMakeFiles/helloworld.dir/main.cpp.o CMakeFiles/helloworld.dir/helloworld_autogen/mocs_compilation.cpp.o -o helloworld /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.9.1 /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.1 /usr/lib/x86_64-linux-gnu/libQt5Core.so.5.9.1 && :
CMakeFiles/helloworld.dir/mainwindow.cpp.o: In function `MainWindow::MainWindow(QWidget*)':
mainwindow.cpp:(.text+0x50): undefined reference to `vtable for MainWindow'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Problem (if I understand correctly is):
CMake with CMAKE_AUTOMOC_MACRO_NAMES
being set no longer includes moc_mainwindow.cpp in mocs_compilation.cpp.