SConstruct
branchpyrit
changeset 92 9af5c039b678
parent 91 9d66d323c354
child 93 96d65f841791
--- a/SConstruct	Fri May 02 13:27:47 2008 +0200
+++ b/SConstruct	Mon May 05 15:31:14 2008 +0200
@@ -30,12 +30,22 @@
 """)
 
 import os, sys
-env = Environment() #(ENV = {'PATH' : os.environ['PATH']})
+
+EnsurePythonVersion(2, 3)
+EnsureSConsVersion(0, 97)
+
 Decider('MD5-timestamp')
+SConsignFile('build/.sconsign.dblite')
 
-opt = Options(['.optioncache'])
+if sys.platform == 'win32':
+	tools = ['mingw']
+else:
+	tools = ['default']
+
+env = Environment(tools = tools)
+
+opt = Options(['build/.optioncache'])
 opt.AddOptions(
-	BoolOption('intelc', 'use Intel C++ Compiler, if available', True),
 	BoolOption('simd', 'allow SSE intrinsics', True),
 	('precision', 'floating point number precision (single/double)', "single"),
 	('flags', 'add additional compiler flags', ""),
@@ -44,11 +54,18 @@
 )
 if env['PLATFORM'] == 'win32':
 	opt.AddOptions(
+		BoolOption('msvc', 'use Microsoft Visual C++ Compiler, if available', True),
 		('pythonpath', 'path to Python installation',
 			'C:\\Python%c%c' % (sys.version[0], sys.version[2])),
-		)
+	)
+else:
+	opt.AddOptions(
+		BoolOption('intelc', 'use Intel C++ Compiler, if available', True),
+	)
+
+
 opt.Update(env)
-opt.Save('.optioncache', env)
+opt.Save('build/.optioncache', env)
 Help(opt.GenerateHelpText(env))
 
 
@@ -69,7 +86,7 @@
 
 def CheckIntelC(context):
 	global intelc, intelcversion
-	context.Message('Checking for Intel C++ Compiler... ')
+	context.Message('Checking for IntelC compiler... ')
 	intelc = Tool("intelc").exists(env) == True
 	if intelc:
 		testenv = Environment()
@@ -83,7 +100,7 @@
 
 def CheckGCC(context):
 	global gcc, gccversion
-	context.Message('Checking for GCC... ')
+	context.Message('Checking for GCC compiler... ')
 	gcc = "g++" in env['TOOLS']
 	if gcc:
 		gccversion = env['CCVERSION']
@@ -93,6 +110,19 @@
 		context.Result(False)
 	return gcc
 
+def CheckMSVC(context):
+	global msvc, msvcversion
+	context.Message('Checking for MSVC compiler... ')
+	testenv = Environment()
+	msvc = "msvc" in testenv['TOOLS']
+	if msvc:
+		msvcversion = testenv['MSVS_VERSION']
+		context.Result(msvcversion)
+	else:
+		msvcversion = ''
+		context.Result(False)
+	return msvc
+
 def CheckCPUFlags(context):
 	global cpu, cpuflags_gcc, cpuflags_intelc
 	context.Message('Checking CPU arch and flags... ')
@@ -102,26 +132,51 @@
 	context.Result(cpu)
 	return True
 
-conf = Configure(env,
+conf_dir = "#/build/.sconf_temp"
+log_file="#/build/config.log"
+config_h="#/include/config.h"
+conf = Configure(env, conf_dir=conf_dir, log_file=log_file, config_h=config_h,
 	custom_tests = {
 		'CheckPlatform' : CheckPlatform, 'CheckCPUFlags' : CheckCPUFlags,
-		'CheckIntelC' : CheckIntelC, 'CheckGCC' : CheckGCC})
+		'CheckIntelC' : CheckIntelC, 'CheckGCC' : CheckGCC, 'CheckMSVC' : CheckMSVC})
 conf.CheckPlatform()
+
 conf.CheckGCC()
-conf.CheckIntelC()
-conf.CheckCPUFlags()
+if platform == 'win32':
+	conf.CheckMSVC()
+	intelc = False
+else:
+	conf.CheckIntelC()
+	msvc=False
 
-if intelc and conf.env['intelc']:
-	Tool("intelc").generate(conf.env)
+if intelc or gcc:
+	conf.CheckCPUFlags()
+
+if intelc and (not gcc or conf.env['intelc']):
+	Tool('intelc').generate(conf.env)
 	cc = 'intelc'
+elif msvc and (not gcc or conf.env['msvc']):
+	Tool('default').generate(conf.env)
+	conf.Define("MSVC")
+	cc = 'msvc'
 elif gcc:
 	cc = 'gcc'
+else:
+	cc = 'none'
+
+if platform == 'win32' and cc == 'gcc':
+	conf.env.Append(LIBPATH=["C:/mingw/lib", "C:/msys/mingw/lib"])
+	conf.env.Append(CPPPATH=["C:/mingw/include", "C:/msys/mingw/include"])
 
 add_flags = ''
 if cc == 'gcc':
 	add_flags += cpuflags_gcc + ' -ffast-math '
 if cc == 'intelc':
 	add_flags += cpuflags_intelc + ' '
+if cc == 'msvc':
+	add_flags += '/fp:fast '
+	if conf.env['simd']:
+		add_flags += '/arch:SSE '
 
 if conf.env['force_flags']:
 	add_flags = conf.env['flags'] + ' '
@@ -129,18 +184,19 @@
 	add_flags += conf.env['flags'] + ' '
 
 if conf.env['precision'] == 'double':
-	add_flags += '-DPYRIT_DOUBLE '
+	conf.Define("PYRIT_DOUBLE")
 elif cc == 'gcc':
 	add_flags += '-fsingle-precision-constant '
 
-if not conf.env['simd']:
-	add_flags += '-DNO_SSE '
+if not conf.env['simd'] or conf.env['precision'] == 'double':
+	conf.Define("NO_SIMD")
 
 if cc == 'intelc':
 	conf.env.Append(CCFLAGS="-O3 -w1 " + add_flags)
 elif cc == 'gcc':
 	conf.env.Append(CCFLAGS="-O3 -Wall -pipe " + add_flags)
-	# CCFLAGS= -fno-strict-aliasing
+elif cc == 'msvc':
+	conf.env.Append(CCFLAGS="/Ox /Ob2 /GS- /Gy /GF /GR- /Zp16 /MD /EHsc /vmb " + add_flags)
 else:
 	print "No supported compiler found."
 	Exit(1)
@@ -148,47 +204,79 @@
 print "Using compiler: " + cc
 print "Additional flags: " + add_flags
 
-if conf.CheckLibWithHeader('png', 'png.h', 'C'):
-	conf.env.Append(CCFLAGS='-DHAVE_PNG')
-	conf.env.Append(LIBS=['png'])
+pthread = True
+if conf.env['PLATFORM'] == 'win32':
+	if cc == 'msvc':
+		if not conf.CheckLib('pthreadVC2'):
+			pthread = False
+		conf.env.Append(LIBS=["pthreadVC2"])
+	elif cc == 'gcc':
+		if not conf.CheckLib('pthreadGC2'):
+			pthread = False
+		conf.env.Append(LIBS=["pthreadGC2"])
+else:
+	conf.env.Append(CCFLAGS="-pthread ")
 
-if not conf.CheckCHeader('pthread.h'):
+if not pthread:
 	print 'Error: Cannot build without pthread.'
 	Exit(1)
 
-if conf.env['PLATFORM'] == 'win32':
-	conf.env.Append(LIBS=["pthreadGC2"])
-else:
-	conf.env.Append(CCFLAGS="-pthread ")
+if conf.CheckLibWithHeader('png', 'png.h', 'C'):
+	conf.Define('HAVE_PNG')
+	conf.env.Append(LIBS=['png'])
+elif conf.CheckLib('libpng13'):
+	conf.Define('HAVE_PNG')
+	conf.env.Append(LIBS=['libpng13'])
 
 if conf.env['profile'] and cc == 'gcc':
 	conf.env.Append(CCFLAGS="-pg", LINKFLAGS="-pg")
 
 env = conf.Finish()
 
+# configure SDL
+sdlenv = env.Clone()
+if cc != 'msvc':
+	try:
+		sdlenv.ParseConfig('sh sdl-config --cflags')
+		sdlenv.ParseConfig('sh sdl-config --libs')
+	except:
+		pass
+else:
+	sdlenv.Append(LIBS=['SDL', 'SDLmain'])
+
+conf = Configure(sdlenv, conf_dir=conf_dir, log_file=log_file, config_h=config_h)
+have_sdl = False
+if conf.CheckLib('SDL'):
+	have_sdl = True
+else:
+	print "SDL not found, some demos will not built."
+sdlenv = conf.Finish()
+
+if cc == 'msvc':
+	sdlenv.Append(LINKFLAGS="/SUBSYSTEM:WINDOWS")
 
 ### build targets
 
-lib = SConscript('src/SConscript', build_dir='build/lib', duplicate=0, exports={'env':env,'buildmodule':False})
-pymodule = SConscript('src/SConscript', build_dir='build/pymodule', duplicate=0, exports={'env':env,'buildmodule':True})
+Export('env sdlenv cc')
+lib = SConscript('src/SConscript', build_dir='build/lib', duplicate=0,
+	exports={'buildmodule':False})
+pymodule = SConscript('src/SConscript', build_dir='build/pymodule', duplicate=0,
+	exports={'buildmodule':True})
 
-SConscript('ccdemos/SConscript', build_dir='build/ccdemos', duplicate=0, exports='env lib')
+if have_sdl:
+	SConscript('ccdemos/SConscript', build_dir='build/ccdemos', duplicate=0,
+		exports='lib')
+
 SConscript('demos/SConscript', exports='pymodule')
-env.Alias('demos', ['cc-demos', 'python-demos'])
-
-SConscript('tests/SConscript', build_dir='build/tests', duplicate=0, exports='env lib')
-
+SConscript('tests/SConscript', build_dir='build/tests', duplicate=0, exports='lib')
 SConscript('models/SConscript')
 
+env.Alias('demos', ['cc-demos', 'python-demos'])
 env.Alias('libs', ['static-lib', 'python-module'])
-
 env.Alias('docs', Command('docs/html', [], 'doxygen'))
 env.Clean('docs', ['docs/html'])
-
 env.Alias('no-docs', ['libs', 'demos', 'models'])
 env.Alias('no-download', ['libs', 'demos', 'local-models'])
-
 env.Alias('all', ['no-docs', 'docs'])
-
 env.Alias('pyrit', 'no-download')
 Default('pyrit')