How to use KDE autotools for a Qt application?

Distributing your code in such a way that everybody may use it, can be difficult on unix systems. The tools needed to make an executable out of the code must be called in the right way. For this reason, the GNU autotools have been developed. KDE uses these tools and there are scripts that make it easier to use these tools. It is possible to use these scripts for applications that do not use the KDE libraries, but only the Qt libraries. This howto is intended to help developers use the KDE scripts with the GNU autotools to package their code.

Obtaining the scripts

The KDE scripts are placed in a directory admin in the top directory of your project. They can be obtained via anonymous cvs:
export CVSROOT=:pserver:anonymous@anoncvs.kde.org:/home/kde
cvs login
cvs co kde-common/admin
mv kde-common/admin .
rm -r kde-common
The variable CVSROOT must be set to the address of a CVS server. There are other anonymous CVS servers than the one mentioned here (see links section below).

Writing configure.in.in

In the top directory, we need two files: configure.in.in and Makefile.am. A nice starting point for the configure.in.in file is in the admin directory: configure.in.min. Copy this file to the top directory. The file configure.in.in is used to make the file configure.in, which is needed for autoconf. The KDE scripts copy this file into configure.in and append automatically generated data to it. For KDE development one can simply put #MIN_CONFIG in the file and the file configure.in.min is used. For a Qt only app, we need different setting, so we write our own configure.in.in starting from the file configure.in.min.

There are a few things that need to be changed to remove KDE dependancies.

A nice feature that encourages modularity is the fact that you can place a configure.in.in file in each subdirectory. The KDE scripts copy all of them into the configure.in file. For example, if you use C++ exceptions in your code, you can place a line CXXFLAGS="$CXXFLAGS $USE_EXCEPTIONS" in the directory with that code.

Writing Makefile.am's

toplevel Makefile.am

There are two different type of Makefile.am files. There's one in the top directory of the project an one for each subdirectory.

Unless you want to have a true GNU project, you should add the line
AUTOMAKE_OPTIONS = foreign 1.5
which relaxes the number of necessary files such as INSTALL and ChangeLog. It is, however, useful to have these files and you can generate them by calling automake --add-missing. The number arguments specifies the minimal version of automake that is accepted.

The top level file should contain information on how to create the acinclude.m4 and configure.in files from the acinclude.m4.in and the configure.in.in files.

$(top_srcdir)/acinclude.m4: $(top_srcdir)/admin/acinclude.m4.in $(top_srcdir)/admin/libtool.m4.in
        @cd $(top_srcdir) && cat admin/acinclude.m4.in admin/libtool.m4.in > acinclude.m4

$(top_srcdir)/configure.in: $(top_srcdir)/configure.files $(shell test -f $(top_srcdir)/configure.files && sed -e "s%^%\$(top_srcdir)/%" $(top_srcdir)/configure.files)
        cd $(top_srcdir) && $(MAKE) -f admin/Makefile.common configure.in
$(top_srcdir)/subdirs:
        cd $(top_srcdir) && $(MAKE) -f admin/Makefile.common subdirs
$(top_srcdir)/configure.files:
        cd $(top_srcdir) && $(MAKE) -f admin/Makefile.common configure.files

It should also contain information on which subdirectories to process:
SUBDIRS=$(TOPSUBDIRS)

other Makefile.am's

The other Makefile.am files are usually used to compile C++ files. Here's an example:

bin_PROGRAMS = someqtprogram

someqtprogram_SOURCES = program.cpp \
        mainclass.cpp
someqtprogram_LDFLAGS = $(QT_LDFLAGS) $(X_LDFLAGS)
someqtprogram_LDADD = $(LIB_QT) $(LIB_X11)

AM_CPPFLAGS = $(QT_INCLUDES)

METASOURCES = AUTO

If you want to generate .cpp files from .ui files, you need to give the line KDE_OPTIONS = qtonly, so that the internationalisation support is Qt specific.

You can find more information on writing a Makefile.am in the KDE specific manual and in the automake manual.

Using the files

Now the files are prepared, we can configure the autotools with the command:
make -f admin/Makefile.common cvs
./configure
make

To distribute your project, run these commands:
make distclean
cd ..
tar czf project.tgz projectdir

Links

Comments

If you have any question or comments, you can reach me at jos at vandenoever dot info.

Revisions