#! /usr/bin/env python
# encoding: utf-8
# Richard Quirk, 2008

import UnitTest, Utils

srcdir = '.'
blddir = 'build'

def set_options(opt):
	opt.tool_options('compiler_cxx')

def configure(conf):
	conf.check_tool('compiler_cxx')

	# this one requires cppunit
	conf.check_cfg(package='cppunit', args='--cflags --libs')
	if 'LIB_CPPUNIT' in conf.env:
		if 'dl' not in conf.env['LIB_CPPUNIT']:
			l = conf.check(lib='dl', uselib_store='CPPUNIT')
		Utils.pprint('CYAN', "To run unit tests use 'waf check'")
	else:
		conf.fatal('Install cppunit')

def build(bld):
	# process subfolders from here
	subdirs = 'src'
	# if cppunit was found in the config step, build unit tests too
	if bld.env['LIB_CPPUNIT']:
		subdirs += ' tests'
	bld.add_subdirs(subdirs)

def shutdown():
	# Unit tests are run when "check" target is used
	ut = UnitTest.unit_test()
	ut.change_to_testfile_dir = True
	ut.run()
	ut.print_results()
