[QBS] propagate compiler options

Thomas Epting thomas.epting.stryker at gmail.com
Sat Jan 17 13:15:32 CET 2015


> No, you don’t get it right. I want to propagate down, not up. So the
> parent product determines the compile options of the siblings.
> In your case Product A defines the compile options for Product C when
> building A and Product B defines the compile option for Product C when
> building B.
> Do you know how I can do that? Because when a build for example product A
> than product C is build with the cpp module defaults and not with the
> compile options of product A.
> Product C should however be able to override or add compile options.
>

Hi Marcel,

Let me try to sketch a solution for your problem, which provides
project-level compiler options for all references products.



First, I suggest to derive from all base items you need (like Application
and StaticLibrary products), and to use your own items instead of the
standard ones. So instead of using Application, your application products
should use *My*Application. Your static libraries should use *My*StaticLibrary,
and so on. Put all your derived products in a folder “qbs/imports” (you
need to extend qbsSearchPaths in your main project later, in order to
access these files). Your derived product definitions could look like this:



--- *My*Application.qbs ---

import qbs 1.0

Application {

    Depends { name: "cpp" }

    cpp.cxxFlags: project.myCxxFlags

}



--- *My*StaticLibrary.qbs ---

import qbs 1.0

StaticLibrary {

    Depends { name: "cpp" }

    cpp.cxxFlags: project.myCxxFlags

}



The trick is to extend “cpp.cxxFlags” by a property defined on project
level. This means: (1) your project has to define such a property,
otherwise loading of the Qbs project will fail. (2) Each project may define
a different set of settings, which apply to ALL products referenced by it.



Now let’s consider your project consists of an application A and a library
L.



--- A.qbs ---

import qbs 1.0

*My*Application {

    // …
}



--- L.qbs ---

import qbs 1.0

*My*StaticLibary {

    // …
}



Here’s how your project definition could look like:



--- YourProject.qbs ---

import qbs 1.0

Project {

    references: [ "A.qbs", "L.qbs" ]

    qbsSearchPaths: "path/to/your/qbs-folder"

    property stringList myCxxFlags: [ "--cxx-flag1", "--cxx-flag2" ]

}



Of course you could extend this solution to support extra defines, include
paths, or whatever you like. You could even propagate down different
settings for each sub-project of your overall project, since project
settings are inherited by sub-projects.



Hope this helps.

Regards, Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20150117/40ec68ff/attachment.html>


More information about the Qbs mailing list