#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2006 (ita)

"""
for some obscure reason, the precompiled header will not be taken if
all.h is in the same directory as main.cpp
we recommend to add the header to compile in a separate directory without any sources

Note: the #warning will come once when the .h is compiled, it will not come when the .cpp is compiled
"""

from TaskGen import taskgen, feature, after
import Task, ccroot

@taskgen
@feature('cxx')
@after('apply_link')
def process_pch(self):
	if getattr(self, 'pch', ''):
		node = self.path.find_resource(self.pch)
		if not node:
			print "not a valid header !"
			return
		tsk = self.create_task('gchx')
		tsk.set_inputs(node)
		tsk.set_outputs(node.parent.find_or_declare(node.name + '.gch'))
		tsk.defines = self.scanner_defines
		tsk.env = self.env.copy()

cls = Task.simple_task_type('gchx', '${CXX} ${CXXFLAGS} ${CPPFLAGS} ${_CXXINCFLAGS} ${_CXXDEFFLAGS} ${SRC} -o ${TGT}')
cls.scan = ccroot.scan
cls.before = 'cxx'

def build(bld):
	obj = bld.new_task_gen('cxx', 'program')
	obj.source = 'main.cpp'
	obj.includes='. subdir'
	obj.target='test'
	obj.pch = 'subdir/all.h'

def configure(conf):
	conf.check_tool('g++')

def set_options(opt):
	pass

VERSION='0.0.1'
APPNAME='pch_test'

srcdir = '.'
blddir = 'build'

