[Qbs] Building code generator and its dependencies for a different architecture than the rest of the products

Christian Kandeler christian.kandeler at qt.io
Fri Mar 20 15:41:21 CET 2020

On Fri, 20 Mar 2020 14:10:49 +0000
Leon Buckel <leon.buckel at clausmark.com> wrote:

> I have a project with the following products:
>   *   Shared library
>   *   Code generator tool
>   *   Application
> The code generator and application both depend on the shared library. The build process is as follows:
>   1.  Build the shared library
>   2.  Build the code generator and link against the library
>   3.  Use the previously built generator to generate code used by the application.
>   4.  Build the application and link against the library
> This works fine when building for windows or macOS but I'm running into an issue when targeting iOS.
> Basically what I want is to build the generator as a Mac application so that it can be run during the build to generate code for the iOS app.
> Since the library is used by both it should be built for both architectures.
> I looked into multiplexing but I'm not sure it does exactly what I want but maybe I misunderstood something.
> Is there a way to do this with qbs?

Excellent, a real-life test case...
Yes, this is pretty much what multiplexing is for. However, there isn't a lot of experience with how to best set this up in practice.
Also, I notice that for your use case we should probably have a qbs.targetPlatforms property...
Anyway, as of right now you'd do this with in-project profiles. Define them in e.g. the top-level project file:
    Profile {
        name: "hostProfile"
        qbs.targetPlatform: qbs.hostPlatform
    Profile {
        name: "targetProfile"
        baseProfile: project.profile // Assumes that the iOS profile is your main profile that you build the project with

Then multiplex your library over these profiles:
    DynamicLibrary {
        // ...
        multiplexByQbsProperties: ["profiles"]
        qbs.profiles: ["hostProfile", "targetProfile"]

Your app and build tool use normal Depends items for pulling in the library; the matching should work automatically.
Note: The host profile as written above relies on the host toolchain being auto-detected, i.e. PATH and/or other variables have to be suitably set up.
Good luck, and please share your findings.


More information about the Qbs mailing list