Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Feb 2007 21:59:59 +0100
From:      Michael Nottebrock <lofi@freebsd.org>
To:        kde@freebsd.org, ports@freebsd.org
Subject:   A few notes about the Qt4 ports for porters
Message-ID:  <200702052200.04240.lofi@freebsd.org>

next in thread | raw e-mail | index | archive | help
--nextPart1320163.x9YgR5HM2H
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

This is a rather verbose mail. Skip towards the end for some quick
explanations with hands-on examples.

There are two import differences between the qt4 ports and qt33: Qt4
lives in ${LOCALBASE} instead of ${X11BASE} and qt4 is not a single
monolithic port, but many individual ports and one (entirely
optional) metaport (devel/qt4). The metaport is provided mostly for the
benefit of developers and porters and should *not* be depended on by
other ports. It will pull in all other qt4 component ports except for
misc/qt4-qtdemo.


Makefile Variables/Switches
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D

To depend on qt4 or individual parts of qt4, porters need to specify

USE_QT_VER=3D4

in their port Makefiles. Specifying nothing but this switch will
trigger a dependency on the qt4 metaport. The switch enables an
additional variable:

QT_COMPONENTS

QT_COMPONENTS can be used to list Qt4 tool and library dependencies
in a specific and concise fashion. The complete list of
possible values of QT_COMPONENTS can be found in
${PORTSDIR}/Mk/bsd.kde.mk in the _QT_COMPONENTS_ALL variable.

The most important components for porters are:

The libraries:

corelib gui network opengl qt3support qtestlib sql xml

All libraries themselves depend on corelib, so unless the application
you are porting uses nothing but corelib, corelib doesn't need to be
explicitly specified. You can determine which libraries the
application depends on, by running
ldd </path/to/main-executable> | grep Qt
after a successful compilation.

The tools:

moc qmake rcc uic

You will almost certainly need to depend on moc regardless what type
of application you are porting. If the application in question uses a
GUI, uic will be needed, too. Dependence on rcc can be determined by
looking for *.rc or *.qrc files in the application's source code
directories.

Note that moc and uic are installed as "moc4" and "uic4" in order to
not conflict with qt33. qmake is installed as "qmake-qt4"
in order to not conflict with Qt3's qmake. Applications that use qmake
as a buildsystem or query qmake for Qt's configuration will figure
this out automatically, other buildsystems might require additional
environment variables, configure switches or even patches in order to
work.

The plugins:

iconengines imageformats

You should specify imageformats if your application ships image files
which are loaded and displayed within your application. You should
specify iconengines if your application ships with SVG icons which
are used in the application's GUI. If in doubt, specify both, or users
might see a crippled user interface.

Environment
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Specifying USE_QT_VER=3D4 in a port Makefile will set some useful
environment variables to these default values:

QT_PREFIX=3D     ${LOCALBASE}
MOC=3D           ${QT_PREFIX}/bin/moc4
UIC=3D           ${QT_PREFIX}/bin/uic4
QMAKE=3D         ${QT_PREFIX}/bin/qmake-qt4
QMAKESPEC=3D     ${QT_PREFIX}/share/qt4/mkspecs/freebsd-g++

QTCPPFLAGS	(empty)
QTCGFLIBS	(empty)

It will also influence ${CONFIGURE_ENV}:

MOC=3D"${MOC}" UIC=3D"${UIC} CPPFLAGS=3D"${CPPFLAGS}
${QTCPPFLAGS}" LIBS=3D"${QTCFGLIBS}" QMAKE=3D"${QMAKE}
QMAKESPEC=3D"${QMAKESPEC}" QTDIR=3D"${QT_PREFIX}" KDEDIR=3D"${KDE_PREFIX}"

=2E.. and ${MAKE_ENV}

QMAKESPEC=3D"${QMAKESPEC}"

${CONFIGURE_ARGS} are appended with:

=2D-with-qt-includes=3D${QT_PREFIX}/include
=2D-with-qt-libraries=3D${QT_PREFIX}/lib
=2D-with-extra-libs=3D${LOCALBASE}/lib
=2D-with-extra-includes=3D${LOCALBASE}/include

The modification of CONFIGURE_ENV and CONFIGURE_ARGS can be
suppressed by defining QT_NONSTANDARD in your port Makefile.


Example
=3D=3D=3D=3D=3D=3D=3D

Note: *Do not use the actual qt4-* ports themselves as references*.

They are quite special (read: full of bad hacks and generally ugly),
since Qt doesn't really support being built component-by-component.

The editors/texmaker port can be used as reference for a typical Qt4
application that uses Qt's own qmake build system.

Let's look at the port Makefile:

[...]
USE_QT_VER=3D     4
QT_COMPONENTS=3D  gui moc qmake rcc uic
[...]

USE_QT_VER=3D4 enables the QT_COMPONENTS variable. The value of
QT_COMPONENTS, 'gui moc qmake rcc uic', triggers dependencies on the
qt4-gui, qt4-moc, qmake4, qt4-rcc and qt4-uic ports.

How to find out what components are needed by the application?

In this case, the INSTALL document only contains the instructions
"To compile and install Texmaker (Unix and MacosX): sudo sh BUILD.sh".
Looking at BUILD.sh, we find the line:

qmake -unix PREFIX=3D$PREFIX texmaker.pro

Apparently this application uses qmake, so we need 'qmake' added to
QT_COMPONENTS. As mentioned above, 'moc' is required by virtually
every qt application. Texmaker uses a GUI and there are files
with the .ui extension among the source code, thus we need
'uic'. There is also a .qrc file, which needs 'rcc' for processing.

Examination of the binary with ldd yields:

$ ldd /usr/local/bin/texmaker | grep Qt
libQtGui.so.4 =3D> /usr/local/lib/libQtGui.so.4 (0x281c9000)
libQtCore.so.4 =3D> /usr/local/lib/libQtCore.so.4 (0x28a01000)

The application links against the Qt gui and core libraries. Since
the core library is an implicit dependency of all other Qt4
libraries, it doesn't need to be specified. Our QT_COMPONENTS are now
complete: gui moc qmake rcc uic

What about the configure target?

Qmake allows for much flexibility with regards to how it is run and
what it is run on, which is why a generic configure target for
qmake isn't provided by bsd.kde.mk. With the provided environment it
is however quite easy to write your own:

[...]
HAS_CONFIGURE=3D	yes

do-configure:
        @cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} \
                ${QMAKE} -unix PREFIX=3D${PREFIX} texmaker.pro
[...]

Note the similarity to the qmake line from the provided BUILD.sh
script. The ${SETENV} ${CONFIGURE_ENV} ensures qmake will see the
QMAKESPEC variable, without which it cannot work.

Qmake generates standard Makefiles, so it is
not necessary to write our own build or configure targets.

Any other things to watch out for?

Qt applications often are written to be cross-platform and often
X11/Unix isn't the platform they are developed on, which in turn often
leads to certain loose ends, like:

=2D Missing additional includepaths. Many
applications come with system tray icon support, but neglect to look
for includes and/or libraries in the X11 directories. You can
tell qmake to add directories to the include and library searchpaths
via the commandline, for example:

${QMAKE} -unix PREFIX=3D${PREFIX} INCLUDEPATH+=3D${X11BASE}/include \
LIBS+=3D-L${X11BASE}/lib sillyapp.pro

=2D Bogus installation paths. Sometimes data such as icons or .desktop
files are by default installed into directories which aren't scanned
by XDG-compatible applications. editors/texmaker is an example for
this - look at patch-texmaker.pro in the files directory of that port
for a template on how to remedy this directly in the Qmake project
file.

A final note: At the moment, bsd.kde.mk isn't pre/postmk-safe, which
means you cannot use USE_QT_VER and QT_COMPONENTS after an .include
<bsd.port.pre.mk>. If your port requires this, please depend on the
component you need the traditional way for now, for example:

=2Einclude <bsd.port.pre.mk>

=2Eif defined(WITH_QT_SUPPORT)
BUILD_DEPENDS+=3D	moc4:${PORTSDIR}/devel/qt4-moc
LIB_DEPENDS+=3D	QtCore:${PORTSDIR}/devel/qt4-corelib
=2Eendif

=2Einclude <bsd.port.post.mk>

=2D-=20
   ,_,   | Michael Nottebrock               | lofi@freebsd.org
 (/^ ^\) | FreeBSD - The Power to Serve     | http://www.freebsd.org
   \u/   | K Desktop Environment on FreeBSD | http://freebsd.kde.org

--nextPart1320163.x9YgR5HM2H
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (FreeBSD)

iD8DBQBFx5rUXhc68WspdLARAkOZAJwJ+dckfSsOr5Lp9si2ikrA8tCWuACghKL6
TW+0V3/F2KA/t3eCiMIqtF4=
=Nhfo
-----END PGP SIGNATURE-----

--nextPart1320163.x9YgR5HM2H--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200702052200.04240.lofi>