Properties

Provides conditional setting of properties. More...

Properties

Detailed Description

Note: This topic documents the Properties item in the context of products. For more information about using it in sub-projects, see SubProject.

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.includes("windows")
        cpp.defines: ["ON_WINDOWS"]
        cpp.includePaths: ["extraWindowsIncludes"]
    }
}

As the above example demonstrates, the Properties item is especially useful if there are several properties whose values depend on the same set of conditions. These conditions do not need to be mutually exclusive, but care should be taken not to set the same scalar property in more than one matching Properties item. Qbs makes no guarantees about the value of the property in such cases.

If the same property is set both inside and outside of a Properties item, the outside binding is only considered if none of the Properties conditions match, that is, it acts as an "else" case.

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

is roughly equivalent to

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

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

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

Property Documentation

[default: true] condition : bool

The condition to be used for the other bindings in this item.

Note: The special value undefined can be used to indicate that this condition should be considered true if and only if none of the other Properties items matched for a given property binding.


overrideListProperties : bool

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.

Default: false


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