Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Qbs Quick Reference

From Qt Wiki
Revision as of 16:31, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

Qbs is the next-generation build system initially introduced in the Qt Labs Blog [blog.qt.io]. This page is intended as a quick guide to porting project files from qmake *.pro syntax to *.qbs. It is not intended to supplant the official documentation, rather to be a quick summary of the current status of qbs functionality with a focus on how to port from qmake.

Some things at the time of writing have no equivalent qbs syntax. Bugtracker links are included for missing functionality, where known. And finally this is based on my incomplete current understanding of qbs, so there may be errors or indeed things which have changed by the time you read this :)

Qbs Manual

The full Qbs Manual is found at http://doc.qt.io/qbs

qbs equivalents

TEMPLATE = app

Use Application or CppApplication as the product:

This is roughly equivalent to:

except that in the first example, the type is “applicationbundle” on OSX.

TEMPLATE = lib

Use DynamicLibrary as the product:

TARGET = myappname

Use the “name” property, see the TEMPLATE example above.

HEADERS, SOURCES, FORMS, RESOURCES

Include in files section, eg

qbs will use file taggers to figure out what kind of file it is dealing with.

CONFIG += console

CONFIG += designer_defines

QT += modulename

Add an appropriate Depends section to the product. For example:

Both forms are equivalent, the first form being quicker to type if you depend on just one module and the second more flexible if you have more complex dependencies.

DEFINES += MACRO

Use the following: Note that in order to reference cpp.defines you must specify a dependency on the cpp module.

The cpp module might define default preprocessor macros. For example on Windows UNICODE is predefined.
These are stored in the property cpp.platformDefines.
To override these macros do:

To add macros within a group, you need to use outer.concat rather than base.concat(), because you are adding additional macros to what is specified in the outer scope:

cpp.defines statements inside a group only apply to the files in that group – therefore you cannot use a group to include a bunch of files and globally-visible macros – the macros must go in a Properties block at the same level as the group if they need to be visible to files outside the group:

INCLUDEPATH += dir

CONFIG -= Qt

Just don’t declare Qt as a dependency. Probably you’d want:

RC_FILE

Just add the file to the “files” list.

QMAKE_INFO_PLIST

Set the cpp.infoPlistFile property.

ICON,

Not yet implemented. See QBS-73 [bugreports.qt.io].

TEMPLATE = subdirs

Inside a “Project” item, use “references”:

DESTDIR

Use the destinationDirectory property:

message(), warning(), error()

You can use the JavaScript function print for printing messages and throw exceptions on the right hand side of property bindings.

Others not mentioned above

Either I’ve missed them, or they’re not yet implemented.

.pro and .pri

The top-level .qbs file contains the “Project” definition. A project can contain multiple products, so you may find that multiple .pro files can be expressed in a single .qbs. The subdirs pattern will typically convert to a single .qbs containing references to multiple .qbs files. Each .qbs file would then define a single product or sub-project.

.qbs files can also be used like .pri files in that a top-level .qbs can include sections defined in another .qbs. For example:

.qbs files in the same directory as the top-level .qbs file are picked up automatically. Others must be explicitly imported and named using an “import … as …” statement:

Conditionals

Instead of the qmake syntax of “windows { … }” or “macx:…”, you specify a “condition” property in the relevant block. Conditionally-compiled files should be collected in a “Group” block, while platform-specific properties should go in a “Properties” block rather than being put in the main (outer) block:

See the DEFINES section above for important information about how conditionals and cpp.defines interact.

C++ compiler options

Here is a selection of options that are supported. The full list can be found in share/qbs/modules/cpp/CppModule.qbs in the qbs source tree, these are some of the more useful:

Note that setting things like cflags directly is discouraged (because they are compiler-dependent), and higher-level alternatives like cpp.optimization: “fast” should be used if available.

Installing files

Create a group containing the files, and set qbs.install and qbs.installDir:

For files generated by the build (e.g. an executable), you need to match them by their file tag:

The installation happens by invoking the “qbs install” command:

Command-line examples

64-bit:

“Magic” variables

Variables defined in various scopes, which may not be obvious:

qbs

This has lots of useful things in, such as: targetOS (“windows”, “linux”, “macx”, …); buildVariant (“debug”, “release”); architecture (“x86”, “x86_64”, …)

project

Valid anywhere in your project, needed to refer to project properties from within a product:

buildDirectory

The top-level build directory. By default will be a subdirectory in the directory where you invoked qbs from, whose name is derived from the current profile.

Module names

Modules that are declared as dependencies can be referred to by their name and their properties accessed – for example:

Inside custom javascript

Generally when writing custom JavaScript logic, things are referenced through the top-level “product” variable. In particular, to get the product’s value of the property “baz” of a module “foo”, use product.moduleProperty(“foo”, “baz”). For list values that get automatically combined, like includePaths, use product.moduleProperties(“foo”, “baz”).

and

Categories: