Boost logo

Boost-Build :

From: Bojan Resnik (resnikb_at_[hidden])
Date: 2006-10-24 02:56:14


> I think I have the final question about PCH interface. Now if we write:
>
> cpp-pch pch : pch.hpp : ......... ;
> exe hello : hello.cpp pch : ....... ;
>
> the user is required to make sure that properties used to compile pch and the
> exe are "compatible". I wonder if we can improve that. One approach is to
> propagate all features, including free one, from exe to pch. So that if you
> write:
>
> cpp-pch pch : pch.hpp ;
> exe hello : hello.cpp pch : <define>FOO ;
>
> the <define>FOO is propagated to 'pch'. That's "implementable", but then what
> about:
>
> cpp-pch pch : pch.hpp ;
> exe hello : hello.cpp pch : <define>FOO ;
> exe hello2 : hello.cpp pch : <define>BAR ;
>
> In this case, Boost.Build won't know with what properties to build 'pch' and
> will error out. And FOO/BAR really might affect just the executables, and not
> the PCH. So, I think that requiring user to set right properties on PCH might
> be a good idea, after all.
>
> Comments?

  Personally, I've never used the same header for multiple projects
because you can get a wrong compile if the compiler flags do not match
for the main target and the pch. IIRC, MSVC will issue warnings if the
flags are not the same. The other reason is that different projects
may have different benefits or drawbacks with the same set of header
files included from pch. I usually tailor the pch according to the
project it belongs to.

  Another issue when using the same pch for multiple targets, are the
usage requirements of dependencies:

    lib some-lib : : : <runtime-link>static ;
    lib some-other-lib : : : <runtime-link>shared ;
    exe hello : hello.cpp pch some-lib : <define>FOO ;
    exe hello2 : hello.cpp pch some-other-lib : <define>BAR ;

  The usage requirements of some-lib should be propagated to the pch
if compiling hello, and those of some-other-lib if compiling hello2.

  I think it would be best to use one pch target for one project:

    cpp-pch pch : pch.hpp ;
    exe hello : hello.cpp pch : <define>FOO ;

    cpp-pch pch2 : pch.hpp ;
    exe hello2 : hello.cpp pch2 : <define>BAR ;

-- 
Bojan Resnik

Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk