packetize Phong shader
new scons config options:
simd=(yes|no) - allow/suppress explicit SSE
force_flags=(yes|no) - force use of specified flags instead of autodetected
profile=(yes|no) - enable gcc's profiling (-pg option)
check for pthread.h header, don't try to build without it
add fourth Vector3 component for better memory aligning
rename Vector3 to Vector
partialy SSE-ize Vector class (only fully vertical operations)
build static lib and python module in distinctive directories
to avoid collision of library file names on some platforms
Help("""
Targets:
all - build everything,
libs - build all libraries
demos - build all demos
models - download/prepare all models
docs - compile doxygen documentation
libs = (static-lib, python-module)
static-lib - ray tracer library to link with
python-module - ray tracer module for Python
demos = (python-demos, cc-demos)
python-demos - Python demos, this depends on python-module
cc-demos - C++ demos
models = (local-models, download-models)
local-models - prepare local models
download-models - download models which are not locally available
no-docs = (libs, demos, models)
- everything but docs
no-download = (libs, demos, local-models)
- 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')
opt = Options(['.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', ""),
BoolOption('force_flags', "use only flags specified by 'flags' option (do not autodetect arch/sse flags)", False),
BoolOption('profile', "enable gcc's profiling support (-pg)", False),
)
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))
### configure
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
def CheckIntelC(context):
global intelc, intelcversion
context.Message('Checking for Intel C++ Compiler... ')
intelc = Tool("intelc").exists(env) == True
if intelc:
testenv = Environment()
Tool("intelc").generate(testenv)
intelcversion = str(testenv['INTEL_C_COMPILER_VERSION']/10.)
context.Result(intelcversion)
else:
intelcversion = ''
context.Result(intelc)
return intelc
def CheckGCC(context):
global gcc, gccversion
context.Message('Checking for GCC... ')
gcc = "g++" in env['TOOLS']
if gcc:
gccversion = env['CCVERSION']
context.Result(gccversion)
else:
gccversion = ''
context.Result(False)
return gcc
def CheckCPUFlags(context):
global cpu, cpuflags_gcc, cpuflags_intelc
context.Message('Checking CPU arch and flags... ')
env.Execute('@$CC tools/cpuflags.c -o tools/cpuflags')
(cpu, cpuflags_gcc, cpuflags_intelc) = os.popen('tools'+os.sep+'cpuflags %s %s'
% (''.join(gccversion.rsplit('.',1)), intelcversion) ).read().split('\n')[:3]
context.Result(cpu)
return True
conf = Configure(env,
custom_tests = {
'CheckPlatform' : CheckPlatform, 'CheckCPUFlags' : CheckCPUFlags,
'CheckIntelC' : CheckIntelC, 'CheckGCC' : CheckGCC})
conf.CheckPlatform()
conf.CheckGCC()
conf.CheckIntelC()
conf.CheckCPUFlags()
if intelc and conf.env['intelc']:
Tool("intelc").generate(conf.env)
cc = 'intelc'
elif gcc:
cc = 'gcc'
add_flags = ''
if cc == 'gcc':
add_flags += cpuflags_gcc + ' -ffast-math '
if cc == 'intelc':
add_flags += cpuflags_intelc + ' '
if conf.env['force_flags']:
add_flags = conf.env['flags'] + ' '
else:
add_flags += conf.env['flags'] + ' '
if conf.env['precision'] == 'double':
add_flags += '-DPYRIT_DOUBLE '
elif cc == 'gcc':
add_flags += '-fsingle-precision-constant '
if not conf.env['simd']:
add_flags += '-DNO_SSE '
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
else:
print "No supported compiler found."
Exit(1)
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'])
if not conf.CheckCHeader('pthread.h'):
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.env['profile'] and cc == 'gcc':
conf.env.Append(CCFLAGS="-pg", LINKFLAGS="-pg")
env = conf.Finish()
### 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})
SConscript('ccdemos/SConscript', build_dir='build/ccdemos', duplicate=0, exports='env 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('models/SConscript')
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')