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
vcproj - generate project files for Visual C++ Studio
Default target is no-download.
Options:
""")
import os, sys
EnsurePythonVersion(2, 3)
EnsureSConsVersion(0, 97)
Decider('MD5-timestamp')
SConsignFile('build/.sconsign.dblite')
env = Environment(tools = ['default'], CPPPATH = ['.','#include','#build/include'])
vars = Variables(files=['build/.varscache'])
vars.AddVariables(
BoolVariable('simd', 'allow SSE intrinsics', True),
('precision', 'floating point number precision (single/double)', "single"),
('flags', 'add additional compiler flags', ""),
BoolVariable('force_flags', "use only flags specified by 'flags' option (do not autodetect arch/sse flags)", False),
('ldflags', 'add additional linker flags', ""),
BoolVariable('profile', "enable gcc's profiling support (-pg)", False),
BoolVariable('intelc', 'use Intel C++ Compiler, if available', False),
)
vars.Update(env)
vars.Save('build/.varscache', env)
Help(vars.GenerateHelpText(env))
if env.GetOption('help') == True or env.GetOption('clean') == True:
Return()
### 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'
context.Result(platform)
return True
intelcversion = ''
def CheckIntelC(context):
global intelc, intelcversion
context.Message('Checking for IntelC 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:
context.Result(intelc)
return intelc
def CheckGCC(context):
global gcc, gccversion
context.Message('Checking for GCC compiler... ')
testenv = Environment()
gcc = "g++" in testenv['TOOLS']
if gcc:
gccversion = testenv['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_dir = "#build/.sconf_temp"
log_file="#build/config.log"
config_h="#build/include/config.h"
conf = Configure(env, conf_dir=conf_dir, log_file=log_file, config_h=config_h,
clean=False, help=False,
custom_tests = {
'CheckPlatform' : CheckPlatform,
'CheckCPUFlags' : CheckCPUFlags,
'CheckIntelC' : CheckIntelC,
'CheckGCC' : CheckGCC,
})
conf.CheckPlatform()
conf.CheckGCC()
conf.CheckIntelC()
if intelc and (not gcc or conf.env['intelc']):
Tool('intelc').generate(conf.env)
cc = 'intelc'
elif gcc:
cc = 'gcc'
else:
cc = 'none'
if cc == 'intelc' or cc == 'gcc':
conf.CheckCPUFlags()
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':
conf.Define("PYRIT_DOUBLE")
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)
# Other useful flags:
# -Wunsafe-loop-optimizations -Wpointer-arith -Wcast-align -Wconversion
# -Wmissing-noreturn -Winline -Wdisabled-optimization
else:
print "No supported compiler found."
Exit(1)
print "Using compiler: " + cc
print "Additional flags: " + add_flags
if conf.env['profile'] and cc == 'gcc':
conf.env.Append(CCFLAGS="-pg", LINKFLAGS="-pg")
if conf.env['ldflags']:
conf.env.Append(LINKFLAGS=conf.env['ldflags'])
# configure pthread
conf.env.Append(CCFLAGS="-pthread ")
# configure libpng
conf.CheckLibWithHeader('zlib', 'zlib.h', 'C')
if conf.CheckLibWithHeader('libpng', 'png.h', 'C'):
conf.Define('HAVE_PNG')
env = conf.Finish()
# configure Python
pyenv = env.Clone()
have_python = True
try:
pyenv.ParseConfig('python-config --includes --libs')
except:
have_python = False
if not have_python:
print "Error: Python is required."
Exit(1)
# configure SDL
sdlenv = env.Clone()
try:
sdlenv.ParseConfig('sdl-config --cflags')
sdlenv.ParseConfig('sdl-config --libs')
except:
pass
def CheckSDL(context):
global have_sdl
context.Message('Checking for SDL... ')
if context.TryLink("#include <SDL.h>\n"+
"int main(int argc,char **argv){return 0;}", '.cc'):
context.Result(1)
return True
else:
context.Result("no (some demos won't be built)")
return False
conf = Configure(sdlenv, conf_dir=conf_dir, log_file=log_file, config_h=config_h,
clean=False, help=False,
custom_tests = {'CheckSDL' : CheckSDL} )
have_sdl = conf.CheckSDL()
sdlenv = conf.Finish()
### build targets
Export('env pyenv sdlenv have_sdl cc')
lib = SConscript('src/SConscript', variant_dir='build/lib', duplicate=0,
exports={'buildmodule':False})
pymodule = SConscript('src/SConscript', variant_dir='build/pymodule', duplicate=0,
exports={'buildmodule':True})
SConscript('ccdemos/SConscript', variant_dir='build/ccdemos', duplicate=0, exports='lib')
SConscript('demos/SConscript', exports='pymodule')
SConscript('tests/SConscript', variant_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')