6.10. Using Qt

6.10.1. Ports That Require Qt

Table 6.7. Variables for Ports That Use Qt
USE_QT_VERThe port uses the Qt toolkit. The only possible value is 3. Appropriate parameters are passed to configure script and make.
USE_QT4Specify tool and library dependencies for ports that use Qt 4. See Qt 4 component selection for more details.
QT_PREFIXSet to the path where Qt installed to (read-only variable).
MOCSet to the path of moc (read-only variable). Default set according to USE_QT_VER value.
QTCPPFLAGSAdditional compiler flags passed via CONFIGURE_ENV for Qt toolkit. Default set according to USE_QT_VER.
QTCFGLIBSAdditional libraries for linking passed via CONFIGURE_ENV for Qt toolkit. Default set according to USE_QT_VER.
QTNONSTANDARDSuppress modification of CONFIGURE_ENV, CONFIGURE_ARGS, CPPFLAGS and MAKE_ENV.

Table 6.8. Additional Variables for Ports That Use Qt 4.x
UICSet to the path of uic (read-only variable).
QMAKESet to the path of qmake (read-only variable).
QMAKESPECSet to the path of configuration file for qmake (read-only variable).
QMAKEFLAGSAdditional flags for qmake.
QT_INCDIRSet to Qt 4 include directories (read-only variable).
QT_LIBDIRSet to Qt 4 libraries path (read-only variable).
QT_PLUGINDIRSet to Qt 4 plugins path (read-only variable).

When USE_QT_VER is set to 3, some useful settings are passed to the configure script:

CONFIGURE_ARGS+= --with-qt-includes=${QT_PREFIX}/include \ --with-qt-libraries=${QT_PREFIX}/lib \ --with-extra-libs=${LOCALBASE}/lib \ --with-extra-includes=${LOCALBASE}/include CONFIGURE_ENV+= MOC="${MOC}" LIBS="${QTCFGLIBS}" \ QTDIR="${QT_PREFIX}" KDEDIR="${KDE_PREFIX}" CPPFLAGS+= ${QTCPPFLAGS}

If USE_QT4 is set, the following settings are deployed:

CONFIGURE_ARGS+= --with-qt-includes=${QT_INCDIR} \ --with-qt-libraries=${QT_LIBDIR} \ --with-extra-libs=${LOCALBASE}/lib \ --with-extra-includes=${LOCALBASE}/include CONFIGURE_ENV+= MOC="${MOC}" UIC="${UIC}" LIBS="${QTCFGLIBS}" \ QMAKE="${QMAKE}" QMAKESPEC="${QMAKESPEC}" QTDIR="${QT_PREFIX}" MAKE_ENV+= QMAKESPEC="${QMAKESPEC}" PLIST_SUB+= QT_INCDIR_REL=${QT_INCDIR_REL} \ QT_LIBDIR_REL=${QT_LIBDIR_REL} \ QT_PLUGINDIR_REL=${QT_PLUGINDIR_REL}

6.10.2. Component Selection (Qt 4.x Only)

Individual Qt 4 tool and library dependencies must be specified in the USE_QT4 variable. Every component can be suffixed by either _build or _run, the suffix indicating whether the component should be depended on at buildtime or runtime, respectively. If unsuffixed, the component will be depended on at both build- and runtime. Usually, library components should be specified unsuffixed, tool components should be specified with the _build suffix and plugin components should be specified with the _run suffix. The most commonly used components are listed below (all available components are listed in _USE_QT4_ALL in /usr/ports/Mk/bsd.qt.mk):

Table 6.9. Available Qt 4 Library Components
NameDescription
corelibcore library (can be omitted unless the port uses nothing but corelib)
guigraphical user interface library
networknetwork library
openglOpenGL library
qt3supportQt 3 compatibility library
qtestlibunit testing library
scriptscript library
sqlSQL library
xmlXML library

You can determine which libraries the application depends on, by running ldd on the main executable after a successful compilation.

Table 6.10. Available Qt 4 Tool Components
NameDescription
mocmeta object compiler (needed for almost every Qt application at buildtime)
qmakeMakefile generator / build utility
rccresource compiler (needed if the application comes with *.rc or *.qrc files)
uicuser interface compiler (needed if the application comes with *.ui files created by Qt Designer - in practice, every Qt application with a GUI)

Table 6.11. Available Qt 4 Plugin Components
NameDescription
iconenginesSVG icon engine plugin (if the application ships SVG icons)
imageformatsimageformat plugins for GIF, JPEG, MNG and SVG (if the application ships image files)

Example 6.5. Selecting Qt 4 Components

In this example, the ported application uses the Qt 4 graphical user interface library, the Qt 4 core library, all of the Qt 4 code generation tools and Qt 4's Makefile generator. Since the gui library implies a dependency on the core library, corelib does not need to be specified. The Qt 4 code generation tools moc, uic and rcc, as well as the Makefile generator qmake are only needed at buildtime, thus they are specified with the _build suffix:

USE_QT4= gui moc_build qmake_build rcc_build uic_build

6.10.3. Additional Considerations

If the application does not provide a configure file but a .pro file, you can use the following:

HAS_CONFIGURE= yes do-configure: @cd ${WRKSRC} && ${SETENV} ${CONFIGURE_ENV} \ ${QMAKE} ${QMAKEFLAGS} PREFIX=${PREFIX} texmaker.pro

Note the similarity to the qmake line from the provided BUILD.sh script. Passing 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 target.

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

  • Missing additional include paths. 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 search paths via the command line, for example:

    ${QMAKE} ${QMAKEFLAGS} PREFIX=${PREFIX} INCLUDEPATH+=${LOCALBASE}/include \ LIBS+=-L${LOCALBASE}/lib sillyapp.pro
  • Bogus installation paths. Sometimes data such as icons or .desktop files are by default installed into directories which are not 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.

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.

Send questions about this document to <freebsd-doc@FreeBSD.org>.