Boost logo

Boost-Build :

From: Bojan Resnik (resnikb_at_[hidden])
Date: 2006-04-26 07:45:58


> Hi Bojan,
> I think it's possible to allow including PCH file right into exe:
>
> exe hello : [ cast _ pchheader : pch.hpp ] main.cpp : <define>ABC ;

  The above does not work, but a similar line allows bjam to build:

exe hello
        : [ pch mypch : [ cast _ pcheader : pch.hpp ] pch.cpp ] main.cpp
        : <define>ABC ;

  However, this still does not define ABC when compiling the PCH (tried).

  My current workaround for this issue is to have custom my-lib and
my-exe rules which have an additional parameter - used libraries. So
instead of
  exe hello : mypch main.cpp ./other//other : <define>ABC ;
I have
  my-exe hello : precompiled.cpp main.cpp : <define>ABC : ./other//other ;

The rule detects if precompiled.cpp is among the sources and if it is
creates an inline pch target by applying all requirements from above
and applying <use> to the dependencies:

exe hello: [ pch prec : [ cast _ pcheader : precompiled.hpp ] precompiled.cpp
                                 : <define>ABC <use>/other//other
                   ]
                   main.cpp /other//other
                  : <define>ABC
                   ;

This adds most things to PCH. It does not, however, propagate user
defined <cxxflags>.

> and in that case PCH will be created with right properties. But this raises
> question about reusing of the same PCH by different targets:
>
> pch mypch : [ cast _ pcheader : pch.hpp ] pch.cpp ;
> exe a : a.cpp mypch : <define>ABC ;
> exe b : b.cpp mypch : <define>ABC ;
>
> In which case we'd need either to propagate defines, or manually add define to
> PCH. And what should happen in this case:
>
> pch mypch : [ cast _ pcheader : pch.hpp ] pch.cpp ;
> exe a : a.cpp mypch ;
> exe b : b.cpp mypch : <define>ABC ;
>
> Should it be an error?
>
> - Volodya

  I believe it should, as it defeats the purpose of precompiled
headers. The above pch must be recreated each time either a or b is
compiled. After a is compiled it must be regenerated for b, with
different compile settings. On the next build it must again be
recreated for a.

--
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