Qbs Manual | Generators

Qbs 1.11.1

Using the Shell ◦ Multiplexing

# Generators

Generators are a Qbs sub-tool and set of APIs that enable arbitrary processing to be performed on the build graph. Currently, they are used to integrate Qbs with popular IDEs, such as Microsoft Visual Studio, and to generate Clang compilation databases.

## Generating Projects

To generate a project for another build system, such as Microsoft Visual Studio, use the qbs generate 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. The resulting project files can be opened in the respective IDE 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.

## Generating Clang Compilation Databases

To generate a Clang compilation database (clangdb), use the following command:

      qbs generate --generator clangdb

## 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 Microsoft 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: 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:

- Product.name
- bundle.isBundle

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

Using the Shell ◦ Multiplexing