basic detection of compiler (GCC or ICC) and CPU capabilities
try to detect Python path in Windows and allow direct specification through build option
plus other build system fixes
--- a/.bzrignore Wed Apr 09 17:55:29 2008 +0200
+++ b/.bzrignore Thu Apr 10 23:20:36 2008 +0200
@@ -1,3 +1,6 @@
build/*
docs/*
.sconsign.dblite
+.sconf_temp
+.optioncache
+config.log
--- a/SConstruct Wed Apr 09 17:55:29 2008 +0200
+++ b/SConstruct Thu Apr 10 23:20:36 2008 +0200
@@ -25,32 +25,116 @@
- everything but docs and downloadable models
Default target is no-download.
+
+Options:
""")
+import os, sys
+env = Environment(ENV = {'PATH' : os.environ['PATH']})
Decider('MD5-timestamp')
-import os
-env = Environment(ENV = {'PATH' : os.environ['PATH']})
+
+opt = Options(['.optioncache'])
+opt.AddOptions(
+ BoolOption('intelc', 'use Intel C++ Compiler, if available', True),
+ ('flags', 'add additional compiler flags', ""),
+)
+if env['PLATFORM'] == 'win32':
+ opt.AddOptions(
+ ('pythonpath', 'path to Python installation',
+ 'C:\\Python%c%c' % (sys.version[0], sys.version[2])),
+ )
+opt.Update(env)
+opt.Save('.optioncache', env)
+Help(opt.GenerateHelpText(env))
+
+if env['intelc']:
+ Tool("intelc")(env)
-### GNU C++ Compiler
-#env.Replace(CXX="g++")
-#env.Append(CCFLAGS="-O3 -Wall -pipe -ffast-math -msse3 ")
+platform = 'unknown'
+def CheckPlatform(context):
+ global platform
+ context.Message('Platform is... ')
+ if sys.platform[:5] == 'linux':
+ platform = 'linux'
+ elif env['PLATFORM'] == 'posix':
+ platform = 'posix'
+ elif env['PLATFORM'] == 'win32':
+ platform = 'win32'
+ context.Result(platform)
+ return True
+
+cpu = 'unknown'
+def CheckCPU(context):
+ global cpu, platform
+ context.Message('Checking CPU model... ')
+ if (platform == 'linux'):
+ if (os.system("cat /proc/cpuinfo | grep 'Core(TM)2 CPU' >/dev/null") == 0):
+ cpu = 'core2'
+ context.Result(cpu)
+ return True
-### Intel C++ Compiler
-env.Replace(CXX="icpc")
-env.Append(CCFLAGS="-O3 -w1 -mtune=core2 -xT ")
+def CheckIntelC(context):
+ global intelc
+ context.Message('Checking for Intel C++ Compiler... ')
+ intelc = "intelc" in env['TOOLS']
+ context.Result(intelc)
+ return intelc
+
+def CheckGCC(context):
+ global gcc, gccversion
+ context.Message('Checking for GCC... ')
+ gcc = "g++" in env['TOOLS']
+ if gcc:
+ gccversion = os.popen("g++ --version").read().split()[2]
+ context.Result(gccversion)
+ else:
+ context.Result(False)
+ return gcc
+
+conf = Configure(env,
+ custom_tests = {
+ 'CheckPlatform' : CheckPlatform, 'CheckCPU' : CheckCPU,
+ 'CheckIntelC' : CheckIntelC, 'CheckGCC' : CheckGCC})
+conf.CheckPlatform()
+conf.CheckCPU()
+conf.CheckGCC()
+conf.CheckIntelC()
+env = conf.Finish()
-### MinGW32
-# PY_CCFLAGS=-I"C:\Program Files\Python25\include"
-# PY_LDFLAGS=-L"C:\Program Files\Python25\libs" -lpython25
+if intelc:
+ cc = 'intelc'
+elif gcc:
+ cc = 'gcc'
+
+cpu_flags = ''
+if cc == 'gcc':
+ cpu_flags += '-ffast-math '
+if cpu == 'core2':
+ if (cc == 'intelc' or gccversion[:3] == '4.3'):
+ cpu_flags += '-march=core2 -mtune=core2 '
+ if cc == 'intelc':
+ cpu_flags += '-xT '
+ if cc == 'gcc':
+ cpu_flags += '-msse3 -mfpmath=sse '
+cpu_flags += env['flags']
+
+if intelc:
+ env.Append(CCFLAGS="-O3 -w1 " + cpu_flags)
+elif gcc:
+ env.Append(CCFLAGS="-O3 -Wall -pipe " + cpu_flags)
+ # CCFLAGS= -fno-strict-aliasing
+else:
+ print "No supported compiler found."
+ Exit(1)
+
+print "Additional compiler flags: " + cpu_flags
# pthread
if env['PLATFORM'] == 'win32':
- env.Append(LINKFLAGS="-lpthreadGC2 ")
+ env.Append(LIBS=["pthreadGC2"])
else:
env.Append(CCFLAGS="-pthread ")
-# CCFLAGS=-g -fno-strict-aliasing
-
# float: -fsingle-precision-constant
# double: -DPYRIT_DOUBLE
(lib, pymodule) = SConscript('src/SConscript', build_dir='build/lib', duplicate=0, exports='env')
--- a/ccdemos/SConscript Wed Apr 09 17:55:29 2008 +0200
+++ b/ccdemos/SConscript Thu Apr 10 23:20:36 2008 +0200
@@ -1,11 +1,9 @@
Import('env lib')
-env.Append(CPPPATH = ['.','#include'], LIBPATH='#build/lib', LIBS='pyrit')
+env.Append(CPPPATH = ['.','#include'], LIBPATH='#build/lib')
+env.Prepend(LIBS=['pyrit','png'])
-import os
-SDL_CCFLAGS = os.popen('sdl-config --cflags').read()
-SDL_LDFLAGS = os.popen('sdl-config --libs').read()
sdlenv = env.Clone()
-sdlenv.Append(LINKFLAGS=SDL_LDFLAGS, CCFLAGS=SDL_CCFLAGS)
+sdlenv.ParseConfig('sh sdl-config --cflags --libs')
l = []
image_obj = env.Object('image.c', CC="$CXX")
@@ -13,7 +11,7 @@
l.append( sdlenv.Program(['realtime.cc']) )
l.append( sdlenv.Program(['realtime_bunny.cc']) )
l.append( sdlenv.Program(['realtime_dragon.cc']) )
-l.append( sdlenv.Program(['spheres_shadow.cc']+image_obj, LIBS="$LIBS:png") )
-l.append( sdlenv.Program(['textures.cc']+image_obj, LIBS="$LIBS:png") )
+l.append( sdlenv.Program(['spheres_shadow.cc']+image_obj) )
+l.append( sdlenv.Program(['textures.cc']+image_obj) )
env.Alias('cc-demos', l)
--- a/demos/SConscript Wed Apr 09 17:55:29 2008 +0200
+++ b/demos/SConscript Thu Apr 10 23:20:36 2008 +0200
@@ -12,6 +12,7 @@
for file in files:
l.append( env.Copy('#build/demos/'+file, file) )
-l.append( env.Copy('#build/demos/'+str(pymodule[0]).split('/')[-1], str(pymodule[0])) )
+import os
+l.append( env.Copy('#build/demos/'+str(pymodule[0]).split(os.sep)[-1], str(pymodule[0])) )
env.Alias('python-demos', l)
--- a/demos/lworeader.py Wed Apr 09 17:55:29 2008 +0200
+++ b/demos/lworeader.py Thu Apr 10 23:20:36 2008 +0200
@@ -42,7 +42,7 @@
faces = []
tags = []
surfaces = []
- f = file(filename)
+ f = file(filename, 'rb')
(ID,size) = read_chunk(f)
form = f.read(4)
if (ID != 'FORM' or form != 'LWOB'):
--- a/src/SConscript Wed Apr 09 17:55:29 2008 +0200
+++ b/src/SConscript Thu Apr 10 23:20:36 2008 +0200
@@ -1,11 +1,19 @@
Import('env')
env.Append(CPPPATH = '#include')
-import os
-PY_CCFLAGS = os.popen('python-config --includes').read()
-PY_LDFLAGS = os.popen('python-config --libs').read()
pyenv = env.Clone()
-pyenv.Append(LINKFLAGS=PY_LDFLAGS, CCFLAGS=PY_CCFLAGS)
+if env['PLATFORM'] == 'win32':
+ import sys
+ pythonver = '%c%c' % (sys.version[0], sys.version[2])
+ pythonlib = 'python'+pythonver
+ pythonpath = [env['pythonpath'],
+ 'C:\\Program Files\\Python'+pythonver]
+ pyenv.Append(LIBS=pythonlib)
+ pyenv.Append(CPPPATH=[s+'\\include' for s in pythonpath])
+ pyenv.Append(LIBPATH=[s+'\\libs' for s in pythonpath])
+ pyenv.Replace(SHLIBSUFFIX='.pyd')
+else:
+ pyenv.ParseConfig('python-config --includes --libs')
sources = [
'raytracer.cc', 'scene.cc', 'sampler.cc',
@@ -17,7 +25,7 @@
objs.append( env.Object(src) )
shared_objs.append( env.SharedObject(src) )
-pymodule = pyenv.SharedLibrary(
+pymodule = pyenv.SharedLibrary('raytracer',
['raytracermodule.cc']+shared_objs,
SHLIBPREFIX = '',
CCFLAGS = '$CCFLAGS -Wno-write-strings')