Qbs Manual | Properties Item

Qbs 1.9.1

Project Item ◦ PropertyOptions Item

# Properties Item

Note: This documents the `Properties` item in the context of products. Usage within a `SubProject` item is described here.

The `Properties` item is an auxiliary item for setting multiple property values conditionally.

In the following example, two properties are set if the project is built for Windows:

      Product {
          Properties {
              condition: qbs.targetOS.contains("windows")
              cpp.defines: ["ON_WINDOWS"]
              cpp.includePaths: ["extraWindowsIncludes"]
          }
      }

Multiple `Properties` items can be specified to set properties dependent on different conditions. The order of appearance is important. Semantics are similar to if-else-chains. The following example

      Product {
          Properties {
              condition: qbs.targetOS.contains("windows")
              cpp.defines: ["ON_WINDOWS"]
              cpp.includePaths: ["myWindowsIncludes"]
          }
          Properties {
              condition: qbs.targetOS.contains("linux")
              cpp.defines: ["ON_LINUX"]
              cpp.includePaths: ["myLinuxIncludes"]
          }
          cpp.defines: ["ON_UNKNOWN_PLATFORM"]
      }

is equivalent to

      Product {
          cpp.defines: {
              if (qbs.targetOS.contains("windows"))
                  return ["ON_WINDOWS"];
              if (qbs.targetOS.contains("linux"))
                  return ["ON_LINUX"];
              return ["ON_UNKNOWN_PLATFORM"];
          }
          cpp.includePaths: {
              if (qbs.targetOS.contains("windows"))
                  return ["myWindowsIncludes"];
              if (qbs.targetOS.contains("linux"))
                  return ["myLinuxIncludes"];
              return base;
          }
      }

In `Properties` items one can access the outer value of a property.

      Product {
          Properties {
              condition: qbs.targetOS.contains("windows")
              cpp.defines: outer.concat("ON_WINDOWS")     // === ["FOO", "ON_WINDOWS"]
          }
          Properties {
              condition: qbs.targetOS.contains("linux")
              cpp.defines: ["ON_LINUX"]                   // === ["ON_LINUX"]
          }
          cpp.defines: ["FOO"]
      }

We suggest to use the `Properties` item for mutually exclusive conditions only. It is especially useful if there are several properties to set, based on the same condition.

## List of Properties

Property | Type | Default | Description
--- | --- | --- | ---
condition | bool | none - must be specified | The condition to be used for the other bindings in this item.
overrideListProperties | bool | `false` | List properties set within this item will override the values coming from modules, rather than getting merged with them, which is the default behavior. Use this in the rare case that a module you depend on inserts a value into a list property that is problematic for some product.

Project Item ◦ PropertyOptions Item