#!/usr/bin/python
import sys, os

sys.path.append('../libs')
from buildtools import *
# CLAM unit tests build

clamToolPath="../sconstools"

options = Options('options.cache')

options.Add( PathOption( 'clam_prefix', 'Prefix were CLAM was installed', '/usr/local') )
options.Add( PathOption( 'install_prefix', 'Prefix where Network editor is going to be installed', '/usr/local') )
if sys.platform == 'win32' :
	options.Add( PathOption( 'cppunit_prefix', 'Prefix were cppunit was installed', '' ))
options.Add( BoolOption( 'release', 'Build CLAM Tests enabling compiler optimizations', 'no') )
options.Add( PathOption( 'test_data_path', 'Path to the TestDataPrefix', '') )

env = Environment( ENV=os.environ, tools=['default', 'clam'], toolpath=[clamToolPath], options=options)

options.Update(env)
options.Save('options.cache', env)
Help(options.GenerateHelpText(env))

env['project'] = 'CLAMTests'

libraries = [
	'clam_core',
	'clam_processing',
	'clam_audioio',
]

env.SConsignFile() # Single signature file

env.EnableClamModules(libs=libraries, path=env['clam_prefix'])
if sys.platform != 'win32' :
#	env.ParseConfig( 'pkg-config --cflags --libs cppunit') #cppunit.pc doesn't exist in ubuntu
	env.Append( LIBS=['cppunit'])
	if env['release'] :
		env.Append( CCFLAGS=['-O3','-fomit-frame-pointer','-Wall'] )
	else :
		env.Append( CCFLAGS=['-g', '-Wall'] )
else :
	env.Append( LIBS=['cppunit_vc7'] )
	env.Append( CPPPATH=[env['cppunit_prefix']+'/include'] )
	env.Append( LIBPATH=[env['cppunit_prefix']+'/lib'] )
	if env['release'] :
		env.Append( CPPFLAGS = ['-DWIN32'] )
		env.Append( CCFLAGS = '/FD /GR /GX /MD /O2 /GL /W3 /Zm1000' )	
		env.Append( LINKFLAGS = ['/LTCG'] )
	else :
		env.Append( CPPFLAGS = ['-DWIN32', '-D_DEBUG'] )
		env.Append( CCFLAGS = '/D /FD /GR /GX /GZ /MDd /Od /W3 /ZI /Zm1000' )
		env.Append( LINKFLAGS = ['/OPT:NOREF', '/OPT:NOICF', '/DEBUG'] )

#TODO: KLUDGE to allow old style and new style CLAM headers
env.Append(CPPPATH=env['clam_prefix']+'/include/CLAM')
env.Append(CPPPATH=env['clam_prefix']+'/include')
env.Append(CPPPATH='include')
env.Append(CPPPATH=os.path.join('..','..','..','test','UnitTests', 'CommonHelpers'))
env.Append(CPPPATH=os.path.join('..','..','..','test','UnitTests'))
env.Append(CPPPATH=os.path.join('..','..','..','test','FunctionalTests','CommonHelpers'))

Export( 'env' )
SConscript('unit_tests/SConscript')
SConscript('functional_tests/SConscript')

Alias( 'all', ['run_unit_tests','run_functional_tests'] )
