FILE(REMOVE) and FILE(APPEND) don't resolve relative filenames the same way

David Faure faure at kde.org
Fri Mar 6 17:21:24 CET 2009


On Friday 06 March 2009, Brad King wrote:
> David Faure wrote:
> > => Before QT4_CREATE_MOC_COMMAND calls 
> > FILE(REMOVE ${_moc_parameters_file}), could you make it check that
> > ${_moc_parameters_file} is an absolute path and not a relative one,
> > since that's bound to fail and give unexpected results?
> 
> Please file a feature request in the bug tracker.

OK.

> > (And the reason for all this: there doesn't seem to be a way to generate
> > a foo.moc when foo.cpp defines a Q_OBJECT itself (rather than the header file)
> > and foo.cpp includes foo.moc. Well, kde4automoc handles this, but I'm abusing
> > this list to ask questions about a qt-only project ;) ). So I wrote this macro
> > macro(macro_included_moc cppfile)
> >   GET_FILENAME_COMPONENT(_basename ${cppfile} NAME_WE)
> >   SET(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc)
> >   qt4_generate_moc(${cppfile} ${_moc})
> >   macro_add_file_dependencies(${cppfile} ${_moc})
> > endmacro(macro_included_moc)
> > 
> > Alternative solution: including kde4automoc into cmake. I know we discussed
> > it in the past and it was rejected, but this is another argument for it.
> > My boss wouldn't let me add it as dependency, he wanted an
> > "off-the-shelf cmake" solution: importing kde4automoc and integrating it
> > into the compilation properly sounded like a bit too much trouble 
> > for a single cpp file that defined a Q_OBJECT...)
> 
> If every Qt project needs something like this, wouldn't it make more sense for
> Qt itself to provide an executables with the capabilities of kde4automoc?

Why would Qt do that? They still use and provide QMake (which includes this
functionality), they don't have much interest in cmake, unfortunately...

On the other hand, cmake provides a FindQt4.cmake and QT_WRAP_CPP,
but it looks like a half solution. It only handles one case (separate .moc
for a .h), not the other 3 cases:
C2 - separate moc file for a .cpp,
C3 - #included moc file for a .h, and 
C4 - #included moc file for a .cpp.

My macro above is for C4.
C3 even has variants: qmake names it moc_foo.cpp
while kde names it foo.moc; iirc kde4automoc supports both.
In case of foo.moc this is half solved by FindQt4.cmake too, using the 
confusingly-named QT4_AUTOMOC, marked as experimental though;
but in case of moc_foo.cpp (e.g. code imported from qmake) it doesn't work.

Manual calls to qt4_generate_moc can be used for those 3 unhandled cases,
but only with enough cmake experience to be able to write a macro
like the above without bugs... I guess most people don't even write a macro
but just qt4_generate_moc (+macro_add_file_dependencies
if the moc file is #included), and if they forget ${CMAKE_CURRENT_BINARY_DIR},
they end up with "moc: too many input files"... I bet
http://www.qtforum.org/article/23393/qt-and-cmake-moc-too-many-input-files.html
was an example of it.

-- 
David Faure, faure at kde.org, sponsored by Qt Software @ Nokia to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).


More information about the Kde-buildsystem mailing list