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

import UnitTest, Params

srcdir = '.'
blddir = 'build'

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

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

	# this one requires cppunit
	pkgconfig = conf.create_pkgconfig_configurator()
	pkgconfig.name = 'cppunit'
	pkgconfig.run()
	if conf.is_defined('HAVE_CPPUNIT'):
		if 'dl' not in conf.env['LIB_CPPUNIT']:
			l = conf.create_library_configurator()
			l.name = 'dl'
			l.uselib = 'CPPUNIT'
			l.run()
		Params.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()['HAVE_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()
