Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

[Prev: The 10 minute guide to using qmake] [Home] [Next: qmake's Advanced Concepts]

qmake Concepts

Introducing qmake

qmake is a simple tool that is created by Trolltech to create makefiles for development projects across different platforms. qmake simplifies the generation of makefiles so that only a few lines are needed to create to build a makefile. qmake can be used for any software project whether it is written in Qt or not, and it contains features to support developing with Qt.

qmake generates a makefile for an application by reading a project file. These project files are created by the user; they can also be very powerful in the sense that they can allow the user to do certain things in certain conditions. qmake can also generate projects for Microsoft Visual studio without having to change the project file.

qmake's Concepts

The QMAKESPEC environment variable

Before qmake can be used to build makefiles, the QMAKESPEC environment variable needs to be set to the platform/compiler combination that is being used on the system. The QMAKESPEC environment variable tells qmake where to look to find platform and compiler specific information. This ensures that the right libraries are linked against in certain situations, and that the generated makefile uses the right syntax. A list of the currently supported platform/compiler combinations can be found in qt/mkspecs. Just set your environment variable to one of the directories listed.

For example, if you are using Microsoft Visual Studio on Windows, then you would set your QMAKESPEC environment variable to win32-msvc. If you are using gcc on Solaris then you would set your QMAKESPEC environment variable to solaris-g++.

Inside each of the directories in qt/mkspecs, there is a qmake.conf file which contains the platform and compiler specific information. The settings in here are applied to any project that is built using qmake and should not be modified unless you know what you are doing. For example, this is the place to add a library that you want all of your applications to link against.

Project (.pro) files

A project file is used to tell qmake the details it needs to know about creating a makefile for the application. For instance, a list of source files and header files that should be put into the project file; any application specific configuration, such as an extra library that should be linked against, or an extra include path.

We'll go over these in more detail later on, but first we'll look at the TEMPLATE variable.

Templates

The template variable tells qmake what sort of makefile should be generated for the application. You can choose from one of the following:

The 'app' template

The 'app' template tells qmake to generate a makefile that will build an application. When using this template the following qmake system variables are recognized. You should use these in your .pro file to specify information about your application.

You only need to use the system variables that you have values for, for instance, if you don't have any extra INCLUDEPATHs then you don't need to specify any, qmake will add in the default ones needed. For instance, an example project file might look like the following:

TEMPLATE = app
HEADERS = hello.h
SOURCES = hello.cpp \
	 main.cpp
TARGET = hello
DESTDIR = c:\helloapp
DEFINES += QT_DLL
CONFIG += qt warn_on release

You might have noticed that when the DEFINES system variable is used, instead of putting DEFINES =, we have used DEFINES +=. This is because we are specifying additional DEFINES, by using += we inform qmake that it should use the defines that we have specified as well as the ones that qmake knows about itself.

The other thing that has not been mentioned in much detail up to now is the CONFIG line. If you have read through the quick-start part of the manual then you will know a little bit about the CONFIG line already. This will be explained in more detail later on in the chapter.

The 'lib' template

The 'lib' template tells qmake to generate a makefile that will build a library. When using this template, the system variables mentioned above for the 'app' template and the following are recognized. You should use these in your .pro file to specify information about the library.

The 'subdirs' template

The 'subdirs' template tells qmake to generate a makefile that will go into the specified subdirectories and generate a makefile for the project file in the directory and call make on it.

The only system variable that is recognised for this template is the SUBDIRS variable. The subdirs variable contains a list of all the sub directories that contain project files to be processed. It is essential that the project file in the sub directory has the same name as the sub directory, so qmake will find it without a problem. For example, if the sub directory is called 'hello' then the project file in that directory should be called hello.pro in that directory.

The CONFIG variable

The config variable specifies the options that the compiler should use and the libraries that should be linked against. Anything can be added to the end of the config variable, but the following are recognised by qmake internally.

The following options control what compiler flags are used:

The following options define the type of library/application to be built:

For example, if your application uses the Qt library and you want to build it as a debuggable multi-threaded application, your project file will have the following line:

	CONFIG += qt thread debug

Note, that += must be used here, or qmake will not be able to use the settings used to build Qt as a guide as what type of Qt library was built.

[Prev: The 10 minute guide to using qmake] [Home] [Next: qmake's Advanced Concepts]


Copyright © 2001 TrolltechTrademarks
Qt version 3.0.0-beta6