Boost logo

Boost-Build :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2005-11-20 15:50:02


Juergen Hunold wrote:
> On Friday 18 November 2005 11:53, Reece Dunn wrote:
>> Juergen Hunold wrote:
>>> I'll hack a few tests for this ....
>> Cool. I don't know much about using GCC (and how PCHs work witrh it)
>> so your help is appreciated.
>
> We'll I don't know much about gcc magic, but fortunately (UNIX)-gcc is
> much easier to handler than msv ;-))

:)

> Okay, please find my first try at pch support for gcc attached.
> It creates the pch file but somehow failes to add "-include $(PCH_FILE)"
> to the command line. Any Ideas ?

Note, I don't currently have GCC installed. However, this is what I get
for stdafx.pch...

       -x c++-header -O3 -finline-functions -Wno-inline -Wall -DNDEBUG
-I"f:\devel\drop\boost" -c -o
"..\..\..\..\build\test\pch\microsoft\gcc\release\stdafx.o"
"..\..\..\..\build\test\pch\microsoft\gcc\release\stdafx.pch"
"..\microsoft\stdafx.h"

...and main.cpp (using PCH)...

       -ftemplate-depth-100 -O3 -finline-functions -Wno-inline -Wall
-DNDEBUG -I"f:\devel\drop\boost" -include
"..\..\..\..\build\test\pch\microsoft\gcc\release\stdafx.pch" -c -o
"..\..\..\..\build\test\pch\microsoft\gcc\release\main.o"
"..\microsoft\main.cpp"

...and demo.cpp (not using PCH)...

       -ftemplate-depth-100 -O3 -finline-functions -Wno-inline -Wall
-DNDEBUG -I"f:\devel\drop\boost" -c -o
"..\..\..\..\build\test\pch\simple\gcc\release\pch-off\demo.o"
"..\simple\demo.cpp"

Is this what you wanted?

HTH,
- Reece

Index: gcc.jam
===================================================================
RCS file: /cvsroot/boost/boost/tools/build/v2/tools/gcc.jam,v
retrieving revision 1.57
diff -u -r1.57 gcc.jam
--- gcc.jam 21 Sep 2005 13:44:06 -0000 1.57
+++ gcc.jam 20 Nov 2005 20:46:55 -0000
@@ -16,6 +16,9 @@
 import set ;
 import common ;
 import errors ;
+import pch ;
+
+sp = " " ;
 
 feature.extend toolset : gcc ;
 
@@ -68,6 +71,8 @@
 generators.register-c-compiler gcc.compile.c : C : OBJ : <toolset>gcc ;
 generators.register-c-compiler gcc.compile.asm : ASM : OBJ : <toolset>gcc ;
 
+generators.register [ new pch-generator gcc.compile.pch : PCHEADER : OBJ PCH : <toolset>gcc ] ;
+
 
 # Declare flags and action for compilation
 flags gcc.compile OPTIONS <optimization>off : -O0 ;
@@ -124,7 +129,11 @@
 flags gcc.compile DEFINES <define> ;
 flags gcc.compile INCLUDES <include> ;
 
-rule compile.c++
+flags gcc.compile PCH_SOURCE <pch-source> ;
+flags gcc.compile PCH_HEADER <pch>on : <pch-header> ;
+flags gcc.compile PCH_FILE <pch>on : <pch-file> ;
+
+rule compile.c++ ( targets + : sources * : properties * )
 {
     # Some extensions are compiled as C++ by default. For others, we need
     # to pass -x c++.
@@ -133,15 +142,18 @@
     {
         LANG on $(<) = "-x c++" ;
     }
+
+ DEPENDS $(<) : [ on $(<) return $(PCH_HEADER) ] ;
+ DEPENDS $(<) : [ on $(<) return $(PCH_FILE) ] ;
 }
 
 
-actions compile.c++
+actions compile.c++ bind PCH_HEADER PCH_FILE
 {
- "$(CONFIG_COMMAND)" $(LANG) -ftemplate-depth-100 $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
+ "$(CONFIG_COMMAND)" $(LANG) -ftemplate-depth-100 $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -include$(sp)"$(PCH_FILE:W)" -c -o "$(<)" "$(>)"
 }
 
-rule compile.c
+rule compile.c ( targets + : sources * : properties * )
 {
     # If we use the name g++ then default file suffix -> language mapping
     # does not work. So have to pass -x option. Maybe, we can work around this
@@ -150,12 +162,26 @@
     #{
         LANG on $(<) = "-x c" ;
     #}
+
+ DEPENDS $(<) : [ on $(<) return $(PCH_HEADER) ] ;
+ DEPENDS $(<) : [ on $(<) return $(PCH_FILE) ] ;
 }
 
 
-actions compile.c
+actions compile.c bind PCH_HEADER PCH_FILE
 {
- "$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
+ "$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -include$(sp)"$(PCH_FILE:W)" -c -o "$(<)" "$(>)"
+}
+
+
+rule compile.pch ( targets + : sources * : properties * )
+{
+ DEPENDS $(<) : [ on $(<) return $(PCH_SOURCE) ] ;
+}
+
+actions compile.pch bind PCH_SOURCE
+{
+ "$(CONFIG_COMMAND)" $(LANG) -x c++-header $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
 }
 
 rule compile.asm


# 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) ;
    }
}


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