|
Boost-Build : |
From: Reece Dunn (msclrhd_at_[hidden])
Date: 2005-11-20 14:03:33
Alex Besogonov wrote:
> Reece Dunn wrote:
>> This is a minor revision to correctly use :W where it is needed
>> (including some places in the previous response file changeover).
> Thanks! Now I can _finally_ throw away all <cxxflags> hacks!
:)
> I've noticed a couple of minor problems:
> 1) In pch.jam:
> =================
> # Make mypch.hpp a pre-compiled header (PCH) using mypch.cpp as the
> source file:
> # pch mypch : mypch.cpp mypch.hpp ;
> =================
> But this won't work because hpp must be the first in the sources list
I have now corrected this.
> (BTW, may be an order-independent syntax will be better?).
Yes. The question is how to do the filter inside the pch-generator *and*
inside msvc.compile.pch.
> 2) PCH support won't work if precompiled header has ".h" extension and
> not ".hpp".
Alexey has mentioned this to me off-list. The problem is that the H[PP]
-> OBJ generators are intefering with the message compiler stuff. The
solution is to have:
import cast ;
pch stdafx : [ cast _ pcheader : stdafx.h ] stdafx.cpp ;
exe microsoft
:
main.cpp demo.cpp stdafx
;
I have attached the updated that fixes these issues here.
- Reece
# Copyright (c) 2005 Reece H. Dunn.
#
# Use, modification and distribution is subject to the Boost Software
# License Version 1.0. (See accompanying file LICENSE_1_0.txt or
# http://www.boost.org/LICENSE_1_0.txt)
import type ;
import feature : feature ;
import generators ;
##### Using Pre-compiled Headers (Quick Guide) #####
#
# Make mypch.hpp a pre-compiled header (PCH) using mypch.cpp as the source file:
# import cast ;
# pch mypch : [ cast _ pcheader : pch.hpp ] pch.cpp ;
#
# Enable PCHs in a target:
# exe hello : mypch main.cpp hello.cpp ;
# ^^^^^ -- mypch.hpp is a PCH
#
# Don't use PCHs for a specific source:
# obj nopch : nopch.cpp : <pch>off ;
#
type.register PCH : pch ;
type.register PCHEADER : pcheader ;
feature pch : # control precompiled header (PCH) generation
on # this file has support for using PCHs (if available)
off # this file doesn't use PCHs
;
feature pch-source : : free dependency ; # mypch.cpp
feature pch-header : : free dependency ; # mypch.h[pp]
feature pch-file : : free dependency ; # mypch.pch
class pch-generator : generator
{
import property-set ;
rule __init__ ( * : * )
{
generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
}
rule action-class ( )
{
return compile-action ;
}
rule run ( project name ? : property-set : sources * )
{
local r =
[ generator.run $(project) $(name) :
[
property-set.create
<pch-source>$(sources[2]) # mypch.cpp
[ $(property-set).raw ]
] : $(sources)
] ;
return
[ property-set.create
<pch-header>$(sources[1]) # mypch.h[pp]
<pch-file>$(r[2]) # mypch.pch
] $(r) ;
}
}
Index: msvc.jam
===================================================================
RCS file: /cvsroot/boost/boost/tools/build/v2/tools/msvc.jam,v
retrieving revision 1.64
diff -u -r1.64 msvc.jam
--- msvc.jam 14 Nov 2005 15:15:06 -0000 1.64
+++ msvc.jam 20 Nov 2005 19:00:36 -0000
@@ -18,6 +18,7 @@
import common ;
import "class" : new ;
import rc ;
+import pch ;
if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]
{
@@ -487,6 +488,8 @@
generators.override msvc.compile.rc : rc.resource-compile ;
generators.register-standard msvc.compile.asm : ASM : OBJ : <toolset>msvc ;
+generators.register [ new pch-generator msvc.compile.pch : PCHEADER : OBJ PCH : <toolset>msvc ] ;
+
#
# Declare flags and action for compilation
#
@@ -537,15 +540,41 @@
flags msvc.compile UNDEFS <undef> ;
flags msvc.compile INCLUDES <include> ;
+flags msvc.compile PCH_SOURCE <pch-source> ;
+flags msvc.compile PCH_HEADER <pch>on : <pch-header> ;
+flags msvc.compile PCH_FILE <pch>on : <pch-file> ;
+
+rule compile.c ( targets + : sources * : properties * )
+{
+ DEPENDS $(<) : [ on $(<) return $(PCH_HEADER) ] ;
+ DEPENDS $(<) : [ on $(<) return $(PCH_FILE) ] ;
+}
+
+rule compile.c++ ( targets + : sources * : properties * )
+{
+ DEPENDS $(<) : [ on $(<) return $(PCH_HEADER) ] ;
+ DEPENDS $(<) : [ on $(<) return $(PCH_FILE) ] ;
+}
+
+rule compile.pch ( targets + : sources * : properties * )
+{
+ DEPENDS $(<) : [ on $(<) return $(PCH_SOURCE) ] ;
+}
+
# The actions differ only by explicit selection of input language
-actions compile.c bind
+actions compile.c bind PCH_HEADER PCH_FILE
+{
+ $(.CC) /Zm800 -nologo -TC -U$(UNDEFS) $(CFLAGS) $(USER_CFLAGS) @"@($(<[1]:W).rsp:E=$(nl)"$(>:W)" $(nl)-D$(DEFINES) $(nl)"-I$(INCLUDES)")" -c -Fo"$(<[1]:W)" -Yu"$(PCH_HEADER:D=)" -Fp"$(PCH_FILE:W)"
+}
+
+actions compile.c++ bind PCH_HEADER PCH_FILE
{
- $(.CC) /Zm800 -nologo -TC -U$(UNDEFS) $(CFLAGS) $(USER_CFLAGS) @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)-D$(DEFINES) $(nl)"-I$(INCLUDES)")" -c -Fo"$(<[1]:W)"
+ $(.CC) /Zm800 -nologo -TP -U$(UNDEFS) $(CFLAGS) $(C++FLAGS) $(USER_CFLAGS) @"@($(<[1]:W).rsp:E=$(nl)"$(>:W)" $(nl)-D$(DEFINES) $(nl)"-I$(INCLUDES)")" -c -Fo"$(<[1]:W)" -Yu"$(PCH_HEADER:D=)" -Fp"$(PCH_FILE:W)"
}
-actions compile.c++ bind
+actions compile.pch bind PCH_SOURCE
{
- $(.CC) /Zm800 -nologo -TP -U$(UNDEFS) $(CFLAGS) $(C++FLAGS) $(USER_CFLAGS) @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)-D$(DEFINES) $(nl)"-I$(INCLUDES)")" -c -Fo"$(<[1]:W)"
+ $(.CC) /Zm800 -nologo -TP -U$(UNDEFS) $(CFLAGS) $(C++FLAGS) $(USER_CFLAGS) @"@($(<[1]:W).rsp:E=$(nl)"$(PCH_SOURCE:W)" $(nl)-D$(DEFINES) $(nl)"-I$(INCLUDES)")" -c -Fo"$(<[1]:W)" /Yc"$(>[1]:D=)" -Fp"$(<[2]:W)"
}
actions compile.rc
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