[cmake-developers] Current deficiencies of automoc

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu Oct 20 19:29:39 EDT 2016

On 2016-10-20 15:08-0400 Brad King wrote:

> Please construct a minimal/complete example source tree/tarball
> that demonstrate the layout you'd like to have work.  That will
> be helpful in constructing such a bug report.

OK. I have attached the requested minimal example to serve as the
basis for further discussion.  The files in the tarball are


include/test_q_object.h is a header that contains a minimal use of
Q_OBJECT.  (Likely too minimal so I will need help with that see below.)
main.cpp is a "hello-world" example that #includes that header.  It also #includes
the moc-generated moc_test_q_object.cpp.

The USE_AUTOMOC option for this test project defaults to OFF.  In that
default case this test project is set up so that the qt5_wrap_cpp is called instead of using automoc, and the
result is the compilation works fine (all headers and files generated
by moc are found with no issues) but there is a link error

undefined reference to MyClass::~MyClass()'

which likely has to do with include/test_q_object.h being too minimal.
I would appreciate help with that issue to complete this example, but
that is a side issue and the principal result is the compile (as
opposed to the link) was a success with the default -DUSE_AUTOMOC=OFF.

However, if you try -DUSE_AUTOMOC=ON with this project the compile
step (before it even gets to the link step) fails as follows:

Automatic moc for target helloworld
/home/software/cmake/install-3.5.2/bin/cmake -E cmake_autogen /home/software/plplot/HEAD/test_qt5/build_dir/CMakeFiles/helloworld_automoc.dir/ ""
AUTOGEN: Checking /home/software/plplot/HEAD/test_qt5/main.cpp
AUTOGEN: error: /home/software/plplot/HEAD/test_qt5/main.cpp The file includes the moc file "moc_test_q_object.cpp", but could not find header "test_q_object{.h,.hh,.h++,.hm,.hpp,.hxx,.in,.txx}" in /home/software/plplot/HEAD/test_qt5/

I hope a simple solution to this deficiency of the current automoc can
be found using the following ideas (copied from my previous post to
keep this self-contained).


#include "moc_<name>.cpp"

is found in a source file under automoc
control, then if moc_<name>.cpp could not be found in any of the
include directories for the target, then search those include
directories (including source-tree equivalents of build-tree include
directories) for <name>.h, run moc on that file and place the result
moc_<name>.cpp in the build directory corresponding to <name.h>.

So the result is moc would be run just once on the correct header file
with the moc_<name>.cpp result stored in one logical location no
matter how many different source files in different directories have
code with the above #include.

Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).

Linux-powered Science
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_qt5.tar.gz
Type: application/x-gtar-compressed
Size: 1149 bytes
Desc: compressed tarball containing a minimal example of automoc compile failure
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20161020/ad187c2c/attachment.tgz>

More information about the cmake-developers mailing list