[CMake] [PATCH] FindQt4.cmake qt4_automoc improvements

Tanguy Krotoff tkrotoff at gmail.com
Mon May 19 21:07:50 EDT 2008


> UseQt4.cmake in CVS has been recently patched to reduce the number of include
> directories specified in certain cases.

I don't want to reduce them, I want to get rid of them...

> Hope that solves your problem.

There is no problem, and if there is one it is definitly not specific to me.


Let me explain again :)

Remember the good old time:
Qt previous to version 4 was just a huge lib, there was only one
include directory with everything inside.
Writing Qt-3 #include code looked like this:
#include <qmainwindow.h>
#include <qstring.h>

Qt-4 has been splitted into several libraries: QtCore, QtGui... so
there are one include directory for each module.
Writing Qt #include code now looks like:
#include <QMainWindow>
#include <QString>
or
#include <QtGui/QMainWindow>
#include <QtCore/QString>


Writing #include <QMainWindow>, #include <QString>... leads to have an
include path -I/usr/lib/qt4/include/QtGui -I/usr/lib/qt4/QtCore up to
18! (and obviously more modules will come over time)

Another solution is to write #include <QtGui/QMainWindow>, #include
<QtCore/QString>...
This may you need one and only one include path: -I/usr/lib/qt4/include/

What are the advantages of the latter solution?
Well, as I said before:

- Reduced compilation time, this is obvious as you have a smaller include path

- Cleaner/smaller make compilation line
Never got a problem because of a stupid -DBLABLA left somewhere?
Now it is easier to find as you don't get a make line that takes all
your terminal
Your make line is again readable, so less pain

Why Trolltech kept the possibility to write #include <QMainWindow>?
for "compatibility" reasons I guess, old habits...
KDE doesn't have to necessary follow the same path as QMake

Writing #include <QtGui/QMainWindow> instead of #include <QMainWindow>
keeps the code compatible and I personally find it cleaner: I can see
from where my includes come from and it helps me organizing them
cleanly: #include <QtCore/...> first, then QtGui, then QtNetwork...

To summarize I think it is a cleaner/better solution for free.

A good transition for UseQt4.cmake would be a simple variable:

if (QT_INCLUDE_DIRS_ON)
   INCLUDE_DIRECTORIES(${QT_${module}_INCLUDE_DIR})
endif (QT_INCLUDE_DIRS_ON)

What about "my" problem? I've just added a small macro that remove all
the useless include dirs without touching UseQt4.cmake:
http://code.google.com/p/phonon-vlc-mplayer/source/browse/trunk/cmake/ReduceQtIncludeDirs.cmake

What do you think about it?

-- 
Tanguy Krotoff <tkrotoff at gmail.com>
+33 6 68 42 70 24


More information about the CMake mailing list