Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions | ![]() |
[Prev: The 10 minute guide to using qmake] [Home] [Next: qmake's Advanced Concepts]
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.
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.
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.
The template variable tells qmake what sort of makefile should be generated for the application. You can choose from one of the following:
app - Creates a makefile that builds an application. This is the default, so if a template is not specified, this is used.
lib - Creates a makefile that builds a library.
vcapp - Creates a Visual Studio Project file which builds an application.
vclib - Creates a Visual Studio Project file which builds a library.
subdirs - This is a special template which creates a makefile which will go into the specified directories and create a makefile for the project file and call make on it.
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.
HEADERS - A list of all the header files for the application.
SOURCES - A list of all the source files for the application.
FORMS - A list of all the .ui files (created using Qt Designer) for the application.
LEXSOURCES - A list of all the lex source files for the application.
YACCSOURCES - A list of all the yacc source files for the application.
TARGET - Name of the executable for the application (the extension is added automatically).
DESTDIR - The directory in which the target executable is placed.
DEFINES - A list of any additional pre-processor defines needed for the application.
INCLUDEPATH - A list of any additional include paths needed for the application.
DEPENDPATH - The dependency search path for the application.
DEF_FILE - Windows only: A .def file to be linked against for the application.
RC_FILE - Windows only: A resource file for the application.
RES_FILE - Windows only: A resource file to be linked against for the 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 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.
VERSION - The version number of the target library, for example, 2.3.1.
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 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:
release - The application is to be built in release mode. This is ignored if 'debug' is specified.
debug - The application is to be built in debug mode.
warn_on - The compiler should emit more warnings than usual. This is ignored if 'warn_off' is specified.
warn_off - The compiler should emit as few warnings as possible.
The following options define the type of library/application to be built:
qt - The application is a Qt application and should link against the Qt library.
thread - The application is a multi-threaded application.
x11 - The application is an X11 application or library.
windows - 'app' template only: The application is a Windows window application.
console - 'app' template only: The application is a Windows console application.
dll - 'lib' template only: The library is a shared library (dll).
staticlib - 'lib' template only: The library is a static library.
plugin - 'lib' template only: The library is a plugin; this enables the dll option.
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 Trolltech | Trademarks | Qt version 3.0.0-beta6
|