Search code examples
qbs

Set a property declared in one qbs project from another


I have a typical application dev scenario, a library + application, both are qbs projects. In the library project I declared a Boolean property staticBuild default to true as follow:

Project { // the library

    property bool staticBuild: true

    Product {
        type: staticBuild ? "staticlibrary" : "dynamiclibrary"
        name: "Lib"
    }
}

In the application project I use a Depends item to add Lib as a dependency as follow:

Project { // Application

    Product {
        type: "application"
        Depends { name: "Lib" }
        Lib.staticBuild: false // want to link to a dll.
    }
}

but this property referencing does not work, I get error telling me that the property is not declared.

How could I fix this ?.


Solution

  • First of all, the library does not even have that property; its parent project does. But even if it did, it would not be visible, much less settable, from the outside. Keep in mind that the library exists once, while there could be many dependencies on it. So if you want to make a decision about how the library is built, you need to do that at a higher level, from which both products take their information. This could be a common parent project (typically the top-level one), or a project-specific module that both products pull in. The main point is that the decision is made in a central place.