using qmake

107
Using qmake qmake provides a project-oriented system for managing the build process for applications, libraries, and other components. This approach gives developers control over the source files used, and allows each of the steps in the process to be described concisely, typically within a single file.qmake expands the information in each project file to a Makefile that executes the necessary commands for compiling and linking. In this document, we provide a basic introduction to project files, describe some of the main features of qmake, and show how to use qmake on the command line. Describing a Project Projects are described by the contents of project (.pro) files. The information within these is used by qmake to generate a Makefile containing all the commands that are needed to build each project. Project files typically contain a list of source and header files, general configuration information, and any application-specific details, such as a list of extra libraries to link against, or a list of extra include paths to use. Project files can contain a number of different elements, including comments, variable declarations, built-in functions, and some simple control structures. In most simple projects, it is only necessary to declare the source and header files that are used to build the project with some basic configuration options. Complete examples of project files can be found in the qmake Tutorial . An introduction to project files can be found in the qmake Project Files chapter, and a more detailed description is available in the qmake Reference . Building a Project For simple projects, you only need to run qmake in the top level directory of your project. By default, qmake generates a Makefile that you then use to build the project, and you can then run your platform's make tool to build the project. qmake can also be used to generate project files. A full description of qmake's command line options can be found in the Running qmake chapter of this manual. Using Precompiled Headers In large projects, it is possible to take advantage of precompiled header files to speed up the build process. This feature is described in detail in the Using Precompiled Headers chapter. qmake Project Files

Upload: auddrey

Post on 04-Apr-2015

5.474 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Using Qmake

Using qmakeqmake provides a project-oriented system for managing the build process for applications,

libraries, and other components. This approach gives developers control over the source

files used, and allows each of the steps in the process to be described concisely, typically within a single file.qmake expands the information in each project file to a Makefile that

executes the necessary commands for compiling and linking.

In this document, we provide a basic introduction to project files, describe some of the main features of qmake, and show how to use qmake on the command line.

Describing a ProjectProjects are described by the contents of project (.pro) files. The information within these is

used by qmake to generate a Makefile containing all the commands that are needed to build

each project. Project files typically contain a list of source and header files, general

configuration information, and any application-specific details, such as a list of extra libraries

to link against, or a list of extra include paths to use.

Project files can contain a number of different elements, including comments, variable

declarations, built-in functions, and some simple control structures. In most simple projects,

it is only necessary to declare the source and header files that are used to build the project

with some basic configuration options.

Complete examples of project files can be found in the qmake Tutorial. An introduction to

project files can be found in the qmake Project Files chapter, and a more detailed

description is available in the qmake Reference.

Building a ProjectFor simple projects, you only need to run qmake in the top level directory of your project. By

default, qmake generates a Makefile that you then use to build the project, and you can then

run your platform's make tool to build the project.

qmake can also be used to generate project files. A full description of qmake's command line

options can be found in the Running qmake chapter of this manual.

Using Precompiled HeadersIn large projects, it is possible to take advantage of precompiled header files to speed up the

build process. This feature is described in detail in the Using Precompiled Headerschapter.

qmake Project FilesProject files contain all the information required byqmake to build your application, library, or

plugin. The resources used by your project are generally specified using a series of

declarations, but support for simple programming constructs allow you to describe different

build processes for different platforms and environments.

Project File ElementsThe project file format used by qmake can be used to support both simple and fairly complex

build systems. Simple project files will use a straightforward declarative style, defining

Page 2: Using Qmake

standard variables to indicate the source and header files that are used in the project.

Complex projects may use the control flow structures to fine-tune the build process.

The following sections describe the different types of elements used in project files.

Variables

In a project file, variables are used to hold lists of strings. In the simplest projects, these variables inform qmake about the configuration options to use, or supply filenames and paths

to use in the build process.qmake looks for certain variables in each project file, and it uses the contents of these to

determine what it should write to a Makefile. For example, the list of values in the HEADERSand SOURCES variables are used to tell qmake about header and source files in

the same directory as the project file.

Variables can also be used internally to store temporary lists of values, and existing lists of

values can be overwritten or extended with new values.

The following lines show how lists of values are assigned to variables:

HEADERS = mainwindow.h paintwidget.h

Note that the first assignment only includes values that are specified on the same line as the SOURCES variable. The second assignment splits the items across lines by using the \\

character.

The list of values in a variable is extended in the following way:

SOURCES = main.cpp mainwindow.cpp \

paintwidget.cpp

CONFIG += qt

The CONFIG variable is another special variable that qmake uses when generating a Makefile.

It is discussed in the section on general configuration later in this chapter. In the above line, qt is added to the list of existing values contained in CONFIG.

The following table lists the variables that qmake recognizes, and describes what they should

contain.

Variable Contents

CONFIG General project configuration options.

DESTDIR The directory in which the executable or binary file will be placed.

FORMS A list of UI files to be processed by uic.

HEADERS A list of filenames of header (.h) files used when building the project.

QT Qt-specific configuration options.

Page 3: Using Qmake

Variable Contents

RESOURCES A list of resource (.rc) files to be included in the final project. See the The Qt Resource System for more

information about these files.

SOURCES A list of source code files to be used when building the project.

TEMPLATE The template to use for the project. This determines whether the output of the build process will be an application,

a library, or a plugin.

The contents of a variable can be read by prepending the variable name with $$. This can be

used to assign the contents of one variable to another:

TEMP_SOURCES = $$SOURCES

The $$ operator is used extensively with built-in functions that operate on strings and lists of

values. These are described in the chapter on qmake Advanced Usage.Whitespace

Normally, variables are used to contain whitespace-separated lists of values. However, it is

sometimes necessary to specify values containing spaces. These must be quoted by using

the quote() function in the following way:

DEST = "Program Files"

The quoted text is treated as a single item in the list of values held by the variable. A similar

approach is used to deal with paths that contain spaces, particularly when defining

theINCLUDEPATH and LIBS variables for the Windows platform. In cases like these,

the quote()function can be used in the following way:

win32:INCLUDEPATH += $$quote(C:/mylibs/extra headers)

unix:INCLUDEPATH += $$quote(/home/user/extra headers)

CommentsYou can add comments to project files. Comments begin with the # character and continue

to the end of the same line. For example:

# Comments usually start at the beginning of a line, but they

# can also follow other content on the same line.

To include the # character in variable assignments, it is necessary to use the contents of the

built-in LITERAL_HASH variable. See the variable reference for more information.

Page 4: Using Qmake

Built-in Functions and Control Flowqmake provides a number of built-in functions to allow the contents of variables to be

processed. The most commonly used function in simple project files is the include function

which takes a filename as an argument. The contents of the given file are included in the project file at the place where the include function is used. The include function is most

commonly used to include other project files:

include(other.pro)

Support for conditional structures is made available via scopes that behave like ifstatements in programming languages:

win32 {

SOURCES += paintwidget_win.cpp

}

The assignments inside the braces are only made if the condition is true. In this case, the special win32 variable must be set; this happens automatically on Windows, but this can

also be specified on other platforms by running qmake with the -win32 command line option

(see Running qmake for more information). The opening brace must stand on the same line

as the condition.Simple loops are constructed by iterating over lists of values using the built-in for function.

The following code adds directories to the SUBDIRS variable, but only if they exist:

EXTRAS = handlers tests docs

for(dir, EXTRAS) {

exists($$dir) {

SUBDIRS += $$dir

}

}

More complex operations on variables that would usually require loops are provided by built-in functions such as find, unique, and count. These functions, and many others are

provided to manipulate strings and paths, support user input, and call external tools. A list of

the functions available can be found in the qmake Advanced Usage chapter of this manual.

Project Templates

Page 5: Using Qmake

The TEMPLATE variable is used to define the type of project that will be built. If this is not

declared in the project file, qmake assumes that an application should be built, and will

generate an appropriate Makefile (or equivalent file) for the purpose.

The types of project available are listed in the following table with information about the files that qmake will generate for each of them:

Template Description of qmake output

app (default) Creates a Makefile to build an application.

lib Creates a Makefile to build a library.

subdirs Creates a Makefile containing rules for the subdirectories specified using theSUBDIRS variable. Each subdirectory

must contain its own project file.

vcapp Creates a Visual Studio Project file to build an application.

vclib Creates a Visual Studio Project file to build a library.

vcsubdirs Creates a Visual Studio Solution file to build projects in sub-directories.

See the qmake Tutorial for advice on writing project files for projects that use the app andlib templates.

When the subdirs template is used, qmake generates a Makefile to examine each specified

subdirectory, process any project file it finds there, and run the platform's make tool on the

newly-created Makefile. The SUBDIRS variable is used to contain a list of all the

subdirectories to be processed.

General ConfigurationThe CONFIG variable specifies the options and features that the compiler should use and the libraries that should be linked against. Anything can be added to the CONFIG variable, but

the options covered below are recognized by qmake internally.

The following options control the compiler flags that are used to build the project:

Option Description

release The project is to be built in release mode. This is ignored ifdebug is also specified.

debug The project is to be built in debug mode.

debug_and_release The project is built in both debug and release modes.

debug_and_release_target The project is built in both debug and release modes. TARGET is built into both the debug and

release directories.

build_all If debug_and_release is specified, the project is built in both debug and release modes by

default.

autogen_precompile_source Automatically generates a .cpp file that includes the precompiled header file specified in the .pro

file.

ordered When using the subdirs template, this option specifies that the directories listed should be

processed in the order in which they are given.

Page 6: Using Qmake

Option Description

warn_on The compiler should output as many warnings as possible. This is ignored if warn_off is

specified.

warn_off The compiler should output as few warnings as possible.

copy_dir_files Enables the install rule to also copy directories, not just files.

The debug_and_release option is special in that it enables both debug and release versions

of a project to be built. In such a case, the Makefile that qmake generates includes a rule that

builds both versions, and this can be invoked in the following way:

make all

Adding the build_all option to the CONFIG variable makes this rule the default when

building the project, and installation targets will be created for both debug and release

builds.Note that each of the options specified in the CONFIG variable can also be used as a scope

condition. You can test for the presence of certain configuration options by using the built-

in CONFIG() function. For example, the following lines show the function as the condition in a scope to test whether only the opengl option is in use:

CONFIG(opengl) {

message(Building with OpenGL support.)

} else {

message(OpenGL support is not available.)

}

This enables different configurations to be defined for release and debug builds, and is

described in more detail in the Scopes section of the Advanced Usage chapter of this

manual.

The following options define the type of project to be built. Note that some of these options

only take effect when used on the relevant platform. On other platforms, they have no

effect.

Option Description

qt The project is a Qt application and should link against the Qt library. You can use theQT variable to control any

additional Qt modules that are required by your application.

thread The project is a multi-threaded application.

x11 The project is an X11 application or library.

Page 7: Using Qmake

When using application or library project templates, more specialized configuration options

can be used to fine tune the build process. These are explained in details in the Common

Projects chapter of this manual.

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

CONFIG += qt thread debug

Note, that you must use "+=", not "=", or qmake will not be able to use Qt's configuration to

determine the settings needed for your project.

Declaring Qt LibrariesIf the CONFIG variable contains the qt value, qmake's support for Qt applications is enabled.

This makes it possible to fine-tune which of the Qt modules are used by your application. This is achieved with the QT variable which can be used to declare the required extension

modules. For example, we can enable the XML and network modules in the following way:

CONFIG += qt

QT += network xml

Note that QT includes the core and gui modules by default, so the above

declaration addsthe network and XML modules to this default list. The following

assignment omits the default modules, and will lead to errors when the application's source

code is being compiled:

QT = network xml # This will omit the core and gui modules.

If you want to build a project without the gui module, you need to exclude it with the "-="

operator. By default, QT contains both core and gui, so the following line will result in a

minimal Qt project being built:

QT -= gui # Only the core module is used.

The table below shows the options that can be used with the QT variable and the features

that are associated with each of them:

Option Features

core (included by default) QtCore module

gui (included by default) QtGui module

Page 8: Using Qmake

Option Features

network QtNetwork module

opengl QtOpenGL module

sql QtSql module

svg QtSvg module

xml QtXml module

xmlpatterns QtXmlPatterns module

qt3support Qt3Support module

Note that adding the opengl option to the QT variable automatically causes the equivalent

option to be added to the CONFIG variable. Therefore, for Qt applications, it is not necessary

to add the opengl option to both CONFIG and QT.

Configuration Featuresqmake can be set up with extra configuration features that are specified in feature (.prf) files.

These extra features often provide support for custom tools that are used during the build

process. To add a feature to the build process, append the feature name (the stem of the feature filename) to the CONFIG variable.

For example, qmake can configure the build process to take advantage of external libraries

that are supported by pkg-config, such as the D-Bus and ogg libraries, with the following

lines:

CONFIG += link_pkgconfig

PKGCONFIG += ogg dbus-1

More information about features can be found in the Adding New Configuration

Featuressection of the qmake Advanced Usage chapter.

Declaring Other LibrariesIf you are using other libraries in your project in addition to those supplied with Qt, you need

to specify them in your project file.The paths that qmake searches for libraries and the specific libraries to link against can be

added to the list of values in the LIBS variable. The paths to the libraries themselves can be

given, or the familiar Unix-style notation for specifying libraries and paths can be used if

preferred.

For example, the following lines show how a library can be specified:

LIBS += -L/usr/local/lib -lmath

Page 9: Using Qmake

The paths containing header files can also be specified in a similar way using

theINCLUDEPATH variable.

For example, it is possible to add several paths to be searched for header files:

INCLUDEPATH = c:/msdev/include d:/stl/include

Running qmakeThe behavior of qmake can be customized when it is run by specifying various options on the

command line. These allow the build process to be fine-tuned, provide useful diagnostic

information, and can be used to specify the target platform for your project.

Command-Line Options

SyntaxThe syntax used to run qmake takes the following simple form:

qmake [mode] [options] files

qmake supports two different modes of operation: In the default mode, qmake will use the

description in a project file to generate a Makefile, but it is also possible to use qmake to

generate project files. If you want to explicitly set the mode, you must specify it before all other options. The mode can be either of the following two values:

-makefile qmake output will be a Makefile.

-project qmake output will be a project file. Note: It is likely that the created file will need to be edited for example adding the QTvariable to suit what modules are required for the project.

The following options are used to specify both general and mode-specific settings. Options

that only apply to the Makefile mode are described in the Makefile Mode Options section;

options that influence the creation of project files are described in the Project File

Optionssection.The files argument represents a list of one or more project files, separated by spaces.

OptionsA wide range of options can be specified on the command line to qmake in order to

customize the build process, and to override default settings for your platform. The following basic options provide usage information, specify where qmake writes the output file, and

control the level of debugging information that will be written to the console: -help 

qmake will go over these features and give some useful help.

Page 10: Using Qmake

-o file qmake output will be directed to file. If this option is not specified, qmake will try to use a suitable file name for its output, depending on the mode it is running in.If '-' is specified, output is directed to stdout.

-d qmake will output debugging information.

For projects that need to be built differently on each target platform, with many subdirectories, you can run qmake with each of the following options to set the

corresponding platform-specific variable in each project file: -unix 

qmake will run in unix mode. In this mode, Unix file naming and path conventions will be used, additionally testing for unix (as a scope) will succeed. This is the default mode on all Unices.

-macx qmake will run in Mac OS X mode. In this mode, Unix file naming and path conventions will be used, additionally testing for macx (as a scope) will succeed. This is the default mode on Mac OS X.

-win32 qmake will run in win32 mode. In this mode, Windows file naming and path conventions will be used, additionally testing for win32 (as a scope) will succeed. This is the default mode on Windows.

The template used for the project is usually specified by the TEMPLATE variable in the project

file. We can override or modify this by using the following options: -t tmpl 

qmake will override any set TEMPLATE variables with tmpl, but only after the .pro file has been processed.

-tp prefix qmake will add the prefix to the TEMPLATE variable.

The level of warning information can be fine-tuned to help you find problems in your project

file: -Wall 

qmake will report all known warnings.

-Wnone No warning information will be generated by qmake.

-Wparser qmake will only generate parser warnings. This will alert you to common pitfalls and potential problems in the parsing of your project files.

-Wlogic qmake will warn of common pitfalls and potential problems in your project file. For example, qmake will report whether a file is placed into a list of files multiple times, or if a file cannot be found.

Page 11: Using Qmake

Makefile Mode Options

qmake -makefile [options] files

In Makefile mode, qmake will generate a Makefile that is used to build the project.

Additionally, the following options may be used in this mode to influence the way the project

file is generated: -after 

qmake will process assignments given on the command line after the specified files.

-nocache qmake will ignore the .qmake.cache file.

-nodepend qmake will not generate any dependency information.

-cache file qmake will use file as the cache file, ignoring any other .qmake.cache files found.

-spec spec qmake will use spec as a path to platform and compiler information, and the value ofQMAKESPEC will be ignored.

You may also pass qmake assignments on the command line; they will be processed before

all of the files specified. For example:

qmake -makefile -unix -o Makefile "CONFIG+=test" test.pro

This will generate a Makefile, from test.pro with Unix pathnames. However many of the

specified options aren't necessary as they are the default. Therefore, the line can be

simplified on Unix to:

qmake "CONFIG+=test" test.pro

If you are certain you want your variables processed after the files specified, then you may pass the -after option. When this is specified, all assignments on the command line after

the -after option will be postponed until after the specified files are parsed.

Project Mode Options

qmake -project [options] files

In project mode, qmake will generate a project file. Additionally, you may supply the

following options in this mode:

Page 12: Using Qmake

-r qmake will look through supplied directories recursively

-nopwd qmake will not look in your current working directory for source code and only use the specified files

In this mode, the files argument can be a list of files or directories. If a directory is

specified, it will be included in the DEPENDPATH variable, and relevant code from there will be

included in the generated project file. If a file is given, it will be appended to the correct variable, depending on its extension; for example, UI files are added to FORMS, and C++ files

are added to SOURCES.

You may also pass assignments on the command line in this mode. When doing so, these

assignments will be placed last in the generated project file.

qmake Platform NotesMany cross-platform projects can be handled by theqmake's basic configuration features. On

some platforms, it is sometimes useful, or even necessary, to take advantage of platform-specific features.qmake knows about many of these features, and these can be accessed via

specific variables that only have an effect on the platforms where they are relevant.

Mac OS XFeatures specific to this platform include support for creating universal binaries, frameworks

and bundles.

Source and Binary PackagesThe version of qmake supplied in source packages is configured slightly differently to that

supplied in binary packages in that it uses a different feature specification. Where the source package typically uses the macx-g++ specification, the binary package is typically configured

to use the macx-xcodespecification.

Users of each package can override this configuration by invoking qmake with the -

spec option (see Running qmake for more information). This makes it possible, for example,

to use qmake from a binary package to create a Makefile in a project directory with the

following command line invocation:

qmake -spec macx-g++

Using Frameworksqmake is able to automatically generate build rules for linking against frameworks in the

standard framework directory on Mac OS X, located at /Library/Frameworks/.

Directories other than the standard framework directory need to be specified to the build

system, and this is achieved by appending linker options to the QMAKE_LFLAGS variable, as

shown in the following example:

Page 13: Using Qmake

QMAKE_LFLAGS += -F/path/to/framework/directory/

The framework itself is linked in by appending the -framework options and the name of the

framework to the LIBS variable:

LIBS += -framework TheFramework

Creating Frameworks

Any given library project can be configured so that the resulting library file is placed in aframework, ready for deployment. To do this, set up the project to use the lib   template and

add the lib_bundle option to the CONFIG variable:

TEMPLATE = lib

CONFIG += lib_bundle

The data associated with the library is specified using the QMAKE_BUNDLE_DATA variable.

This holds items that will be installed with a library bundle, and is often used to specify a

collection of header files, as in the following example:

FRAMEWORK_HEADERS.version = Versions

FRAMEWORK_HEADERS.files = path/to/header_one.h path/to/header_two.h

FRAMEWORK_HEADERS.path = Headers

QMAKE_BUNDLE_DATA += FRAMEWORK_HEADERS

Here, the FRAMEWORK_HEADERS variable is a user-defined variable that is used to define the

headers required to use a particular framework. Appending it to the QMAKE_BUNDLE_DATAvariable ensures that the information about these headers are

added to the collection of resources that will be installed with the library bundle. Also, the

framework's name and version are specified

by QMAKE_FRAMEWORK_BUNDLE_NAME andQMAKE_FRAMEWORK_VERSION variables. By

default, the values used for these are obtained from the TARGET and VERSION variables.

See Deploying an Application on Mac OS X for more information about deploying

applications and libraries.

Creating Universal Binaries

To create a universal binary for your application, you need to be using a version of Qt that has been configured with the -universal option.

Page 14: Using Qmake

The architectures to be supported in the binary are specified with the CONFIG variable. For example, the following assignment causes qmake to generate build rules to create a

universal binary for both PowerPC and x86 architectures:

CONFIG += x86 ppc

Additionally, developers using a PowerPC-based platform need to set

the QMAKE_MAC_SDKvariable. This process is discussed in more detail in the deployment

guide for Mac OS X.

Creating and Moving Xcode ProjectsDevelopers on Mac OS X can take advantage of qmake's support for Xcode project files, as

described in Qt is Mac OS X Native, by running qmake to generate an Xcode project from an

existing qmake project files. For example:

qmake -spec macx-xcode project.pro

Note that, if a project is later moved on the disk, qmake must be run again to process the

project file and create a new Xcode project file.

On supporting two build targets simultaneously

Implementing this is currently not feasible, because the XCode concept of Active Build

Configurations is conceptually different from the qmake idea of build targets.

The XCode Active Build Configurations settings are for modifying xcode configurations,

compiler flags and similar build options. Unlike Visual Studio, XCode does not allow for the

selection of specific library files based on whether debug or release build configurations are

selected. The qmake debug and release settings control which library files are linked to the

executable.

It is currently not possible to set files in XCode configuration settings from the qmake

generated xcode project file. The way the libraries are linked in the "Frameworks &

Libraries" phase in the XCode build system.

Furthermore, the selected "Active Build Configuration" is stored in a .pbxuser file, which is

generated by xcode on first load, not created by qmake.

WindowsFeatures specific to this platform include support for creating Visual Studio project files and

handling manifest files when deploying Qt applications developed using Visual Studio 2005.

Creating Visual Studio Project Files

Developers using Visual Studio to write Qt applications can use the Visual Studio integration

facilities provided with the Qt Commercial Edition and do not need to worry about how

project dependencies are managed.

Page 15: Using Qmake

However, some developers may need to import an existing qmake project into Visual

Studio.qmake is able to take a project file and create a Visual Studio project that contains all

the necessary information required by the development environment. This is achieved by setting the qmake project template to either vcapp (for application projects) or vclib (for

library projects).

This can also be set using a command line option, for example:

qmake -tp vc

It is possible to recursively generate .vcproj files in subdirectories and a .sln file in the

main directory, by typing:

qmake -tp vc -r

Each time you update the project file, you need to run qmake to generate an updated Visual

Studio project.Note: If you are using the Visual Studio Add-in, you can import .pro files via the Qt-

>Import from .pro file menu item.

Visual Studio 2005 Manifest Files

When deploying Qt applications built using Visual Studio 2005, it is necessary to ensure that

the manifest file, created when the application was linked, is handled correctly. This is

handled automatically for projects that generate DLLs.

Removing manifest embedding for application executables can be done with the following

assignment to the CONFIG variable:

CONFIG -= embed_manifest_exe

Also, the manifest embedding for DLLs can be removed with the following assignment to

theCONFIG variable:

CONFIG -= embed_manifest_dll

This is discussed in more detail in the deployment guide for Windows.

Symbian platformFeatures specific to this platform include handling of static data, capabilities, stack and heap

size, compiler specific options, and unique identifiers for the application or library.

Page 16: Using Qmake

Handling of static data

If the application uses any static data, the build system needs to be informed about it. This

is because Symbian tries to save memory if no static data is in use.

To specify that static data support is desired, add this to the project file:

TARGET.EPOCALLOWDLLDATA = 1

The default value is zero.

Stack and heap size

The Symbian platform uses predefined sizes for stacks and heaps. If an application exceeds

either limit, it may crash or fail to complete its task. Crashes that seem to have no reason

can often be traced back to insufficient stack and/or heap sizes.

The stack size has a maximum value, whereas the heap size has a minimum and a

maximum value, all specified in bytes. The minimum value prevents the application from

starting if that amount of memory is not available. The minimum and maximum values are

separated by a space. For example:

TARGET.EPOCHEAPSIZE = 10000 10000000

TARGET.EPOCSTACKSIZE = 0x8000

The default values depend on the version of the Symbian SDK you're using, however, the Qt

toolchain sets this to the maximum possible value and this should not be changed.

Compiler specific optionsGeneral compiler options can as usual be set using QMAKE_CFLAGS and QMAKE_CXXFLAGS. In

order to set specific compiler options, QMAKE_CFLAGS.<compiler> and QMAKE_CXXFLAGS.<compiler> can be

used. <compiler> can be either CW for the WINSCW architecture (emulator), or ARMCC for the

ARMv5 architecture (hardware), or GCCE for the ARMv5 architecture (hardware).

Here is an example:

QMAKE_CXXFLAGS.CW += -O2

QMAKE_CXXFLAGS.ARMCC += -O0

Unique identifiers

Symbian applications may have unique identifiers attached to them. Here is how to define

them in a project file:There are four available types of IDs supported: UID2, UID3, SID, and VID. They are specified

like this:

Page 17: Using Qmake

TARGET.UID2 = 0x00000001

TARGET.UID3 = 0x00000002

TARGET.SID = 0x00000003

TARGET.VID = 0x00000004

If SID is not specified, it defaults to the same value as UID3. If UID3 is not specified, qmake

will automatically generate a UID3 suitable for development and debugging. This value

should be manually specified for applications that are to be released. In order to obtain an official UID, please contact http:\www.symbiansigned.com. Both SID and VID default to

empty values.

There exists one UID1 too, but this should not be touched by any application.

The UID2 has a specific value for different types of files - e.g. apps/exes are always

0x100039CE. The toolchain will set this for value for the most common file types like,

EXE/APP and shared library DLL.

For more information about unique identifiers and their meaning for Symbian applications,

please refer to the

http://developer.symbian.org/main/documentation/reference/s3/pdk/GUID-380A8C4F-3EB6-

5E1C-BCFB-ED5B866136D9.html

Capabilities

Capabilities define extra privileges for the application, such as the ability to list all files on

the file system. Capabilities are defined in the project file like this:

TARGET.CAPABILITY += AllFiles

It is also possible to specify which capabilities not to have, by first specifying ALL and then

list the unwanted capabilities with a minus in front of them, like this:

TARGET.CAPABILITY = ALL -TCB -DRM -AllFiles

For more information about capabilities, please refer to the Symbian SDK documentat

qmake Advanced UsageMany qmake project files simply describe the sources and header files used by the project,

using a list ofname = value and name += value definitions.qmake also provides other

operators, functions, and scopes that can be used to process the information supplied in

variable declarations. These advanced features allow Makefiles to be generated for multiple

platforms from a single project file.

Page 18: Using Qmake

OperatorsIn many project files, the assignment (=) and append (+=) operators can be used to include

all the information about a project. The typical pattern of use is to assign a list of values to a

variable, and append more values depending on the result of various tests. Since qmake defines certain variables using default values, it is sometimes necessary to use

the removal (-=) operator to filter out values that are not required. The following operators

can be used to manipulate the contents of variables.The = operator assigns a value to a variable:

TARGET = myapp

The above line sets the TARGET variable to myapp. This will overwrite any values previously

set for TARGET with myapp.

The += operator appends a new value to the list of values in a variable:

DEFINES += QT_DLL

The above line appends QT_DLL to the list of pre-processor defines to be put in the

generated Makefile.The -= operator removes a value from the list of values in a variable:

DEFINES -= QT_DLL

The above line removes QT_DLL from the list of pre-processor defines to be put in the

generated Makefile.The *= operator adds a value to the list of values in a variable, but only if it is not already

present. This prevents values from being included many times in a variable. For example:

DEFINES *= QT_DLL

In the above line, QT_DLL will only be added to the list of pre-processor defines if it is not

already defined. Note that the unique() function can also be used to ensure that a

variables only contains one instance of each value.The ~= operator replaces any values that match a regular expression with the specified

value:

DEFINES ~= s/QT_[DT].+/QT

In the above line, any values in the list that start with QT_D or QT_T are replaced with QT.

Page 19: Using Qmake

The $$ operator is used to extract the contents of a variable, and can be used to pass values

between variables or supply them to functions:

EVERYTHING = $$SOURCES $$HEADERS

message("The project contains the following files:")

message($$EVERYTHING)

ScopesScopes are similar to if statements in procedural programming languages. If a certain

condition is true, the declarations inside the scope are processed.

Syntax

Scopes consist of a condition followed by an opening brace on the same line, a sequence of

commands and definitions, and a closing brace on a new line:

<condition> {

<command or definition>

...

}

The opening brace must be written on the same line as the condition. Scopes may be

concatenated to include more than one condition; see below for examples.

Scopes and Conditions

A scope is written as a condition followed by a series of declarations contained within a pair

of braces; for example:

win32 {

SOURCES += paintwidget_win.cpp

}

The above code will add the paintwidget_win.cpp file to the sources listed in the

generated Makefile if qmake is used on a Windows platform. If qmake is used on a platform

other than Windows, the define will be ignored.

The conditions used in a given scope can also be negated to provide an alternative set of

declarations that will be processed only if the original condition is false. For example,

suppose we want to process something on all platforms except for Windows. We can achieve

this by negating the scope like this:

Page 20: Using Qmake

!win32 {

SOURCES -= paintwidget_win.cpp

}

Scopes can be nested to combine more than one condition. For instance, if you want to

include a particular file for a certain platform only if debugging is enabled then you write the

following:

macx {

debug {

HEADERS += debugging.h

}

}

To save writing many nested scopes, you can nest scopes using the : operator. The nested

scopes in the above example can be rewritten in the following way:

macx:debug {

HEADERS += debugging.h

}

You may also use the : operator to perform single line conditional assignments; for

example:

win32:DEFINES += QT_DLL

The above line adds QT_DLL to the DEFINES variable only on the Windows platform.

Generally, the : operator behaves like a logical AND operator, joining together a number of

conditions, and requiring all of them to be true.There is also the | operator to act like a logical OR operator, joining together a number of

conditions, and requiring only one of them to be true.

win32|macx {

HEADERS += debugging.h

}

Page 21: Using Qmake

You can also provide alternative declarations to those within a scope by using an elsescope.

Each else scope is processed if the conditions for the preceding scopes are false. This

allows you to write complex tests when combined with other scopes (separated by the: operator as above). For example:

win32:xml {

message(Building for Windows)

SOURCES += xmlhandler_win.cpp

} else:xml {

SOURCES += xmlhandler.cpp

} else {

message("Unknown configuration")

}

Configuration and ScopesThe values stored in the CONFIG   variable  are treated specially by qmake. Each of the

possible values can be used as the condition for a scope. For example, the list of values held by CONFIG can be extended with the opengl value:

CONFIG += opengl

As a result of this operation, any scopes that test for opengl will be processed. We can use

this feature to give the final executable an appropriate name:

opengl {

TARGET = application-gl

} else {

TARGET = application

}

This feature makes it easy to change the configuration for a project without losing all the

custom settings that might be needed for a specific configuration. In the above code, the

declarations in the first scope are processed, and the final executable will be calledapplication-gl. However, if opengl is not specified, the declarations in the second

scope are processed instead, and the final executable will be called application.

Since it is possible to put your own values on the CONFIG line, this provides you with a

convenient way to customize project files and fine-tune the generated Makefiles.

Page 22: Using Qmake

Platform Scope ValuesIn addition to the win32, macx, and unix values used in many scope conditions, various

other built-in platform and compiler-specific values can be tested with scopes. These are based on platform specifications provided in Qt's mkspecs directory. For example, the

following lines from a project file show the current specification in use and test for thelinux-g++ specification:

message($$QMAKESPEC)

linux-g++ {

message(Linux)

}

You can test for any other platform-compiler combination as long as a specification exists for it in the mkspecs directory.

The scope unix is true for the Symbian platform.

VariablesMany of the variables used in project files are special variables that qmake uses when

generating Makefiles, such as DEFINES, SOURCES, and HEADERS. It is possible for you to

create variables for your own use; qmake creates new variables with a given name when it

encounters an assignment to that name. For example:

MY_VARIABLE = value

There are no restricitions on what you do to your own variables, as qmake will ignore them

unless it needs to evaluate them when processing a scope.

You can also assign the value of a current variable to another variable by prefixing $$ to the

variable name. For example:

MY_DEFINES = $$DEFINES

Now the MY_DEFINES variable contains what is in the DEFINES variable at this point in the

project file. This is also equivalent to:

MY_DEFINES = $${DEFINES}

Page 23: Using Qmake

The second notation allows you to append the contents of the variable to another value

without separating the two with a space. For example, the following will ensure that the final

executable will be given a name that includes the project template being used:

TARGET = myproject_$${TEMPLATE}

Variables can be used to store the contents of environment variables. These can be evaluated at the time that qmake is run, or included in the generated Makefile for evaluation

when the project is built.To obtain the contents of an environment value when qmake is run, use the $$

(...)operator:

DESTDIR = $$(PWD)

message(The project will be installed in $$DESTDIR)

In the above assignment, the value of the PWD environment variable is read when the project

file is processed.

To obtain the contents of an environment value at the time when the generated Makefile is processed, use the $(...) operator:

DESTDIR = $$(PWD)

message(The project will be installed in $$DESTDIR)

DESTDIR = $(PWD)

message(The project will be installed in the value of PWD)

message(when the Makefile is processed.)

In the above assignment, the value of PWD is read immediately when the project file is

processed, but $(PWD) is assigned to DESTDIR in the generated Makefile. This makes the

build process more flexible as long as the environment variable is set correctly when the

Makefile is processed.The special $$[...] operator can be used to access various configuration options that were

set when Qt was built:

message(Qt version: $$[QT_VERSION])

message(Qt is installed in $$[QT_INSTALL_PREFIX])

message(Qt resources can be found in the following locations:)

Page 24: Using Qmake

message(Documentation: $$[QT_INSTALL_DOCS])

message(Header files: $$[QT_INSTALL_HEADERS])

message(Libraries: $$[QT_INSTALL_LIBS])

message(Binary files (executables): $$[QT_INSTALL_BINS])

message(Plugins: $$[QT_INSTALL_PLUGINS])

message(Data files: $$[QT_INSTALL_DATA])

message(Translation files: $$[QT_INSTALL_TRANSLATIONS])

message(Settings: $$[QT_INSTALL_SETTINGS])

message(Examples: $$[QT_INSTALL_EXAMPLES])

message(Demonstrations: $$[QT_INSTALL_DEMOS])

The variables accessible with this operator are typically used to enable third party plugins

and components to be integrated with Qt. For example, a Qt Designer plugin can be

installed alongside Qt Designer's built-in plugins if the following declaration is made in its

project file:

target.path = $$[QT_INSTALL_PLUGINS]/designer

INSTALLS += target

Variable Processing Functionsqmake provides a selection of built-in functions to allow the contents of variables to be

processed. These functions process the arguments supplied to them and return a value, or list of values, as a result. In order to assign a result to a variable, it is necessary to use the$

$ operator with this type of function in the same way used to assign contents of one variable

to another:

HEADERS = model.h

HEADERS += $$OTHER_HEADERS

HEADERS = $$unique(HEADERS)

This type of function should be used on the right-hand side of assignments (i.e, as an

operand).

It is possible to define your own functions for processing the contents of variables. These

functions can be defined in the following way:

Page 25: Using Qmake

defineReplace(functionName){

#function code

}

The following example function takes a variable name as its only argument, extracts a list of values from the variable with the eval() built-in function, and compiles a list of files:

defineReplace(headersAndSources) {

variable = $$1

names = $$eval($$variable)

headers =

sources =

for(name, names) {

header = $${name}.h

exists($$header) {

headers += $$header

}

source = $${name}.cpp

exists($$source) {

sources += $$source

}

}

return($$headers $$sources)

}

Conditional Functionsqmake provides built-in functions that can be used as conditions when writing scopes. These

functions do not return a value, but instead indicate "success" or "failure":

count(options, 2) {

message(Both release and debug specified.)

}

Page 26: Using Qmake

This type of function should be used in conditional expressions only.

It is possible to define your own functions to provide conditions for scopes. The following

example tests whether each file in a list exists and returns true if they all exist, or false if

not:

defineTest(allFiles) {

files = $$ARGS

for(file, files) {

!exists($$file) {

return(false)

}

}

return(true)

}

Adding New Configuration Featuresqmake lets you create your own features that can be included in project files by adding their

names to the list of values specified by the CONFIG variable. Features are collections of

custom functions and definitions in .prf files that can reside in one of many standard

directories. The locations of these directories are defined in a number of places, and qmakechecks each of them in the following order when it looks for .prf files:

1. In a directory listed in the QMAKEFEATURES environment variable; this contains a colon-separated list of directories.

2. In a directory listed in the QMAKEFEATURES property variable; this contains a colon-spearated list of directories.

3. In a features directory residing within a mkspecs directory. mkspecs directories can be located beneath any of the directories listed in the QMAKEPATH environment variable (a colon-separated list of directories). ($QMAKEPATH/mkspecs/<features>)

4. In a features directory residing beneath the directory provided by the QMAKESPECenvironment variable. ($QMAKESPEC/<features>)

5. In a features directory residing in the data_install/mkspecs directory. (data_install/mkspecs/<features>)

6. In a features directory that exists as a sibling of the directory specified by theQMAKESPEC environment variable. ($QMAKESPEC/../<features>)

The following features directories are searched for features files:1. features/unix, features/win32, or features/macx, depending on the platform in

use

2. features/

Page 27: Using Qmake

For example, consider the following assignment in a project file:

CONFIG += myfeatures

With this addition to the CONFIG variable, qmake will search the locations listed above for

the myfeatures.prf file after it has finished parsing your project file. On Unix systems, it

will look for the following file:1. $QMAKEFEATURES/myfeatures.prf (for each directory listed in

the QMAKEFEATURESenvironment variable)

2. $$QMAKEFEATURES/myfeatures.prf (for each directory listed in the QMAKEFEATURESproperty variable)

3. myfeatures.prf (in the project's root directory)

4. $QMAKEPATH/mkspecs/features/unix/myfeatures.prf and$QMAKEPATH/mkspecs/features/myfeatures.prf (for each directory listed in theQMAKEPATH environment variable)

5. $QMAKESPEC/features/unix/myfeatures.prf and$QMAKESPEC/features/myfeatures.prf

6. data_install/mkspecs/features/unix/myfeatures.prf anddata_install/mkspecs/features/myfeatures.prf

7. $QMAKESPEC/../features/unix/myfeatures.prf and$QMAKESPEC/../features/myfeatures.prf

Note: The .prf files must have names in lower case.

Using Precompiled HeadersPrecompiled headers are a performance feature supported by some compilers to compile a

stable body of code, and store the compiled state of the code in a binary file. During

subsequent compilations, the compiler will load the stored state, and continue compiling the

specified file. Each subsequent compilation is faster because the stable code does not need

to be recompiled.qmake supports the use of precompiled headers (PCH) on some platforms and build

environments, including: Windows

o nmake

o Dsp projects (VC 6.0)

o Vcproj projects (VC 7.0 & 7.1)

Mac OS X

o Makefile

o Xcode

Page 28: Using Qmake

Unix

o GCC 3.4 and above

Adding Precompiled Headers to Your Project

Contents of the Precompiled Header File

The precompiled header must contain code which is stable and static throughout your

project. A typical PCH might look like this:Example: stable.h

// Add C includes here

#if defined __cplusplus

// Add C++ includes here

#include <stdlib>

#include <iostream>

#include <vector>

#include <QApplication> // Qt includes

#include <QPushButton>

#include <QLabel>

#include "thirdparty/include/libmain.h"

#include "my_stable_class.h"

...

#endif

Note that a precompiled header file needs to separate C includes from C++ includes, since

the precompiled header file for C files may not contain C++ code.

Project OptionsTo make your project use PCH, you only need to define the PRECOMPILED_HEADER variable in

your project file:

PRECOMPILED_HEADER = stable.h

qmake will handle the rest, to ensure the creation and use of the precompiled header file.

You do not need to include the precompiled header file in HEADERS, as qmake will do this if

the configuration supports PCH.

Page 29: Using Qmake

All platforms that support precompiled headers have the configuration optionprecompile_header set. Using this option, you may trigger conditional blocks in your

project file to add settings when using PCH. For example:

precompile_header:!isEmpty(PRECOMPILED_HEADER) {

DEFINES += USING_PCH

}

Notes on Possible IssuesOn some platforms, the file name suffix for precompiled header files is the same as that for

other object files. For example, the following declarations may cause two different object

files with the same name to be generated:

PRECOMPILED_HEADER = window.h

SOURCES = window.cpp

To avoid potential conflicts like these, it is good practice to ensure that header files that will

be precompiled are given distinctive names.

Example ProjectYou can find the following source code in the examples/qmake/precompile directory in the

Qt distribution:

mydialog.ui

<ui version="4.0" >

<author></author>

<comment></comment>

<exportmacro></exportmacro>

<class>MyDialog</class>

<widget class="QDialog" name="MyDialog" >

<property name="geometry" >

<rect>

<x>0</x>

<y>0</y>

<width>401</width>

<height>70</height>

Page 30: Using Qmake

</rect>

</property>

<property name="windowTitle" >

<string>Mach 2!</string>

</property>

<layout class="QVBoxLayout" >

<property name="margin" >

<number>9</number>

</property>

<property name="spacing" >

<number>6</number>

</property>

<item>

<widget class="QLabel" name="aLabel" >

<property name="text" >

<string>Join the life in the fastlane; - PCH enable your project today! -</string>

</property>

</widget>

</item>

<item>

<widget class="QPushButton" name="aButton" >

<property name="text" >

<string>&amp;Quit</string>

</property>

<property name="shortcut" >

<string>Alt+Q</string>

</property>

</widget>

</item>

</layout>

</widget>

<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>

Page 31: Using Qmake

<resources/>

<connections/>

</ui>

stable.h

/* Add C includes here */

#if defined __cplusplus

/* Add C++ includes here */

# include <iostream>

# include <QApplication>

# include <QPushButton>

# include <QLabel>

#endif

myobject.h

#include <QObject>

class MyObject : public QObject

{

public:

MyObject();

~MyObject();

};

myobject.cpp

#include <iostream>

#include <QDebug>

#include <QObject>

Page 32: Using Qmake

#include "myobject.h"

MyObject::MyObject()

: QObject()

{

std::cout << "MyObject::MyObject()\n";

}

util.cpp

void util_function_does_nothing()

{

// Nothing here...

int x = 0;

++x;

}

main.cpp

#include <QApplication>

#include <QPushButton>

#include <QLabel>

#include "myobject.h"

#include "mydialog.h"

int main(int argc, char **argv)

{

QApplication app(argc, argv);

MyObject obj;

MyDialog dialog;

dialog.connect(dialog.aButton, SIGNAL(clicked()), SLOT(close()));

Page 33: Using Qmake

dialog.show();

return app.exec();

}

precompile.pro

TEMPLATE = app

LANGUAGE = C++

CONFIG += console precompile_header

# Use Precompiled headers (PCH)

PRECOMPILED_HEADER = stable.h

HEADERS = stable.h \

mydialog.h \

myobject.h

SOURCES = main.cpp \

mydialog.cpp \

myobject.cpp \

util.cpp

FORMS = mydialog.ui

qmake ReferenceThis reference is a detailed index of all the variables and function that are available for use in qmakeproject files.

Variable ReferenceThe qmake Variable Reference describes the variables that are recognized by qmake when

configuring the build process for projects.

Function ReferenceThe qmake Function Reference describes the function that can be used to process the

contents of variables defined in project files.

Frequently Used Variables

Page 34: Using Qmake

The following variables are frequently used in project files to describe common aspects of the build process. These are fully described in the Variable Reference.

CONFIG

DEF_FILE

DEFINES

DESTDIR

DISTFILES

DLLDESTDIR

FORMS

FORMS3

GUID

HEADERS

INCLUDEPATH

LEXSOURCES

LIBS

MOC_DIR

OBJECTS_DIR

QT

RCC_DIR

REQUIRES

RESOURCES

SOURCES

SUBDIRS

TARGET

TEMPLATE

TRANSLATIONS

UI_DIR

UI_HEADERS_DIR

UI_SOURCES_DIR

VERSION

YACCSOURCES

Environment Variables and ConfigurationThe Configuring qmake's Environment chapter of this manual describes the environment

variables that qmake uses when configuring the build process.

Page 35: Using Qmake

qmake Variable Referenceqmake's fundamental behavior is influenced by variable declarations that define the build

process of each project. Some of these declare resources, such as headers and source files,

that are common to each platform; others are used to customize the behavior of compilers

and linkers on specific platforms.

Platform-specific variables follow the naming pattern of the variables which they extend or

modify, but include the name of the relevant platform in their name. For example, QMAKE_LIBS can be used to specify a list of libraries that a project needs to link

against, and QMAKE_LIBS_X11 can be used to extend or override this list.

BLD_INF_RULESThis is only used on the Symbian platform.Generic bld.inf file content can be specified withBLD_INF_RULES variables. The section

of bld.inffile where each rule goes is appended toBLD_INF_RULES with a dot.

For example:

my_exports = \

"foo.h /epoc32/include/mylib/foo.h" \

"bar.h /epoc32/include/mylib/bar.h"

BLD_INF_RULES.prj_exports += my_exports

This will add the specified statements to theprj_exports section of the

generated bld.inf file.

It is also possible to add multiple rows in a single block. Each double quoted string will be placed on a new row in the generated bld.inf file.

For example:

myextension = \

"start extension myextension" \

"$${LITERAL_HASH}if defined(WINSCW)" \

"option MYOPTION foo" \

"$${LITERAL_HASH}endif" \

"option MYOPTION bar" \

"end"

BLD_INF_RULES.prj_extensions += myextension

Any rules you define will be added after automatically generated rules in each section.

CONFIG

Page 36: Using Qmake

The CONFIG variable specifies project configuration and compiler options. The values will be

recognized internally by qmake and have special meaning. They are as follows.

These CONFIG values control compilation flags:

Option Description

release The project is to be built in release mode. This is ignored if debug is also specified.

debug The project is to be built in debug mode.

debug_and_release The project is built in bothdebug and release modes. This can have some unexpected side effects (see below

for more information).

build_all If debug_and_release is specified, the project is built in both debug and release modes by default.

ordered When using the subdirstemplate, this option specifies that the directories listed should be processed in

the order in which they are given.

precompile_header Enables support for the use of precompiled headers in projects.

warn_on The compiler should output as many warnings as possible. This is ignored ifwarn_off is specified.

warn_off The compiler should output as few warnings as possible.

Since the debug option overrides the release option when both are defined in

the CONFIG variable, it is necessary to use the debug_and_release option if you want to

allow both debug and release versions of a project to be built. In such a case, the Makefile that qmake generates includes a rule that builds both versions, and this can be invoked in

the following way:

make all

When linking a library, qmake relies on the underlying platform to know what other libraries

this library links against. However, if linking statically, qmake will not get this information

unless we use the followingCONFIG options:

Option Description

create_prl This option enables qmake to track these dependencies. When this option is enabled, qmake will create a file

ending in .prl which will save meta-information about the library (see Library Dependencies for more info).

link_prl When this is enabled, qmake will process all libraries linked to by the application and find their meta-information

(see Library Dependencies for more info).

Please note that create_prl is required whenbuilding a static library, while link_prl is

required when using a static library.

On Windows (or if Qt is configured with -debug_and_release, adding the build_all option

to the CONFIG variable makes this rule the default when building the project, and installation

targets will be created for both debug and release builds.Additionally, adding debug_and_release to theCONFIG variable will cause

both debug and releaseto be defined in the contents of CONFIG. When the project file is

processed, the scopes that test for each value will be processed for both debug and release

Page 37: Using Qmake

modes. The build_pass variable will be set for each of these mode, and you can test for

this to perform build-specific tasks. For example:

build_pass:CONFIG(debug, debug|release) {

unix: TARGET = $$join(TARGET,,,_debug)

else: TARGET = $$join(TARGET,,,d)

}

As a result, it may be useful to define mode-specific variables, such as QMAKE_LFLAGS_RELEASE, instead of general variables, such as QMAKE_LFLAGS, where

possible.

The following options define the application/library type:

Option Description

qt The target is a Qt application/library and requires the Qt library and header files. The proper include

and library paths for the Qt library will automatically be added to the project. This is defined by

default, and can be fine-tuned with the\l{#qt}{QT}variable.

thread The target is a multi-threaded application or library. The proper defines and compiler flags will

automatically be added to the project.

x11 The target is a X11 application or library. The proper include paths and libraries will automatically be

added to the project.

windows The target is a Win32 window application (app only). The proper include paths, compiler flags and

libraries will automatically be added to the project.

console The target is a Win32 console application (app only). The proper include paths, compiler flags and

libraries will automatically be added to the project.

shared The target is a shared object/DLL. The proper include paths, compiler flags and libraries will

automatically be added to the project.

dll

dylib

static The target is a static library (lib only). The proper compiler flags will automatically be added to the

project.staticlib

plugin The target is a plugin (lib only). This enables dll as well.

designer The target is a plugin for Qt Designer.

uic3 Configures qmake to run uic3 on the content of FORMS3 if defined; otherwise the contents

of FORMS will be processed instead.

no_lflags_merge Ensures that the list of libraries stored in theLIBS variable is not reduced to a list of unique values

before it is used.

Page 38: Using Qmake

Option Description

resources Configures qmake to run rcc on the content of RESOURCES if defined.

These options are used to set the compiler flags:

Option Description

3dnow AMD 3DNow! instruction support is enabled.

exceptions Exception support is enabled.

mmx Intel MMX instruction support is enabled.

rtti RTTI support is enabled.

stl STL support is enabled.

sse SSE support is enabled.

sse2 SSE2 support is enabled.

These options define specific features on Windows only:

Option Description

flat When using the vcapp template this will put all the source files into the source group and the header files

into the header group regardless of what directory they reside in. Turning this option off will group the files

within the source/header group depending on the directory they reside. This is turned on by default.

embed_manifest_dll Embeds a manifest file in the DLL created as part of a library project.

embed_manifest_exe Embeds a manifest file in the DLL created as part of an application project.

incremental Used to enable or disable incremental linking in Visual C++, depending on whether this feature is enabled

or disabled by default.

See qmake Platform Notes for more information on the options for embedding manifest files.

These options only have an effect on Mac OS X:

Option Description

ppc Builds a PowerPC binary.

x86 Builds an i386 compatible binary.

app_bundle Puts the executable into a bundle (this is the default).

lib_bundle Puts the library into a library bundle.

The build process for bundles is also influenced by the contents of theQMAKE_BUNDLE_DATA variable.

These options only have an effect on the Symbian platform:

Option Description

stdbinary Builds an Open C binary (i.e. STDDLL, STDEXE, or STDLIB, depending on the target binary type.)

no_icon Doesn't generate resources needed for displaying an icon for executable in application menu (app only).

symbian_test Places mmp files and extension makefiles under test sections in generated bld.inf instead of their regular

sections. Note that this only affects automatically generated bld.inf content; the content added

Page 39: Using Qmake

Option Description

viaBLD_INF_RULES variable is not affected.

localize_deployment Makes lupdate tool add fields for application captions and package file names into

generated .ts files. Qmake generates properly localized.loc and .pkg files based on available

translations. Translation file name bodies must end with underscore and the language code for deployment

localization to work. E.g. myapp_en.ts. Note: All languages supported by Qt are not supported by

Symbian, so some .ts files may be ignored by qmake.

These options have an effect on Linux/Unix platforms:

Option Description

largefile Includes support for large files.

separate_debug_info Puts debugging information for libraries in separate files.

The CONFIG variable will also be checked when resolving scopes. You may assign anything

to this variable.

For example:

CONFIG += qt console newstuff

...

newstuff {

SOURCES += new.cpp

HEADERS += new.h

}

DEFINESqmake adds the values of this variable as compiler C preprocessor macros (-D option).

For example:

DEFINES += USE_MY_STUFF QT_DLL

DEF_FILEThis is only used on Windows when using the app template, and on Symbian when building a

shared DLL.Specifies a .def file to be included in the project. On Symbian a directory may be specified

instead, in which case the real files will be located under the standard Symbian directoriesbwins and eabi.

DEPENDPATHThis variable contains the list of all directories to look in to resolve dependencies. This will be used when crawling through included files.

Page 40: Using Qmake

DEPLOYMENTThis is only used on Windows CE and the Symbian platform.

Specifies which additional files will be deployed. Deployment means the transfer of files from

the development system to the target device or emulator.

Files can be deployed by either creating a Visual Studio project or using the cetestexecutable.

For example:

myFiles.sources = path\*.png

DEPLOYMENT += myFiles

This will upload all PNG images in path to the same directory your build target will be

deployed to.The default deployment target path for Windows CE is %CSIDL_PROGRAM_FILES%\target,

which usually gets expanded to \Program Files\target. For the Symbian platform, the

default target is the application private directory on the drive it is installed to.It is also possible to specify multiple sources to be deployed on target paths. In addition,

different variables can be used for deployment to different directories.

For example:

myFiles.sources = path\file1.ext1 path2\file2.ext1 path3\*

myFiles.path = \some\path\on\device

someother.sources = C:\additional\files\*

someother.path = \myFiles\path2

DEPLOYMENT += myFiles someother

Note: In Windows CE all linked Qt libraries will be deployed to the path specified

bymyFiles.path. On Symbian platform all libraries and executables will always be deployed

to the \sys\bin of the installation drive.

Since the Symbian platform build system automatically moves binaries to certain directories

under the epoc32 directory, custom plugins, executables or dynamically loadable libraries

need special handling. When deploying extra executables or dynamically loadable libraries,

the target path must specify \sys\bin. For plugins, the target path must specify the location where the plugin stub will be deployed to (see the How to Create Qt Plugins document for

more information about plugins). If the binary cannot be found from the indicated source

path, the directory Symbian build process moves the executables to is searched, e.g. \

epoc32\release\armv5\urel.

For example:

Page 41: Using Qmake

customplugin.sources = customimageplugin.dll

customplugin.sources += c:\myplugins\othercustomimageplugin.dll

customplugin.path = imageformats

dynamiclibrary.sources = mylib.dll helper.exe

dynamiclibrary.path = \sys\bin

globalplugin.sources = someglobalimageplugin.dll

globalplugin.path = \resource\qt\plugins\imageformats

DEPLOYMENT += customplugin dynamiclibrary globalplugin

On the Symbian platform, generic PKG file content can also be specified with this variable. You can use either pkg_prerules or pkg_postrules to pass raw data to PKG file. The

strings in pkg_prerules are added before package-body

and pkg_postrules after.pkg_prerules is used for defining vendor information,

dependencies, custom package headers, and the like, while pkg_postrules is used for

custom file deployment and embedded sis directives. The strings defined in pkg_postrules or pkg_prerules are not parsed by qmake, so they should be in a format

understood by Symbian package generation tools. Please consult the Symbian platform

documentation for correct syntax.

For example, to deploy DLL and add a new dependency:

somelib.sources = somelib.dll

somelib.path = \sys\bin

somelib.pkg_prerules = "(0x12345678), 2, 2, 0, {\"Some Package\"}" \

"(0x87654321), 1, *, * ~ 2, 2, 0, {\"Some Other Package\"}"

justdep.pkg_prerules = "(0xAAAABBBB), 0, 2, 0, {\"My Framework\"}"

DEPLOYMENT += somelib justdep

Please note that pkg_prerules can also replace default statements in pkg file. If no

pkg_prerules is defined, qmake makes sure that PKG file syntax is correct and it contains all

mandatory statements such as: languages, for example 

&EN,FR

package-header, for example #{"MyApp-EN", "MyApp-FR"}, (0x1000001F), 1, 2, 3, TYPE=SA

localized and unique vendor, for example %{"Vendor-EN", ..., "Vendor-FR"} :"Unique vendor name"

Page 42: Using Qmake

If you decide to override any of these statements, you need to pay attention that also other

statements stay valid. For example if you override languages statement, you must override

also package-header statement and all other statements which are language specific.

On the Symbian platform, three separate PKG files are generated: <app>_template.pkg - For application SIS file. Rules suffix: .main

<app>_installer.pkg - For smart installer SIS file. Rules suffix: .installer

<app>_stub.pkg - For ROM stubs. Rules suffix: .stub

pkg_prerules and pkg_postrules given without rules suffix will intelligently apply to each

of these files, but rules can also be targeted to only one of above files by appending listed

rules suffix to the variable name:

my_note.pkg_postrules.installer = "\"myinstallnote.txt\" - \"\", FILETEXT, TEXTCONTINUE"

DEPLOYMENT += my_note

On the Symbian platform, the default_deployment item specifies default platform and

package dependencies. Those dependencies can be selectively disabled if alternative

dependencies need to be defined - e.g. if a specific device is required to run the application

or more languages need to be supported by the package file. The supporteddefault_deployment rules that can be disabled are:

pkg_depends_qt

pkg_depends_webkit

pkg_platform_dependencies

For example:

default_deployment.pkg_prerules -= pkg_platform_dependencies

my_deployment.pkg_prerules = "[0x11223344],0,0,0,{\"SomeSpecificDeviceID\"}"

DEPLOYMENT += my_deployment

On the Symbian platform, a default deployment is generated for all application projects. You can modify the autogenerated default deployment via following DEPLOYMENT variable values:

default_bin_deployment - Application executable

default_resource_deployment - Application resources, including icon

default_reg_deployment - Application registration file

For example:

Page 43: Using Qmake

DEPLOYMENT -= default_bin_deployment default_resource_deployment default_reg_deployment

This will entirely remove the default application deployment.On the Symbian platform, you can specify file specific install options with .flags modifier.

Please consult the Symbian platform documentation for supported options.

For example:

default_bin_deployment.flags += FILERUN RUNINSTALL

dep_note.sources = install_note.txt

dep_note.flags = FILETEXT TEXTEXIT

DEPLOYMENT += dep_note

This will show a message box that gives user an option to cancel the installation and then

automatically runs the application after installation is complete.Note: Automatically running the applications after install may require signing the package

with better than self-signed certificate, depending on the phone model. Additionally, some

tools such as Runonphone may not work properly with sis packages that automatically run

the application upon install.

On the Symbian platform, the default package name and the default name that appears in application menu is derived from the TARGET variable. Often the default is not optimal for

displaying to end user. To set a better display name for these purposes, useDEPLOYMENT.display_name variable:

DEPLOYMENT.display_name = My Qt App

On the Symbian platform, you can use DEPLOYMENT.installer_header variable to generate

smart installer wrapper for your application. If you specify just UID of the installer package

as the value, then installer package name and version will be autogenerated:

DEPLOYMENT.installer_header = 0x12345678

If autogenerated values are not suitable, you can also specify the sis header yourself using

this variable:

DEPLOYMENT.installer_header = "$${LITERAL_HASH}{\"My Application Installer\"},(0x12345678),1,0,0"

Page 44: Using Qmake

DEPLOYMENT_PLUGINThis is only used on Windows CE and the Symbian platform.

This variable specifies the Qt plugins that will be deployed. All plugins available in Qt can be explicitly deployed to the device. See Static Plugins for a complete list.

Note: In Windows CE, No plugins will be deployed automatically. If the application depends

on plugins, these plugins have to be specified manually.Note: On the Symbian platform, all plugins supported by this variable will be deployed by

default with Qt libraries, so generally using this variable is not needed.

For example:

DEPLOYMENT_PLUGIN += qjpeg

This will upload the jpeg imageformat plugin to the plugins directory on the Windows CE

device.

DESTDIRSpecifies where to put the target file.

For example:

DESTDIR = ../../lib

DESTDIR_TARGETThis variable is set internally by qmake, which is basically the DESTDIR variable with

theTARGET variable appened at the end. The value of this variable is typically handled

by qmakeor qmake.conf and rarely needs to be modified.

DLLDESTDIRSpecifies where to copy the target dll.

DISTFILESThis variable contains a list of files to be included in the dist target. This feature is supported

by UnixMake specs only.

For example:

DISTFILES += ../program.txt

DSP_TEMPLATEThis variable is set internally by qmake, which specifies where the dsp template file for

basing generated dsp files is stored. The value of this variable is typically handled by qmakeor qmake.conf and rarely needs to be modified.

Page 45: Using Qmake

FORMSThis variable specifies the UI files (see Qt Designer) to be processed through uic before

compiling. All dependencies, headers and source files required to build these UI files will

automatically be added to the project.

For example:

FORMS = mydialog.ui \

mywidget.ui \

myconfig.ui

If FORMS3 is defined in your project, then this variable must contain forms for uic, and not

uic3. If CONFIG contains uic3, and FORMS3 is not defined, the this variable must contain only

uic3 type forms.

FORMS3This variable specifies the old style UI files to be processed through uic3 before compiling,

when CONFIG contains uic3. All dependencies, headers and source files required to build

these UI files will automatically be added to the project.

For example:

FORMS3 = my_uic3_dialog.ui \

my_uic3_widget.ui \

my_uic3_config.ui

GUIDSpecifies the GUID that is set inside a .vcproj file. The GUID is usually randomly

determined. However, should you require a fixed GUID, it can be set using this variable.This variable is specific to .vcproj files only; it is ignored otherwise.

HEADERSDefines the header files for the project.qmake will generate dependency information (unless -nodepend is specified on

the command line) for the specified headers. qmake will also automatically detect if moc is

required by the classes in these headers, and add the appropriate dependencies and files to

the project for generating and linking the moc files.

For example:

HEADERS = myclass.h \

login.h \

Page 46: Using Qmake

mainwindow.h

See also SOURCES.

ICONThis variable is used only in MAC and the Symbian platform to set the application icon. Please see the application icon documentation for more information.

INCLUDEPATHThis variable specifies the #include directories which should be searched when compiling

the project. Use ';' or a space as the directory separator.

For example:

INCLUDEPATH = c:/msdev/include d:/stl/include

To specify a path containing spaces, quote the path using the technique mentioned in theqmake Project Files document. For example, paths with spaces can be specified on

Windows and Unix platforms by using the quote() function in the following way:

win32:INCLUDEPATH += $$quote(C:/mylibs/extra headers)

unix:INCLUDEPATH += $$quote(/home/user/extra headers)

INSTALLSThis variable contains a list of resources that will be installed when make install or a

similar installation procedure is executed. Each item in the list is typically defined with

attributes that provide information about where it will be installed.For example, the following target.path definition describes where the build target will be

installed, and the INSTALLS assignment adds the build target to the list of existing resources

to be installed:

target.path += $$[QT_INSTALL_PLUGINS]/imageformats

INSTALLS += target

Note that qmake will skip files that are executable. If you need to install executable files, you

can unset the files' executable flags.

LEXIMPLSThis variable contains a list of lex implementation files. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

Page 47: Using Qmake

LEXOBJECTSThis variable contains the names of intermediate lex object files.The value of this variable is typically handled by qmake and rarely needs to be modified.

LEXSOURCESThis variable contains a list of lex source files. All dependencies, headers and source files

will automatically be added to the project for building these lex files.

For example:

LEXSOURCES = lexer.l

LIBSThis variable contains a list of libraries to be linked into the project. You can use the Unix -l(library) and -L (library path) flags and qmake will do the correct thing with these libraries

on Windows and the Symbian platform (namely this means passing the full path of the

library to the linker). The only limitation to this is the library must exist, for qmake to find which directory a -l lib lives in.

For example:

unix:LIBS += -L/usr/local/lib -lmath

win32:LIBS += c:/mylibs/math.lib

To specify a path containing spaces, quote the path using the technique mentioned in theqmake Project Files document. For example, paths with spaces can be specified on

Windows and Unix platforms by using the quote() function in the following way:

win32:LIBS += $$quote(C:/mylibs/extra libs/extra.lib)

unix:LIBS += $$quote(-L/home/user/extra libs) -lextra

Note: On Windows, specifying libraries with the -l option, as in the above example, will

cause the library with the highest version number to be used; for example, libmath2.libcould potentially be used instead of libmathlib. To avoid this

ambiguity, we recommend that you explicitly specify the library to be used by including the .lib file name suffix.

Note: On the Symbian platform, the build system makes a distinction between shared and

static libraries. In most cases, qmake will figure out which library you are refering to, but in

some cases you may have to specify it explicitly to get the expected behavior. This typically

happens if you are building a library and using it in the same project. To specify that the

library is either shared or static, add a ".dll" or ".lib" suffix, respectively, to the library name.

Page 48: Using Qmake

By default, the list of libraries stored in LIBS is reduced to a list of unique names before it is

used. To change this behavior, add the no_lflags_merge option to the CONFIG variable:

CONFIG += no_lflags_merge

LITERAL_HASHThis variable is used whenever a literal hash character (#) is needed in a variable

declaration, perhaps as part of a file name or in a string passed to some external

application.

For example:

# To include a literal hash character, use the $$LITERAL_HASH variable:

urlPieces = http://qt.nokia.com/doc/4.0/qtextdocument.html pageCount

message($$join(urlPieces, $$LITERAL_HASH))

By using LITERAL_HASH in this way, the # character can be used to construct a URL for

themessage() function to print to the console.

MAKEFILEThis variable specifies the name of the Makefile which qmake should use when outputting

the dependency information for building a project. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

Note: On the Symbian platform, this variable is ignored.

MAKEFILE_GENERATORThis variable contains the name of the Makefile generator to use when generating a Makefile. The value of this variable is typically handled internally by qmake and rarely needs

to be modified.

MMP_RULESThis is only used on the Symbian platform.

Generic MMP file content can be specified with this variable.

For example:

MMP_RULES += "DEFFILE hello.def"

This will add the specified statement to the end of the generated MMP file.

It is also possible to add multiple rows in a single block. Each double quoted string will be

placed on a new row in the generated MMP file.

For example:

Page 49: Using Qmake

myBlock = \

"START RESOURCE foo.rss" \

"TARGET bar" \

"TARGETPATH private\10001234" \

"HEADER" \

"LANG 01" \

"UID 0x10002345 0x10003456" \

"END"

MMP_RULES += myBlock

If you need to include a hash (#) character inside the MMP_RULES statement, it can be done

with the variable LITERAL_HASH as follows:

myIfdefBlock = \

"$${LITERAL_HASH}ifdef WINSCW" \

"DEFFILE hello_winscw.def" \

"$${LITERAL_HASH}endif"

MMP_RULES += myIfdefBlock

There is also a convenience function for adding conditional rules called addMMPRules.

Suppose you need certain functionality to require different library depending on architecture. This can be specified with addMMPRules as follows:

# Set conditional libraries

LIB.MARM = "LIBRARY myarm.lib"

LIB.WINSCW = "LIBRARY mywinscw.lib"

LIB.default = "LIBRARY mydefault.lib"

# Add the conditional MMP rules

MYCONDITIONS = MARM WINSCW

MYVARIABLES = LIB

Page 50: Using Qmake

addMMPRules(MYCONDITIONS, MYVARIABLES)

Note: You should not use this variable to add MMP statements that are explicitly supported

by their own variables, such as TARGET.EPOCSTACKSIZE. Doing so could result in duplicate

statements in the MMP file.

MOC_DIRThis variable specifies the directory where all intermediate moc files should be placed.

For example:

unix:MOC_DIR = ../myproject/tmp

win32:MOC_DIR = c:/myproject/tmp

OBJECTSThis variable is generated from the SOURCES variable. The extension of each source file will

have been replaced by .o (Unix) or .obj (Win32). The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

OBJECTS_DIRThis variable specifies the directory where all intermediate objects should be placed.

For example:

unix:OBJECTS_DIR = ../myproject/tmp

win32:OBJECTS_DIR = c:/myproject/tmp

OBJMOCThis variable is set by qmake if files can be found that contain

the Q_OBJECT macro. OBJMOCcontains the name of all intermediate moc object files. The

value of this variable is typically handled by qmake or qmake.conf and rarely needs to be

modified.

POST_TARGETDEPSAll libraries that the target depends on can be listed in this variable. Some backends do not

support this, these include MSVC Dsp, and ProjectBuilder .pbproj files. Generally this is

supported internally by these build tools, this is useful for explicitly listing dependant static

libraries.This list will go after all builtin (and $$PRE_TARGETDEPS) dependencies.

PRE_TARGETDEPS

Page 51: Using Qmake

All libraries that the target depends on can be listed in this variable. Some backends do not

support this, these include MSVC Dsp, and ProjectBuilder .pbproj files. Generally this is

supported internally by these build tools, this is useful for explicitly listing dependant static

libraries.

This list will go before all builtin dependencies.

PRECOMPILED_HEADERThis variable indicates the header file for creating a precompiled header file, to increase the

compilation speed of a project. Precompiled headers are currently only supported on some

platforms (Windows - all MSVC project types, Mac OS X - Xcode, Makefile, Unix - gcc 3.3 and

up).

On other platforms, this variable has different meaning, as noted below.

This variable contains a list of header files that require some sort of pre-compilation step

(such as with moc). The value of this variable is typically handled by qmake or qmake.confand rarely needs to be modified.

PWDThis variable contains the full path leading to the directory where the qmake project file

(project.pro) is located.

OUT_PWDThis variable contains the full path leading to the directory where qmake places the

generated Makefile.

QMAKEThis variable contains the name of the qmake program itself and is placed in generated

Makefiles. The value of this variable is typically handled by qmake or qmake.conf and rarely

needs to be modified.

QMAKESPECThis variable contains the name of the qmake configuration to use when generating

Makefiles. The value of this variable is typically handled by qmake and rarely needs to be

modified.Use the QMAKESPEC environment variable to override the qmake configuration. Note that, due

to the way qmake reads project files, setting the QMAKESPEC environment variable from

within a project file will have no effect.

QMAKE_APP_FLAGThis variable is empty unless the app TEMPLATE is specified. The value of this variable is

typically handled by qmake or qmake.conf and rarely needs to be modified. Use the

following instead:

app {

Page 52: Using Qmake

# Conditional code for 'app' template here

}

QMAKE_APP_OR_DLLThis variable is empty unless the app or dll TEMPLATE is specified. The value of this

variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_AR_CMDThis is used on Unix platforms only.

This variable contains the command for invoking the program which creates, modifies and extracts archives. The value of this variable is typically handled by qmake or qmake.confand

rarely needs to be modified.

QMAKE_BUNDLE_DATAThis variable is used to hold the data that will be installed with a library bundle, and is often

used to specify a collection of header files.For example, the following lines add path/to/header_one.h and path/to/header_two.h to

a group containing information about the headers supplied with the framework:

FRAMEWORK_HEADERS.version = Versions

FRAMEWORK_HEADERS.files = path/to/header_one.h path/to/header_two.h

FRAMEWORK_HEADERS.path = Headers

QMAKE_BUNDLE_DATA += FRAMEWORK_HEADERS

The last line adds the information about the headers to the collection of resources that will

be installed with the library bundle.Library bundles are created when the lib_bundle option is added to the CONFIG variable.

See qmake Platform Notes for more information about creating library bundles.

This is used on Mac OS X only.

QMAKE_BUNDLE_EXTENSIONThis variable defines the extension to be used for library bundles. This allows frameworks to be created with custom extensions instead of the standard .framework directory name

extension.

For example, the following definition will result in a framework with the .myframeworkextension:

QMAKE_BUNDLE_EXTENSION = .myframework

Page 53: Using Qmake

This is used on Mac OS X only.

QMAKE_CCThis variable specifies the C compiler that will be used when building projects containing C

source code. Only the file name of the compiler executable needs to be specified as long as it is on a path contained in the PATH variable when the Makefile is processed.

QMAKE_CFLAGS_DEBUGThis variable contains the flags for the C compiler in debug mode.The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_CFLAGS_MTThis variable contains the compiler flags for creating a multi-threaded application or when

the version of Qt that you link against is a multi-threaded statically linked library. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_CFLAGS_MT_DBGThis variable contains the compiler flags for creating a debuggable multi-threaded

application or when the version of Qt that you link against is a debuggable multi-threaded

statically linked library. The value of this variable is typically handled by qmake orqmake.conf and rarely needs to be modified.

QMAKE_CFLAGS_MT_DLLThis is used on Windows only.

This variable contains the compiler flags for creating a multi-threaded dll or when the

version of Qt that you link against is a multi-threaded dll. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_CFLAGS_MT_DLLDBGThis is used on Windows only.

This variable contains the compiler flags for creating a debuggable multi-threaded dll or

when the version of Qt that you link against is a debuggable multi-threaded statically linked library. The value of this variable is typically handled by qmake or qmake.conf and rarely

needs to be modified.

QMAKE_CFLAGS_RELEASEThis variable contains the compiler flags for creating a non-debuggable application. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be

modified.

QMAKE_CFLAGS_SHLIBThis is used on Unix platforms only.

This variable contains the compiler flags for creating a shared library. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_CFLAGS_THREAD

Page 54: Using Qmake

This variable contains the compiler flags for creating a multi-threaded application. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_CFLAGS_WARN_OFFThis variable is not empty if the warn_off CONFIG option is specified. The value of this

variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_CFLAGS_WARN_ONThis variable is not empty if the warn_on CONFIG option is specified. The value of this

variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_CLEANThis variable contains any files which are not generated files (such as moc and uic

generated files) and object files that should be removed when using "make clean".

QMAKE_CXXThis variable specifies the C++ compiler that will be used when building projects containing

C++ source code. Only the file name of the compiler executable needs to be specified as long as it is on a path contained in the PATH variable when the Makefile is processed.

QMAKE_CXXFLAGSThis variable contains the C++ compiler flags that are used when building a project. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be

modified. The flags specific to debug and release modes can be adjusted by modifying theQMAKE_CXXFLAGS_DEBUG and QMAKE_CXXFLAGS_RELEASE variables, respectively.

Note: On the Symbian platform, this variable can be used to pass architecture specific

options to each compiler in the Symbian build system. For example:

QMAKE_CXXFLAGS.CW += -O2

QMAKE_CXXFLAGS.ARMCC += -O0

For more information, see qmake Platform Notes.

QMAKE_CXXFLAGS_DEBUGThis variable contains the C++ compiler flags for creating a debuggable application. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be

modified.

QMAKE_CXXFLAGS_MTThis variable contains the C++ compiler flags for creating a multi-threaded application. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be

modified.

QMAKE_CXXFLAGS_MT_DBG

Page 55: Using Qmake

This variable contains the C++ compiler flags for creating a debuggable multi-threaded application. The value of this variable is typically handled by qmake or qmake.conf and

rarely needs to be modified.

QMAKE_CXXFLAGS_MT_DLLThis is used on Windows only.

This variable contains the C++ compiler flags for creating a multi-threaded dll. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_CXXFLAGS_MT_DLLDBGThis is used on Windows only.

This variable contains the C++ compiler flags for creating a multi-threaded debuggable dll. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to

be modified.

QMAKE_CXXFLAGS_RELEASEThis variable contains the C++ compiler flags for creating an application. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_CXXFLAGS_SHLIBThis variable contains the C++ compiler flags for creating a shared library. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_CXXFLAGS_THREADThis variable contains the C++ compiler flags for creating a multi-threaded application. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be

modified.

QMAKE_CXXFLAGS_WARN_OFFThis variable contains the C++ compiler flags for suppressing compiler warnings. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_CXXFLAGS_WARN_ONThis variable contains C++ compiler flags for generating compiler warnings. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_DISTCLEANThis variable removes extra files upon the invocation of make distclean.

QMAKE_EXTENSION_SHLIBThis variable contains the extention for shared libraries. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

Note that platform-specific variables that change the extension will override the contents of

this variable.

QMAKE_EXT_MOC

Page 56: Using Qmake

This variable changes the extention used on included moc files.See also File Extensions.

QMAKE_EXT_UIThis variable changes the extention used on /e Designer UI files.See also File Extensions.

QMAKE_EXT_PRLThis variable changes the extention used on created PRL files.See also File Extensions, Library Dependencies.

QMAKE_EXT_LEXThis variable changes the extention used on files given to lex.See also File Extensions, LEXSOURCES.

QMAKE_EXT_YACCThis variable changes the extention used on files given to yacc.See also File Extensions, YACCSOURCES.

QMAKE_EXT_OBJThis variable changes the extention used on generated object files.See also File Extensions.

QMAKE_EXT_CPPThis variable changes the interpretation of all suffixes in this list of values as files of type C+

+ source code.See also File Extensions.

QMAKE_EXT_HThis variable changes the interpretation of all suffixes in this list of values as files of type C

header files.See also File Extensions.

QMAKE_EXTRA_COMPILERSThis variable contains the extra compilers/preprocessors that have been addedSee also Customizing Makefile Output

QMAKE_EXTRA_TARGETSThis variable contains the extra targets that have been addedSee also Customizing Makefile Output

QMAKE_FAILED_REQUIREMENTSThis variable contains the list of requirements that were failed to be met when qmake was

used. For example, the sql module is needed and wasn't compiled into Qt. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

Page 57: Using Qmake

QMAKE_FILETAGSThis variable contains the file tags needed to be entered into the Makefile, such as SOURCES and HEADERS. The value of this variable is typically handled by qmake orqmake.conf and

rarely needs to be modified.

QMAKE_FRAMEWORK_BUNDLE_NAMEIn a framework project, this variable contains the name to be used for the framework that is

built.By default, this variable contains the same value as the TARGET variable.

See qmake Platform Notes for more information about creating frameworks and library

bundles.

This is used on Mac OS X only.

QMAKE_FRAMEWORK_VERSIONFor projects where the build target is a Mac OS X framework, this variable is used to specify

the version number that will be applied to the framework that is built.By default, this variable contains the same value as the VERSION variable.

See qmake Platform Notes for more information about creating frameworks.

This is used on Mac OS X only.

QMAKE_INCDIRThis variable contains the location of all known header files to be added to INCLUDEPATH

when building an application. The value of this variable is typically handled by qmake orqmake.conf and rarely needs to be modified.

QMAKE_INCDIR_EGLThis variable contains the location of EGL header files to be added to INCLUDEPATH when

building an application with OpenGL/ES or OpenVG support. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_INCDIR_OPENGLThis variable contains the location of OpenGL header files to be added to INCLUDEPATH

when building an application with OpenGL support. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

If the OpenGL implementation uses EGL (most OpenGL/ES systems), thenQMAKE_INCDIR_EGL may also need to be set.

QMAKE_INCDIR_OPENGL_ES1, QMAKE_INCDIR_OPENGL_ES2These variables contain the location of OpenGL headers files to be added to INCLUDEPATH

when building an application with OpenGL ES 1 or OpenGL ES 2 support respectively.The value of this variable is typically handled by qmake or qmake.conf and rarely needs to

be modified.

If the OpenGL implementation uses EGL (most OpenGL/ES systems), thenQMAKE_INCDIR_EGL may also need to be set.

Page 58: Using Qmake

QMAKE_INCDIR_OPENVGThis variable contains the location of OpenVG header files to be added to INCLUDEPATH

when building an application with OpenVG support. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

If the OpenVG implementation uses EGL then QMAKE_INCDIR_EGL may also need to be set.

QMAKE_INCDIR_QTThis variable contains the location of all known header file paths to be added to

INCLUDEPATH when building a Qt application. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_INCDIR_THREADThis variable contains the location of all known header file paths to be added to

INCLUDEPATH when building a multi-threaded application. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_INCDIR_X11This is used on Unix platforms only.

This variable contains the location of X11 header file paths to be added to INCLUDEPATH

when building a X11 application. The value of this variable is typically handled by qmake orqmake.conf and rarely needs to be modified.

QMAKE_INFO_PLISTThis is used on Mac OS X platforms only.This variable contains the name of the property list file, .plist, you would like to include in

your Mac OS X application bundle.In the .plist file, you can define some variables, e.g., @EXECUTABLE@, which qmake will

replace with the actual executable name. Other variables include @ICON@,

@TYPEINFO@,@LIBRARY@, and @[email protected]: Most of the time, the default Info.plist is good enough.

QMAKE_LFLAGSThis variable contains a general set of flags that are passed to the linker. If you need to

change the flags used for a particular platform or type of project, use one of the specialized

variables for that purpose instead of this variable.

QMAKE_LFLAGS_CONSOLEThis is used on Windows only.

This variable contains link flags when building console programs. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LFLAGS_CONSOLE_DLLThis is used on Windows only.

This variable contains link flags when building console dlls. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

Page 59: Using Qmake

QMAKE_LFLAGS_DEBUGThis variable contains link flags when building debuggable applications. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LFLAGS_PLUGINThis variable contains link flags when building plugins. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LFLAGS_RPATHThis is used on Unix platforms only.

Library paths in this definition are added to the executable at link time so that the added

paths will be preferentially searched at runtime.

QMAKE_LFLAGS_QT_DLLThis variable contains link flags when building programs that use the Qt library built as a dll. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to

be modified.

QMAKE_LFLAGS_RELEASEThis variable contains link flags when building applications for release. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LFLAGS_SHAPPThis variable contains link flags when building applications which are using the app template. The value of this variable is typically handled

by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LFLAGS_SHLIBThis variable contains link flags when building shared libraries The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LFLAGS_SONAMEThis variable specifies the link flags to set the name of shared objects, such as .so or .dll. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to

be modified.

QMAKE_LFLAGS_THREADThis variable contains link flags when building multi-threaded projects. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LFLAGS_WINDOWSThis is used on Windows only.

This variable contains link flags when building Windows GUI projects (i.e. non-console applications). The value of this variable is typically handled by qmake or qmake.conf and

rarely needs to be modified.

Page 60: Using Qmake

QMAKE_LFLAGS_WINDOWS_DLLThis is used on Windows only.

This variable contains link flags when building Windows DLL projects. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LIBDIRThis variable contains the location of all known library directories.The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LIBDIR_FLAGSThis is used on Unix platforms only.

This variable contains the location of all library directory with -L prefixed. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LIBDIR_EGLThis variable contains the location of the EGL library directory, when EGL is used with

OpenGL/ES or OpenVG. The value of this variable is typically handled by qmake orqmake.conf and rarely needs to be modified.

QMAKE_LIBDIR_OPENGLThis variable contains the location of the OpenGL library directory.The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

If the OpenGL implementation uses EGL (most OpenGL/ES systems), thenQMAKE_LIBDIR_EGL may also need to be set.

QMAKE_LIBDIR_OPENVGThis variable contains the location of the OpenVG library directory. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

If the OpenVG implementation uses EGL, then QMAKE_LIBDIR_EGL may also need to be set.

QMAKE_LIBDIR_QTThis variable contains the location of the Qt library directory.The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LIBDIR_X11This is used on Unix platforms only.

This variable contains the location of the X11 library directory.The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LIBSThis variable contains all project libraries. The value of this variable is typically handled byqmake or qmake.conf and rarely needs to be modified.

QMAKE_LIBS_CONSOLEThis Windows-specific variable is no longer used.

Page 61: Using Qmake

Prior to Qt 4.2, this variable was used to list the libraries that should be linked against when building a console application project on Windows. QMAKE_LIBS_WINDOW should now be

used instead.

QMAKE_LIBS_EGLThis variable contains all EGL libraries when building Qt with OpenGL/ES or OpenVG. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be

modified. The usual value is -lEGL.

QMAKE_LIBS_OPENGLThis variable contains all OpenGL libraries. The value of this variable is typically handled byqmake or qmake.conf and rarely needs to be modified.

If the OpenGL implementation uses EGL (most OpenGL/ES systems), then QMAKE_LIBS_EGLmay also need to be set.

QMAKE_LIBS_OPENGL_QTThis variable contains all OpenGL Qt libraries.The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LIBS_OPENGL_ES1, QMAKE_LIBS_OPENGL_ES2These variables contain all the OpenGL libraries for OpenGL ES 1 and OpenGL ES 2.The value of these variables is typically handled by qmake or qmake.conf and rarely needs

to be modified.

If the OpenGL implementation uses EGL (most OpenGL/ES systems), then QMAKE_LIBS_EGLmay also need to be set.

QMAKE_LIBS_OPENVGThis variable contains all OpenVG libraries. The value of this variable is typically handled byqmake or qmake.conf and rarely needs to be modified. The usual value is -lOpenVG.

Some OpenVG engines are implemented on top of OpenGL. This will be detected at configure time and QMAKE_LIBS_OPENGL will be implicitly added

to QMAKE_LIBS_OPENVG wherever the OpenVG libraries are linked.

If the OpenVG implementation uses EGL, then QMAKE_LIBS_EGL may also need to be set.

QMAKE_LIBS_QTThis variable contains all Qt libraries.The value of this variable is typically handled by qmakeor qmake.conf and rarely needs to be modified.

QMAKE_LIBS_QT_DLLThis is used on Windows only.

This variable contains all Qt libraries when Qt is built as a dll. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LIBS_QT_OPENGL

Page 62: Using Qmake

This variable contains all the libraries needed to link against if OpenGL support is turned on. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to

be modified.

QMAKE_LIBS_QT_THREADThis variable contains all the libraries needed to link against if thread support is turned on. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to

be modified.

QMAKE_LIBS_RTThis is used with Borland compilers only.

This variable contains the runtime library needed to link against when building an application. The value of this variable is typically handled by qmake or qmake.conf and

rarely needs to be modified.

QMAKE_LIBS_RTMTThis is used with Borland compilers only.

This variable contains the runtime library needed to link against when building a multi-

threaded application. The value of this variable is typically handled by qmake or qmake.confand rarely needs to be modified.

QMAKE_LIBS_THREADThis is used on Unix and Symbian platforms only.

This variable contains all libraries that need to be linked against when building a multi-

threaded application. The value of this variable is typically handled by qmake or qmake.confand rarely needs to be modified.

QMAKE_LIBS_WINDOWSThis is used on Windows only.

This variable contains all windows libraries.The value of this variable is typically handled byqmake or qmake.conf and rarely needs to be modified.

QMAKE_LIBS_X11This is used on Unix platforms only.

This variable contains all X11 libraries.The value of this variable is typically handled byqmake or qmake.conf and rarely needs to be modified.

QMAKE_LIBS_X11SMThis is used on Unix platforms only.

This variable contains all X11 session management libraries. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_LIB_FLAGThis variable is not empty if the lib template is specified. The value of this variable is

typically handled by qmake or qmake.conf and rarely needs to be modified.

Page 63: Using Qmake

QMAKE_LINK_SHLIB_CMDThis variable contains the command to execute when creating a shared library. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_POST_LINKThis variable contains the command to execute after linking the TARGET together. This

variable is normally empty and therefore nothing is executed, additionally some backends

will not support this - mostly only Makefile backends.

QMAKE_PRE_LINKThis variable contains the command to execute before linking the TARGET together. This

variable is normally empty and therefore nothing is executed, additionally some backends

will not support this - mostly only Makefile backends.

QMAKE_LN_SHLIBThis variable contains the command to execute when creating a link to a shared library. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be

modified.

QMAKE_MAC_SDKThis variable is used on Mac OS X when building universal binaries. This process is described in more detail in the Deploying an Application on Mac OS X document.

QMAKE_MACOSX_DEPLOYMENT_TARGETThis variable only has an effect when building on Mac OS X. On that platform, the variable

will be forwarded to the MACOSX_DEPLOYMENT_TARGET environment variable, which is interpreted by the compiler or linker. For more information, see the Deploying an Application

on Mac OS X document.

QMAKE_MAKEFILEThis variable contains the name of the Makefile to create. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_MOC_SRCThis variable contains the names of all moc source files to generate and include in the project. The value of this variable is typically handled by qmake or qmake.conf and rarely

needs to be modified.

QMAKE_QMAKEThis variable contains the location of qmake if it is not in the path. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_QT_DLLThis variable is not empty if Qt was built as a dll. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

Page 64: Using Qmake

QMAKE_RESOURCE_FLAGSThis variable is used to customize the list of options passed to the Resource Compiler in

each of the build rules where it is used. For example, the following line ensures that the -threshold and -compress options are used with particular values each time that rcc is

invoked:

QMAKE_RESOURCE_FLAGS += -threshold 0 -compress 9

QMAKE_RPATHThis is used on Unix platforms only.Is equivalent to QMAKE_LFLAGS_RPATH.

QMAKE_RPATHDIRThis is used on Unix platforms only.

A list of library directory paths, these paths are added to the executable at link time so that

the paths will be preferentially searched at runtime.

QMAKE_RUN_CCThis variable specifies the individual rule needed to build an object. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_RUN_CC_IMPThis variable specifies the individual rule needed to build an object. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_RUN_CXXThis variable specifies the individual rule needed to build an object. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_RUN_CXX_IMPThis variable specifies the individual rule needed to build an object. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_TARGETThis variable contains the name of the project target. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

QMAKE_UICThis variable contains the location of uic if it is not in the path. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

It can be used to specify arguments to uic as well, such as additional plugin paths. For

example:

Page 65: Using Qmake

QMAKE_UIC = uic -L /path/to/plugin

QTThe values stored in the QT variable control which of the Qt modules are used by your

project.The table below shows the options that can be used with the QT variable and the features

that are associated with each of them:

Option Features

core (included by default) QtCore module

gui (included by default) QtGui module

network QtNetwork module

opengl QtOpenGL module

phonon Phonon Multimedia Framework

sql QtSql module

svg QtSvg module

xml QtXml module

webkit WebKit integration

qt3support Qt3Support module

By default, QT contains both core and gui, ensuring that standard GUI applications can be

built without further configuration.If you want to build a project without the QtGui module, you need to exclude the gui value

with the "-=" operator; the following line will result in a minimal Qt project being built:

QT -= gui # Only the core module is used.

Note that adding the opengl option to the QT variable automatically causes the equivalent

option to be added to the CONFIG variable. Therefore, for Qt applications, it is not necessary

to add the opengl option to both CONFIG and QT.

QTPLUGINThis variable contains a list of names of static plugins that are to be compiled with an

application so that they are available as built-in resources.

QT_VERSIONThis variable contains the current version of Qt.

QT_MAJOR_VERSIONThis variable contains the current major version of Qt.

Page 66: Using Qmake

QT_MINOR_VERSIONThis variable contains the current minor version of Qt.

QT_PATCH_VERSIONThis variable contains the current patch version of Qt.

RC_FILEThis variable contains the name of the resource file for the application. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

RCC_DIRThis variable specifies the directory where all intermediate resource files should be placed.

For example:

unix:RCC_DIR = ../myproject/resources

win32:RCC_DIR = c:/myproject/resources

REQUIRESThis is a special variable processed by qmake. If the contents of this variable do not appear

in CONFIG by the time this variable is assigned, then a minimal Makefile will be generated

that states what dependencies (the values assigned to REQUIRES) are missing.

This is mainly used in Qt's build system for building the examples.

RESOURCESThis variable contains the name of the resource collection file (qrc) for the application. Further information about the resource collection file can be found at The Qt Resource

System.

RES_FILEThis variable contains the name of the resource file for the application. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

RSS_RULESThis is only used on the Symbian platform.

Generic RSS file content can be specified with this variable. The syntax is similar toMMP_RULES and BLD_INF_RULES.

For example:

RSS_RULES += "hidden = KAppIsHidden;"

This will add the specified statement to the end of the APP_REGISTRATION_INFO resource

struct in the generated registration resource file. As an impact of this statement, the

application will not be visible in application shell.

Page 67: Using Qmake

It is also possible to add multiple rows in a single block. Each double quoted string will be

placed on a new row in the registration resource file.

For example:

myrssrules = \

"hidden = KAppIsHidden;" \

"launch = KAppLaunchInBackground;" \

RSS_RULES += myrssrules

This example will install the application to MyFolder in the Symbian platform application

shell. In addition it will make the application to be launched in background.For detailed list of possible APP_REGISTRATION_INFO statements, please refer to the

Symbian platform help.Note: You should not use RSS_RULES variable to set the following RSS

statements:app_file, localisable_resource_file, and localisable_resource_id.

These statements are internally handled by qmake.There is a number of special modifiers you can attach to RSS_RULES to specify where in the

application registration file the rule will be written:

Modifier Location of the rule

<no modifier> Inside APP_REGISTRATION_INFO resource struct.

.header Before APP_REGISTRATION_INFO resource struct.

.footer After APP_REGISTRATION_INFO resource struct.

.service_list Inside a SERVICE_INFO item in the service_list ofAPP_REGISTRATION_INFO

.file_ownership_list Inside a FILE_OWNERSHIP_INFO item in

the file_ownership_list ofAPP_REGISTRATION_INFO

.datatype_list Inside a DATATYPE item in the datatype_list ofAPP_REGISTRATION_INFO

For example:

RSS_RULES.service_list += "uid = 0x12345678; datatype_list = \{\}; opaque_data = r_my_icon;"

RSS_RULES.footer +="RESOURCE CAPTION_AND_ICON_INFO r_my_icon \{ icon_file =\"$$PWD/my_icon.svg\"; \}"

This example will define service information for a fictional service that requires an icon to be supplied via the opaque_data of the service information.

S60_VERSIONThis is only used on the Symbian platform.

Contains the version number of the underlying S60 SDK; e.g. "5.0".

Page 68: Using Qmake

SIGNATURE_FILEThis is only used on Windows CE.

Specifies which signature file should be used to sign the project target.Note: This variable will overwrite the setting you have specified in configure, with the -signature option.

SOURCESThis variable contains the name of all source files in the project.

For example:

SOURCES = myclass.cpp \

login.cpp \

mainwindow.cpp

See also HEADERS

SRCMOCThis variable is set by qmake if files can be found that contain

the Q_OBJECT macro. SRCMOCcontains the name of all the generated moc files. The value of

this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

SUBDIRSThis variable, when used with the subdirs template contains the names of all subdirectories

or project files that contain parts of the project that need be built. Each subdirectory

specified using this variable must contain its own project file.

For example:

SUBDIRS = kernel \

tools

It is essential that the project file in each subdirectory has the same name as the subdirectory itself, so that qmake can find it. For example, if the subdirectory is

calledmyapp then the project file in that directory should be called myapp.pro.

If you need to ensure that the subdirectories are built in the order in which they are specified, update the CONFIG variable to include the ordered option:

CONFIG += ordered

It is possible to modify this default behavior of SUBDIRS by giving additional modifiers

toSUBDIRS elements. Supported modifiers are:

Page 69: Using Qmake

Modifier Effect

.subdir Use the specified subdirectory instead of SUBDIRS value.

.file Specify the subproject pro file explicitly. Cannot be used in conjunction with.subdir modifier.

.condition Specifies a bld.inf define that must be true for subproject to be built. Available only on Symbian platform.

.depends This subproject depends on specified subproject. Available only on platforms that use makefiles.

.makefile The makefile of subproject. Available only on platforms that use makefiles.

.target Base string used for makefile targets related to this subproject. Available only on platforms that use makefiles.

For example, define two subdirectories, both of which reside in a different directory than theSUBDIRS value, and one of the subdirectories must be built before the other:

SUBDIRS += my_executable my_library

my_executable.subdir = app

my_executable.depends = my_library

my_library.subdir = lib

For example, define a subdirectory that is only build for emulator builds in Qt for Symbian:

symbian {

SUBDIRS += emulator_dll

emulator_dll.condition = WINSCW

}

SYMBIAN_VERSIONThis is only used on the Symbian platform.

Contains the version number of the underlying Symbian SDK; e.g. "9.2" or "Symbian3".

TARGETThis specifies the name of the target file.

For example:

TEMPLATE = app

TARGET = myapp

SOURCES = main.cpp

The project file above would produce an executable named myapp on unix and 'myapp.exe'

on windows.

Page 70: Using Qmake

TARGET.CAPABILITYThis is only used on the Symbian platform.

Specifies which platform capabilities the application should have. For more information,

please refer to the Symbian SDK documentation.

TARGET.EPOCALLOWDLLDATAThis is only used on the Symbian platform.

Specifies whether static data should be allowed in the application. Symbian disallows this by

default in order to save memory. To use it, set this to 1.

TARGET.EPOCHEAPSIZEThis is only used on the Symbian platform.

Specifies the minimum and maximum heap size of the application. The program will refuse

to run if the minimum size is not available when it starts. For example:

TARGET.EPOCHEAPSIZE = 10000 10000000

TARGET.EPOCSTACKSIZEThis is only used on the Symbian platform.

Specifies the maximum stack size of the application. For example:

TARGET.EPOCSTACKSIZE = 0x8000

TARGET.SIDThis is only used on the Symbian platform.

Specifies which secure identifier to use for the target application or library. For more

information, see the Symbian SDK documentation.

TARGET.UID2This is only used on the Symbian platform.

Specifies which unique identifier 2 to use for the target application or library. If this variable

is not specified, it defaults to the same value as TARGET.UID3. For more information, see the

Symbian SDK documentation.

TARGET.UID3This is only used on the Symbian platform.

Specifies which unique identifier 3 to use for the target application or library. If this variable

is not specified, a UID3 suitable for development and debugging will be generated

automatically. However, applications being released should always define this variable. For

more information, see the Symbian SDK documentation.

TARGET.VID

Page 71: Using Qmake

This is only used on the Symbian platform.

Specifies which vendor identifier to use for the target application or library. For more

information, see the Symbian SDK documentation.

TARGET_EXTThis variable specifies the target's extension. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

TARGET_xThis variable specifies the target's extension with a major version number. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

TARGET_x.y.zThis variable specifies the target's extension with version number. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

TEMPLATEThis variable contains the name of the template to use when generating the project. The

allowed values are:

Option Description

app Creates a Makefile for building applications (the default). (See qmake Common Projects for more information.)

lib Creates a Makefile for building libraries. (See qmake Common Projects for more information.)

subdirs Creates a Makefile for building targets in subdirectories. The subdirectories are specified using the SUBDIRS variable.

vcapp Windows only Creates an application project for Visual Studio. (See qmake Platform Notes for more information.)

vclib Windows only Creates a library project for Visual Studio. (See qmake Platform Notesfor more information.)

For example:

TEMPLATE = lib

SOURCES = main.cpp

TARGET = mylib

The template can be overridden by specifying a new template type with the -t command

line option. This overrides the template type after the .pro file has been processed. With .pro

files that use the template type to determine how the project is built, it is necessary to declare TEMPLATE on the command line rather than use the -t option.

TRANSLATIONSThis variable contains a list of translation (.ts) files that contain translations of the user

interface text into non-native languages.See the Qt Linguist Manual for more information about internationalization (i18n) and

localization (l10n) with Qt.

Page 72: Using Qmake

UICIMPLSThis variable contains a list of the generated implementation files by UIC. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

UICOBJECTSThis variable is generated from the UICIMPLS variable. The extension of each file will have

been replaced by .o (Unix) or .obj (Win32). The value of this variable is typically handled byqmake or qmake.conf and rarely needs to be modified.

UI_DIRThis variable specifies the directory where all intermediate files from uic should be placed. This variable overrides both UI_SOURCES_DIR and UI_HEADERS_DIR.

For example:

unix:UI_DIR = ../myproject/ui

win32:UI_DIR = c:/myproject/ui

UI_HEADERS_DIRThis variable specifies the directory where all declaration files (as generated by uic) should

be placed.

For example:

unix:UI_HEADERS_DIR = ../myproject/ui/include

win32:UI_HEADERS_DIR = c:/myproject/ui/include

UI_SOURCES_DIRThis variable specifies the directory where all implementation files (as generated by uic)

should be placed.

For example:

unix:UI_SOURCES_DIR = ../myproject/ui/src

win32:UI_SOURCES_DIR = c:/myproject/ui/src

VERSIONThis variable contains the version number of the application or library if either the appTEMPLATE or the lib TEMPLATE is specified.

For example:

Page 73: Using Qmake

VERSION = 1.2.3

VER_MAJThis variable contains the major version number of the library, if the lib template is

specified.

VER_MINThis variable contains the minor version number of the library, if the lib template is

specified.

VER_PATThis variable contains the patch version number of the library, if the lib template is

specified.

VPATHThis variable tells qmake where to search for files it cannot open. With this you may

tellqmake where it may look for things like SOURCES, and if it finds an entry in SOURCES that

cannot be opened it will look through the entire VPATH list to see if it can find the file on its

own.See also DEPENDPATH.

YACCIMPLSThis variable contains a list of yacc source files. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

YACCOBJECTSThis variable contains a list of yacc object files. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.

YACCSOURCESThis variable contains a list of yacc source files to be included in the project. All

dependencies, headers and source files will automatically be included in the project.

For example:

YACCSOURCES = moc.y

_PRO_FILE_This variable contains the path to the project file in use.

For example, the following line causes the location of the project file to be written to the

console:

Page 74: Using Qmake

message($$_PRO_FILE_)

_PRO_FILE_PWD_This variable contains the path to the directory containing the project file in use.

For example, the following line causes the location of the directory containing the project file

to be written to the console:

message($$_PRO_FILE_PWD_)

qmake Function Referenceqmake provides built-in functions to allow the contents of variables to be processed, and to

enable tests to be performed during the configuration process. Functions that process the

contents of variables typically return values that can be assigned to other variables, and these values are obtained by prefixing function with the $$ operator. Functions that perform

tests are usually used as the conditional parts of scopes; these are indicated in the function

descriptions below.

basename(variablename)Returns the basename of the file specified. For example:

FILE = /etc/passwd

FILENAME = $$basename(FILE) #passwd

CONFIG(config)[Conditional]This function can be used to test for variables placed into the CONFIG variable. This is the

same as regular old style (tmake) scopes, but has the added advantage a second parameter

can be passed to test for the active config. As the order of values is important in CONFIG variables (i.e. the last one set will be considered the active config for mutually

exclusive values) a second parameter can be used to specify a set of values to consider. For

example:

CONFIG = debug

CONFIG += release

CONFIG(release, debug|release):message(Release build!) #will print

CONFIG(debug, debug|release):message(Debug build!) #no print

Page 75: Using Qmake

Because release is considered the active setting (for feature parsing) it will be the CONFIG

used to generate the build file. In the common case a second parameter is not needed, but

for specific mutual exclusive tests it is invaluable.

contains(variablename, value)[Conditional]

Succeeds if the variable variablename contains the value value; otherwise fails. You can

check the return value of this function using a scope.

For example:

contains( drivers, network ) {

# drivers contains 'network'

message( "Configuring for network build..." )

HEADERS += network.h

SOURCES += network.cpp

}

The contents of the scope are only processed if the drivers variable contains the

value,network. If this is the case, the appropriate files are added to

the SOURCES and HEADERSvariables.

count(variablename, number)[Conditional]

Succeeds if the variable variablename contains a list with the specified number of value;

otherwise fails.

This function is used to ensure that declarations inside a scope are only processed if the

variable contains the correct number of values; for example:

options = $$find(CONFIG, "debug") $$find(CONFIG, "release")

count(options, 2) {

message(Both release and debug specified.)

}

dirname(file)Returns the directory name part of the specified file. For example:

FILE = /etc/X11R6/XF86Config

DIRNAME = $$dirname(FILE) #/etc/X11R6

Page 76: Using Qmake

error(string)This function never returns a value. qmake displays the given string to the user, and exits.

This function should only be used for unrecoverable errors.

For example:

error(An error has occurred in the configuration process.)

eval(string)[Conditional]Evaluates the contents of the string using qmake's syntax rules and returns true. Definitions

and assignments can be used in the string to modify the values of existing variables or

create new definitions.

For example:

eval(TARGET = myapp) {

message($$TARGET)

}

Note that quotation marks can be used to delimit the string, and that the return value can

be discarded if it is not needed.

exists(filename)[Conditional]

Tests whether a file with the given filename exists. If the file exists, the function succeeds;

otherwise it fails. If a regular expression is specified for the filename, this function succeeds

if any file matches the regular expression specified.

For example:

exists( $(QTDIR)/lib/libqt-mt* ) {

message( "Configuring for multi-threaded Qt..." )

CONFIG += thread

}

Note that "/" can be used as a directory separator, regardless of the platform in use.

find(variablename, substr)Places all the values in variablename that match substr. substr may be a regular expression,

and will be matched accordingly.

Page 77: Using Qmake

MY_VAR = one two three four

MY_VAR2 = $$join(MY_VAR, " -L", -L) -Lfive

MY_VAR3 = $$member(MY_VAR, 2) $$find(MY_VAR, t.*)

MY_VAR2 will contain '-Lone -Ltwo -Lthree -Lfour -Lfive', and MY_VAR3 will contains 'three

two three'.

for(iterate, list)This special test function will cause a loop to be started that iterates over all values in list,

setting iterate to each value in turn. As a convenience, if list is 1..10 then iterate will iterate

over the values 1 through 10.

The use of an else scope afer a condition line with a for() loop is disallowed.

For example:

LIST = 1 2 3

for(a, LIST):exists(file.$${a}):message(I see a file.$${a}!)

include(filename)[Conditional]

Includes the contents of the file specified by filename into the current project at the point

where it is included. This function succeeds if filename is included; otherwise it fails. The

included file is processed immediately.

You can check whether the file was included by using this function as the condition for a

scope; for example:

include( shared.pri )

OPTIONS = standard custom

!include( options.pri ) {

message( "No custom build options specified" )

OPTIONS -= custom

}

infile(filename, var, val)[Conditional]Succeeds if the file filename (when parsed by qmake itself) contains the variable var with a

value of val; otherwise fails. If you do not specify a third argument (val), the function will

only test whether var has been declared in the file.

Page 78: Using Qmake

isEmpty(variablename)[Conditional]

Succeeds if the variable variablename is empty; otherwise fails. This is the equivalent ofcount( variablename, 0 ).

For example:

isEmpty( CONFIG ) {

CONFIG += qt warn_on debug

}

join(variablename, glue, before, after)Joins the value of variablename with glue. If this value is non-empty it prefixes the value

with before and suffix it with after. variablename is the only required field, the others default

to empty strings. If you need to encode spaces in glue, before, or after you must quote

them.

member(variablename, position)Returns the value at the given position in the list of items in variablename. If an item cannot

be found at the position specified, an empty string is returned. variablename is the only required field. If not specified, position defaults to 0, causing the first value in the list to be

returned.

message(string)This function simply writes a message to the console. Unlike the error() function, this

function allows processing to continue.

message( "This is a message" )

The above line causes "This is a message" to be written to the console. The use of quotation

marks is optional.

Note: By default, messages are written out for each Makefile generated by qmake for a

given project. If you want to ensure that messages only appear once for each project, test the build_pass variable in conjunction with a scope to filter out messages during

builds; for example:

!build_pass:message( "This is a message" )

prompt(question)Displays the specified question, and returns a value read from stdin.

Page 79: Using Qmake

quote(string)Converts a whole string into a single entity and returns the result. Newlines, carriage

returns, and tabs can be specified in the string with \n \r and \t. The return value does not

contain either single or double quotation marks unless you explicitly include them yourself,

but will be placed into a single entry (for literal expansion).

replace(string, old_string, new_string)Replaces each instance of old_string with new_string in the contents of the variable

supplied as string. For example, the code

MESSAGE = This is a tent.

message($$replace(MESSAGE, tent, test))

prints the message:

This is a test.

sprintf(string, arguments...)Replaces %1-%9 with the arguments passed in the comma-separated list of

functionarguments and returns the processed string.

system(command)[Conditional]Executes the given command in a secondary shell, and succeeds if the command returns with

a zero exit status; otherwise fails. You can check the return value of this function using a

scope:

For example:

system(ls /bin):HAS_BIN=FALSE

Alternatively, you can use this function to obtain stdout and stderr from the command, and

assign it to a variable. For example, you can use this to interrogate information about the

platform:

UNAME = $$system(uname -s)

contains( UNAME, [lL]inux ):message( This looks like Linux ($$UNAME) to me )

unique(variablename)

Page 80: Using Qmake

This will return a list of values in variable that are unique (that is with repetitive entries

removed). For example:

ARGS = 1 2 3 2 5 1

ARGS = $$unique(ARGS) #1 2 3 5

warning(string)This function will always succeed, and will display the given string to the user. message() is

a synonym for warning().

Configuring qmake's Environment

Propertiesqmake has a system of persistent information, this allows you to set a variable in qmake

once, and each time qmake is invoked this value can be queried. Use the following to set a

property in qmake:

qmake -set VARIABLE VALUE

The appropriate variable and value should be substituted for VARIABLE and VALUE.

To retrieve this information back from qmake you can do:

qmake -query VARIABLE

qmake -query #queries all current VARIABLE/VALUE pairs..

Note: qmake -query will only list variables that you have previously set with qmake -set VARIABLE VALUE.

This information will be saved into a QSettings object (meaning it will be stored in different

places for different platforms). As VARIABLE is versioned as well, you can set one value in an

older version of qmake, and newer versions will retrieve this value. However, if you

setVARIABLE for a newer version of qmake, the older version will not use this value. You can

however query a specific version of a variable if you prefix that version of qmake toVARIABLE, as in the following example:

qmake -query "1.06a/VARIABLE"

qmake also has the notion of builtin properties, for example you can query the installation

of Qt for this version of qmake with the QT_INSTALL_PREFIX property:

Page 81: Using Qmake

qmake -query "QT_INSTALL_PREFIX"

These built-in properties cannot have a version prefixed to them as they are not versioned, and each version of qmake will have its own built-in set of these values. The list below

outlines the built-in properties: QT_INSTALL_PREFIX - Where the version of Qt this qmake is built for resides

QT_INSTALL_DATA - Where data for this version of Qt resides

QMAKE_VERSION - The current version of qmake

Finally, these values can be queried in a project file with a special notation such as:

QMAKE_VERS = $$[QMAKE_VERSION]

QMAKESPECqmake requires a platform and compiler description file which contains many default values

used to generate appropriate Makefiles. The standard Qt distribution comes with many of these files, located in the mkspecs subdirectory of the Qt installation.

The QMAKESPEC environment variable can contain any of the following: A complete path to a directory containing a qmake.conf file. In this case qmake will open

the qmake.conf file from within that directory. If the file does not exist, qmake will exit with an error.

The name of a platform-compiler combination. In this case, qmake will search in the directory specified by the mkspecs subdirectory of the data path specified when Qt was compiled (see QLibraryInfo::DataPath).

Note: The QMAKESPEC path will automatically be added to the INCLUDEPATH system

variable.

INSTALLSIt is common on Unix to also use the build tool to install applications and libraries; for example, by invoking make install. For this reason, qmake has the concept of an install

set, an object which contains instructions about the way part of a project is to be installed.

For example, a collection of documentation files can be described in the following way:

documentation.path = /usr/local/program/doc

documentation.files = docs/*

The path member informs qmake that the files should be installed

in/usr/local/program/doc (the path member), and the files member specifies the files

Page 82: Using Qmake

that should be copied to the installation directory. In this case, everything in the docsdirectory will be coped to /usr/local/program/doc.

Once an install set has been fully described, you can append it to the install list with a line

like this:

INSTALLS += documentation

qmake will ensure that the specified files are copied to the installation directory. If you

require greater control over this process, you can also provide a definition for the extramember of the object. For example, the following line tells qmake to execute a

series of commands for this install set:

unix:documentation.extra = create_docs; mv master.doc toc.doc

The unix scope (see Scopes and Conditions) ensures that these particular commands are

only executed on Unix platforms. Appropriate commands for other platforms can be defined

using other scope rules.Commands specified in the extra member are executed before the instructions in the other

members of the object are performed.If you append a built-in install set to the INSTALLS variable and do not

specify files orextra members, qmake will decide what needs to be copied for you.

Currently, the only supported built-in install set is target:

target.path = /usr/local/myprogram

INSTALLS += target

In the above lines, qmake knows what needs to be copied, and will handle the installation

process automatically.

Cache FileThe cache file is a special file qmake reads to find settings not specified in

the qmake.conffile, project files, or at the command line. If -nocache is not specified

when qmake is run, it will try to find a file called .qmake.cache in parent directories of the

current directory. If it fails to find this file, it will silently ignore this step of processing.If it finds a .qmake.cache file then it will process this file first before it processes the project

file.

Library DependenciesOften when linking against a library, qmake relies on the underlying platform to know what

other libraries this library links against, and lets the platform pull them in. In many cases,

however, this is not sufficent. For example, when statically linking a library, no other

Page 83: Using Qmake

libraries are linked to, and therefore no dependencies to those libraries are created.

However, an application that later links against this library will need to know where to find the symbols that the static library will require. To help with this situation, qmake attempts to

follow a library's dependencies where appropriate, but this behavior must be explicitly

enabled by following two steps.

The first step is to enable dependency tracking in the library itself. To do this you must tellqmake to save information about the library:

CONFIG += create_prl

This is only relevant to the lib template, and will be ignored for all others. When this option

is enabled, qmake will create a file ending in .prl which will save some meta-information

about the library. This metafile is just like an ordinary project file, but only contains internal variable declarations. You are free to view this file and, if it is deleted, qmake will know to

recreate it when necessary, either when the project file is later read, or if a dependent

library (described below) has changed. When installing this library, by specifying it as a target in an INSTALLS declaration, qmake will automatically copy the .prl file to the

installation path.

The second step in this process is to enable reading of this meta information in the

applications that use the static library:

CONFIG += link_prl

When this is enabled, qmake will process all libraries linked to by the application and find

their meta-information. qmake will use this to determine the relevant linking information,

specifically adding values to the application project file's list of DEFINES as well as LIBS.

Once qmake has processed this file, it will then look through the newly introduced libraries in

the LIBS variable, and find their dependent .prl files, continuing until all libraries have been

resolved. At this point, the Makefile is created as usual, and the libraries are linked explicitly

against the application.

The internals of the .prl file are left closed so they can easily change later. They are not designed to be changed by hand, should only be created by qmake, and should not be

transferred between operating systems as they may contain platform-dependent

information.

File ExtensionsUnder normal circumstances qmake will try to use appropriate file extensions for your

platform. However, it is sometimes necessary to override the default choices for each platform and explicitly define file extensions for qmake to use. This is achieved by redefining

certain built-in variables; for example the extension used for moc files can be redefined with

the following assignment in a project file:

Page 84: Using Qmake

QMAKE_EXT_MOC = .mymoc

The following variables can be used to redefine common file extensions recognized byqmake: QMAKE_EXT_MOC  - This modifies the extension placed on included moc files.

QMAKE_EXT_UI  - This modifies the extension used for designer UI files (usually inFORMS).

QMAKE_EXT_PRL  - This modifies the extension placed on library dependency files.

QMAKE_EXT_LEX  - This changes the suffix used in files (usually in LEXSOURCES).

QMAKE_EXT_YACC  - This changes the suffix used in files (usually in YACCSOURCES).

QMAKE_EXT_OBJ  - This changes the suffix used on generated object files.

All of the above accept just the first value, so you must assign to it just one value that will be

used throughout your project file. There are two variables that accept a list of values: QMAKE_EXT_CPP  - Causes qmake to interpret all files with these suffixes as C++ source files.

QMAKE_EXT_H  - Causes qmake to interpret all files with these suffixes as C and C++ header files.

Customizing Makefile Outputqmake tries to do everything expected of a cross-platform build tool. This is often less than

ideal when you really need to run special platform-dependent commands. This can be achieved with specific instructions to the different qmake backends.

Customization of the Makefile output is performed through an object-style API as found in other places in qmake. Objects are defined automatically by specifying their members; for

example:

mytarget.target = .buildfile

mytarget.commands = touch $$mytarget.target

mytarget.depends = mytarget2

mytarget2.commands = @echo Building $$mytarget.target

The definitions above define a qmake target called mytarget, containing a Makefile target

called .buildfile which in turn is generated with the touch command. Finally,

the.depends member specifies that mytarget depends on mytarget2, another target that is

defined afterwards. mytarget2 is a dummy target; it is only defined to echo some text to

the console.The final step is to instruct qmake that this object is a target to be built:

Page 85: Using Qmake

QMAKE_EXTRA_TARGETS += mytarget mytarget2

This is all you need to do to actually build custom targets. Of course, you may want to tie one of these targets to the qmake build target. To do this, you simply need to include your

Makefile target in the list of PRE_TARGETDEPS.

The following tables are an overview of the options available to you with theQMAKE_EXTRA_TARGETS variable.

Member Description

commands The commands for generating the custom build target.

CONFIG Specific configuration options for the custom build target. See the CONFIG table for details.

depends The existing build targets that the custom build target depends on.

recurse Specifies which sub-targets should used when creating the rules in the Makefile to call in the sub-target specific

Makefile. This is only used whenrecursive is set in the CONFIG.

recurse_target Specifies the target that should be built via the sub-target Makefile for the rule in the Makefile. This adds

something like $(MAKE) -f Makefile.[subtarget] [recurse_target]. This is only used when recursive is set in

the CONFIG.

target The file being created by the custom build target.

List of members specific to the CONFIG option:

Member Description

recursive Indicates that rules should be created in the Makefile and thus call the relevant target inside the sub-target specific

Makefile. This defaults to creating an entry for each of the sub-targets.

For convenience, there is also a method of customizing projects for new compilers or

preprocessors:

new_moc.output = moc_${QMAKE_FILE_BASE}.cpp

new_moc.commands = moc ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}

new_moc.depend_command = g++ -E -M ${QMAKE_FILE_NAME} | sed "s,^.*: ,,"

new_moc.input = NEW_HEADERS

QMAKE_EXTRA_COMPILERS += new_moc

With the above definitions, you can use a drop-in replacement for moc if one is available. The commands is executed on all arguments given to the NEW_HEADERS variable (from

theinput member), and the result is written to the file defined by the output member; this

file is added to the other source files in the project. Additionally, qmake will

executedepend_command to generate dependency information, and place this information in

the project as well.

Page 86: Using Qmake

These commands can easily be placed into a cache file, allowing subsequent project files to add arguments to NEW_HEADERS.

The following tables are an overview of the options available to you with theQMAKE_EXTRA_COMPILERS variable.

Member Description

commands The commands used for for generating the output from the input.

CONFIG Specific configuration options for the custom compiler. See the CONFIG table for details.

depend_command Specifies a command used to generate the list of dependencies for the output.

dependency_type Specifies the type of file the output is, if it is a known type (such as TYPE_C, TYPE_UI, TYPE_QRC) then it

is handled as one of those type of files.

depends Specifies the dependencies of the output file.

input The variable that contains the files that should be processed with the custom compiler.

name A description of what the custom compiler is doing. This is only used in some backends.

output The filename that is created from the custom compiler.

output_function Specifies a custom qmake function that is used to specify the filename to be created.

variable_out The variable that the files created from the output should be added to.

List of members specific to the CONFIG option:

Member Description

commands The commands used for for generating the output from the input.

CONFIG Specific configuration options for the custom compiler. See the CONFIG table for details.

depend_command Specifies a command used to generate the list of dependencies for the output.

dependency_type Specifies the type of file the output is, if it is a known type (such as TYPE_C, TYPE_UI, TYPE_QRC) then it

is handled as one of those type of files.

depends Specifies the dependencies of the output file.

input The variable that contains the files that should be processed with the custom compiler.

name A description of what the custom compiler is doing. This is only used in some backends.

output The filename that is created from the custom compiler.

output_function Specifies a custom qmake function that is used to specify the filename to be created.

variables Indicates that the variables specified here are replaced with $(QMAKE_COMP_VARNAME) when refered to

in the pro file as $(VARNAME).

variable_out The variable that the files created from the output should be added to.

List of members specific to the CONFIG option:

Member Description

combine Indicates that all of the input files are combined into a single output file.

target_predeps Indicates that the output should be added to the list ofPRE_TARGETDEPS.

Page 87: Using Qmake

Member Description

explicit_dependencies The dependencies for the output only get generated from the depends member and from nowhere else.

no_link Indicates that the output should not be added to the list of objects to be linked in.

Note: Symbian platform specific: Generating objects to be linked in is not supported on the

Symbian platform, so either the CONFIG option no_link or variable variable_out should

always be defined for extra compilers.

qmake TutorialThis tutorial teaches you how to use qmake. We recommend that you read the qmake user

guide after completing this tutorial.

Starting off SimpleLet's assume that you have just finished a basic implementation of your application, and you

have created the following files: hello.cpp

hello.h

main.cpp

You will find these files in the examples/qmake/tutorial directory of the Qt distribution.

The only other thing you know about the setup of the application is that it's written in Qt.

First, using your favorite plain text editor, create a file called hello.pro inexamples/qmake/tutorial. The first thing you need to do is add the

lines that tell qmakeabout the source and header files that are part of your development

project.

We'll add the source files to the project file first. To do this you need to use the SOURCESvariable. Just start a new line with SOURCES += and put hello.cpp after it. You

should have something like this:

SOURCES += hello.cpp

We repeat this for each source file in the project, until we end up with the following:

SOURCES += hello.cpp

SOURCES += main.cpp

If you prefer to use a Make-like syntax, with all the files listed in one go you can use the

newline escaping like this:

SOURCES = hello.cpp \

main.cpp

Page 88: Using Qmake

Now that the source files are listed in the project file, the header files must be added. These

are added in exactly the same way as source files, except that the variable name we use

is HEADERS.

Once you have done this, your project file should look something like this:

HEADERS += hello.h

SOURCES += hello.cpp

SOURCES += main.cpp

The target name is set automatically; it is the same as the project file, but with the suffix appropriate to the platform. For example, if the project file is called hello.pro, the target

will be hello.exe on Windows and hello on Unix. If you want to use a different name you

can set it in the project file:

TARGET = helloworld

The final step is to set the CONFIG variable. Since this is a Qt application, we need to putqt on the CONFIG line so that qmake will add the relevant libraries to be linked against

and ensure that build lines for moc and uic are included in the generated Makefile.

The finished project file should look like this:

CONFIG += qt

HEADERS += hello.h

SOURCES += hello.cpp

SOURCES += main.cpp

You can now use qmake to generate a Makefile for your application. On the command line, in

your project's directory, type the following:

qmake -o Makefile hello.pro

Then type make or nmake depending on the compiler you use.

For Visual Studio users, qmake can also generate .dsp or .vcproj files, for example:

qmake -tp vc hello.pro

Making an Application Debuggable

Page 89: Using Qmake

The release version of an application doesn't contain any debugging symbols or other

debugging information. During development it is useful to produce a debugging version of the application that has the relevant information. This is easily achieved by adding debug to

theCONFIG variable in the project file.

For example:

CONFIG += qt debug

HEADERS += hello.h

SOURCES += hello.cpp

SOURCES += main.cpp

Use qmake as before to generate a Makefile and you will be able to obtain useful information

about your application when running it in a debugging environment.

Adding Platform-Specific Source FilesAfter a few hours of coding, you might have made a start on the platform-specific part of

your application, and decided to keep the platform-dependent code separate. So you now have two new files to include into your project file: hellowin.cpp and hellounix.cpp. We

can't just add these to the SOURCES variable since this will put both files in the Makefile. So,

what we need to do here is to use a scope which will be processed depending on which platform qmake is run on.

A simple scope that will add in the platform-dependent file for Windows looks like this:

win32 {

SOURCES += hellowin.cpp

}

So if qmake is run on Windows, it will add hellowin.cpp to the list of source files. If qmakeis

run on any other platform, it will simply ignore it. Now all that is left to be done is to create a

scope for the Unix-specific file.

When you have done that, your project file should now look something like this:

CONFIG += qt debug

HEADERS += hello.h

SOURCES += hello.cpp

SOURCES += main.cpp

win32 {

Page 90: Using Qmake

SOURCES += hellowin.cpp

}

unix {

SOURCES += hellounix.cpp

}

Use qmake as before to generate a Makefile.

Stopping qmake If a File Doesn't ExistYou may not want to create a Makefile if a certain file doesn't exist. We can check if a file exists by using the exists() function. We can stop qmake from processing by using the error()

function. This works in the same way as scopes do. Simply replace the scope condition with the function. A check for a main.cpp file looks like this:

!exists( main.cpp ) {

error( "No main.cpp file found" )

}

The ! symbol is used to negate the test; i.e. exists( main.cpp ) is true if the file exists,

and !exists( main.cpp ) is true if the file doesn't exist.

CONFIG += qt debug

HEADERS += hello.h

SOURCES += hello.cpp

SOURCES += main.cpp

win32 {

SOURCES += hellowin.cpp

}

unix {

SOURCES += hellounix.cpp

}

!exists( main.cpp ) {

error( "No main.cpp file found" )

}

Page 91: Using Qmake

Use qmake as before to generate a makefile. If you rename main.cpp temporarily, you will

see the message and qmake will stop processing.

Checking for More than One ConditionSuppose you use Windows and you want to be able to see statement output with qDebug()

when you run your application on the command line. Unless you build your application with the appropriate console setting, you won't see the output. We can easily put console on

the CONFIG line so that on Windows the makefile will have this setting. However, let's say

that we only want to add the CONFIG line if we are running on Windows and when debug is

already on the CONFIG line. This requires using two nested scopes; just create one scope,

then create the other inside it. Put the settings to be processed inside the last scope, like

this:

win32 {

debug {

CONFIG += console

}

}

Nested scopes can be joined together using colons, so the final project file looks like this:

CONFIG += qt debug

HEADERS += hello.h

SOURCES += hello.cpp

SOURCES += main.cpp

win32 {

SOURCES += hellowin.cpp

}

unix {

SOURCES += hellounix.cpp

}

!exists( main.cpp ) {

error( "No main.cpp file found" )

}

win32:debug {

CONFIG += console

Page 92: Using Qmake

}

That's it! You have now completed the tutorial for qmake, and are ready to write project files

for your development projects.

qmake Common ProjectsThis chapter describes how to set up qmake project files for three common project types that

are based on Qt. Although all kinds of projects use many of the same variables, each of

them use project-specific variables to customize output files.

Platform-specific variables are not described here; we refer the reader to the Deploying Qt

Applicationsdocument for information on issues such as building universal binaries for Mac

OS X and handling Visual Studio manifest files.

Building an Application

The app TemplateThe app template tells qmake to generate a Makefile that will build an application. With this

template, the type of application can be specified by adding one of the following options to the CONFIG variable definition:

Option Description

windows The application is a Windows GUI application.

console app template only: the application is a Windows console 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. This defaults to the name of the project file. (The extension, if any, 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.

VPATH - The search path to find supplied files.

DEF_FILE  - Windows only: A .def file to be linked against for the application.

Page 93: Using Qmake

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 do not have any extra INCLUDEPATHs then you do not need to specify any, qmake will add in

the default ones needed. For instance, an example project file might look like this:

TEMPLATE = app

DESTDIR = c:/helloapp

HEADERS += hello.h

SOURCES += hello.cpp

SOURCES += main.cpp

DEFINES += QT_DLL

CONFIG += qt warn_on release

For items that are single valued, e.g. the template or the destination directory, we use "=";

but for multi-valued items we use "+=" to add to the existing items of that type. Using "=" replaces the item's value with the new value, for example if we wrote DEFINES=QT_DLL, all

other definitions would be deleted.

Building a Library

The lib TemplateThe lib template tells qmake to generate a Makefile that will build a library. When using this

template, in addition to the system variables mentioned above for the app template

theVERSION variable is supported. You should use these in your .pro file to specify

information about the library.When using the lib template, the following options can be added to the CONFIG variable to

determine the type of library that is built:

Option Description

dll The library is a shared library (dll).

staticlib The library is a static library.

plugin The library is a plugin; this also enables the dll option.

The following option can also be defined to provide additional information about the library. VERSION - The version number of the target library, for example, 2.3.1.

The target file name for the library is platform-dependent. For example, on X11 and Mac OS X, the library name will be prefixed by lib; on Windows, no prefix is added to the file name.

Building a Plugin

Page 94: Using Qmake

Plugins are built using the lib template, as described in the previous section. This

tellsqmake to generate a Makefile for the project that will build a plugin in a suitable form for

each platform, usually in the form of a library. As with ordinary libraries, the VERSIONvariable

is used to specify information about the plugin. VERSION - The version number of the target library, for example, 2.3.1.

Building a Qt Designer Plugin

Qt Designer plugins are built using a specific set of configuration settings that depend on the

way Qt was configured for your system. For convenience, these settings can be enabled by adding designer to the project's CONFIG variable. For example:

CONFIG += designer plugin

See the Qt Designer Examples for more examples of plugin-based projects.

Building and Installing in Debug and Release ModesSometimes, it is necessary to build a project in both debug and release modes. Although theCONFIG variable can hold both debug and release options, the debug option overrides

therelease option.

Building in Both ModesTo enable a project to be built in both modes, you must add the debug_and_release option

to your project's CONFIG definition:

CONFIG += debug_and_release

CONFIG(debug, debug|release) {

TARGET = debug_binary

} else {

TARGET = release_binary

}

The scope in the above snippet modifies the build target in each mode to ensure that the

resulting targets have different names. Providing different names for targets ensures that

one will not overwrite the other.When qmake processes the project file, it will generate a Makefile rule to allow the project to

be built in both modes. This can be invoked in the following way:

make all

Page 95: Using Qmake

The build_all option can be added to the CONFIG variable in the project file to ensure that

the project is built in both modes by default:

CONFIG += build_all

This allows the Makefile to be processed using the default rule:

make

Installing in Both ModesThe build_all option also ensures that both versions of the target will be installed when the

installation rule is invoked:

make install

It is possible to customize the names of the build targets depending on the target platform.

For example, a library or plugin may be named using a different convention on Windows to

the one used on Unix platforms:

CONFIG(debug, debug|release) {

mac: TARGET = $$join(TARGET,,,_debug)

win32: TARGET = $$join(TARGET,,d)

}

The default behavior in the above snippet is to modify the name used for the build target when building in debug mode. An else clause could be added to the scope to do the same

for release mode; left as it is, the target name remains unmodified.