Generators

Generators are a Qbs sub-tool and set of APIs which enable arbitrary processing to be performed on the build graph. Currently they are used to implement IDE integration with popular IDEs like Visual Studio.

Using Generators

To generate a project for another build system like Visual Studio, use the qbs-generate sub-command and specify a generator using the -g option. For example:

# For Visual Studio
qbs generate -g visualstudio2015

Qbs will then generate a series of files in the current directory, based on the generator that was chosen. For the Visual Studio generator, the resulting project files can be opened in the respective IDEs and all work can be performed there.

The project files will expose as much information as possible to the IDE and will use Qbs to perform the actual build.

Note: You cannot modify build system files and expect the changes to be reflected in Qbs; you must edit your Qbs project files and re-run qbs-generate in order for the changes to be reflected in your IDE.

Limitations

Due to the high flexibility of the Qbs project format and build engine, some projects may be too complex to produce an equivalent project file for another build system.

This list of limitations aims to be as small as possible, but one of the most notable (at least for the Visual Studio generator) is that certain properties must contain the same value across all build configurations. For example, the following is not allowed:

Product {
    // ERROR: 'name' property cannot have different values based on the configuration
    name: qbs.configuration === "debug"
        ? "MyProduct_debug"
        : "MyProduct"
}

Note that this limitation only applies when property values are varied on the configuration name. For example, the following is OK (as long as the value of xyz itself does not vary across configurations):

Product {
    // OK
    property bool isDebug: <some value>
    name: isDebug ? "MyProduct_debug" : "MyProduct"
}

The properties to which the limitation applies includes but is not limited to:

If a simple workaround is possible in a particular case (e.g. varying Product.targetName across configuration instead of Product.name), the generator will typically suggest it in the error message.

© 2017 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.