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

# CLAM unit tests build

clamToolPath="../scons/sconstools"

options = Variables('options.cache')

options.Add( PathVariable( 'clam_prefix', 'Prefix were CLAM was installed', '') )
options.Add( PathVariable( 'prefix', 'Prefix were CLAM was installed', '/usr/local') )
options.Add( BoolVariable( 'release', 'Build CLAM Tests enabling compiler optimizations', 'no') )
options.Add( PathVariable( 'test_data_path', 'Path to the TestDataPrefix', '') )

options.Add(BoolVariable('crossmingw', 'Using MinGW crosscompiler mode in linux', 'no') )
options.Add(BoolVariable('verbose', 'Display the full command line instead a short command description', 'no') )

toolchain='default'
if sys.platform == 'win32': toolchain = 'mingw'
env = Environment(ENV=os.environ, tools=[toolchain], options=options)
env.Tool('clam', toolpath=[clamToolPath])

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

env.SConsignFile() # Single signature file

env['project'] = 'CLAMTests'
env['CXXFILESUFFIX'] = '.cxx'
env['QT4_UICDECLSUFFIX'] = '.hxx'
env.moveIntermediateInto('generated')
env.activateColorCommandLine()
if not env['verbose']: env.ClamQuietCompilation()


crosscompiling = env["crossmingw"]
if crosscompiling :
	env.Tool('crossmingw', toolpath=[clamToolPath])

env.moveIntermediateInto('generated')
env.activateColorCommandLine()
if not env['verbose']: env.ClamQuietCompilation()

env.EnableClamModules([
	'clam_core',
	'clam_audioio',
	'clam_processing'
	], env['clam_prefix'] )

env.ParseConfig( 'pkg-config --cflags --libs cppunit xerces-c libxml++-2.6')

env.Append( CPPFLAGS = ['-DTEST_DATA_PATH="\\"%s\\""' % env['test_data_path'] ] )
env.Append( CPPFLAGS = ['-DCLAM_MODULE="\\"tests\\""'] )

if sys.platform == 'darwin':
	env.AppendUnique( LIBS=['xerces-c'] )
	env.AppendUnique( LIBPATH=['/opt/local/lib'] )

#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('..','UnitTests', 'CommonHelpers'))
env.Append(CPPPATH=os.path.join('..','UnitTests'))
env.Append(CPPPATH=os.path.join('..','FunctionalTests','CommonHelpers'))

Export( 'env' )
SConscript('UnitTests/SConscript')
SConscript('FunctionalTests/SConscript')

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

