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;
    }
}

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.

PropertyTypeDefaultDescription
conditionboolnone - must be specifiedThe condition to be used for the other bindings in this item.

© 2015 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.