import thirdparty
import os

def buildCMake(context, sourceDir):
    os.chdir(sourceDir)
    os.spawnl(os.P_WAIT, 'bootstrap', 'bootstrap', '--prefix='+context.sconf.env['THIRDPARTY_STAGEDIR'])

    make = context.sconf.env['MAKE']
    os.spawnl(os.P_WAIT, make, make)
    os.spawnl(os.P_WAIT, make, make, 'install')

def cmakeConfig(context):
    context.Message('Searching for program cmake...')
    result = thirdparty.searchForProgram(context.sconf.env, 'CMAKE', 'cmake')
    context.Result(result)
    return result

def checkCMake(context):
	    return thirdparty.configureDependency(context,
                                          cmakeConfig,
                                          downloadSource=('http://interreality.org/~tetron/',
                                                          'cmake-2.4.6.tar.gz',
                                                          'cmake-2.4.6',
							  2604547,
							  'c99c747ad8e9bfb3bef9cca875a52129'),
                                          buildFunc=buildCMake)
	    

import scripts
scripts.AddCustomTest('CheckCMake', checkCMake)
