SConstruct
branchpyrit
changeset 92 9af5c039b678
parent 91 9d66d323c354
child 93 96d65f841791
equal deleted inserted replaced
91:9d66d323c354 92:9af5c039b678
    28 
    28 
    29 Options:
    29 Options:
    30 """)
    30 """)
    31 
    31 
    32 import os, sys
    32 import os, sys
    33 env = Environment() #(ENV = {'PATH' : os.environ['PATH']})
    33 
       
    34 EnsurePythonVersion(2, 3)
       
    35 EnsureSConsVersion(0, 97)
       
    36 
    34 Decider('MD5-timestamp')
    37 Decider('MD5-timestamp')
    35 
    38 SConsignFile('build/.sconsign.dblite')
    36 opt = Options(['.optioncache'])
    39 
       
    40 if sys.platform == 'win32':
       
    41 	tools = ['mingw']
       
    42 else:
       
    43 	tools = ['default']
       
    44 
       
    45 env = Environment(tools = tools)
       
    46 
       
    47 opt = Options(['build/.optioncache'])
    37 opt.AddOptions(
    48 opt.AddOptions(
    38 	BoolOption('intelc', 'use Intel C++ Compiler, if available', True),
       
    39 	BoolOption('simd', 'allow SSE intrinsics', True),
    49 	BoolOption('simd', 'allow SSE intrinsics', True),
    40 	('precision', 'floating point number precision (single/double)', "single"),
    50 	('precision', 'floating point number precision (single/double)', "single"),
    41 	('flags', 'add additional compiler flags', ""),
    51 	('flags', 'add additional compiler flags', ""),
    42 	BoolOption('force_flags', "use only flags specified by 'flags' option (do not autodetect arch/sse flags)", False),
    52 	BoolOption('force_flags', "use only flags specified by 'flags' option (do not autodetect arch/sse flags)", False),
    43 	BoolOption('profile', "enable gcc's profiling support (-pg)", False),
    53 	BoolOption('profile', "enable gcc's profiling support (-pg)", False),
    44 )
    54 )
    45 if env['PLATFORM'] == 'win32':
    55 if env['PLATFORM'] == 'win32':
    46 	opt.AddOptions(
    56 	opt.AddOptions(
       
    57 		BoolOption('msvc', 'use Microsoft Visual C++ Compiler, if available', True),
    47 		('pythonpath', 'path to Python installation',
    58 		('pythonpath', 'path to Python installation',
    48 			'C:\\Python%c%c' % (sys.version[0], sys.version[2])),
    59 			'C:\\Python%c%c' % (sys.version[0], sys.version[2])),
    49 		)
    60 	)
       
    61 else:
       
    62 	opt.AddOptions(
       
    63 		BoolOption('intelc', 'use Intel C++ Compiler, if available', True),
       
    64 	)
       
    65 
       
    66 
    50 opt.Update(env)
    67 opt.Update(env)
    51 opt.Save('.optioncache', env)
    68 opt.Save('build/.optioncache', env)
    52 Help(opt.GenerateHelpText(env))
    69 Help(opt.GenerateHelpText(env))
    53 
    70 
    54 
    71 
    55 ### configure
    72 ### configure
    56 
    73 
    67 	context.Result(platform)
    84 	context.Result(platform)
    68 	return True
    85 	return True
    69 
    86 
    70 def CheckIntelC(context):
    87 def CheckIntelC(context):
    71 	global intelc, intelcversion
    88 	global intelc, intelcversion
    72 	context.Message('Checking for Intel C++ Compiler... ')
    89 	context.Message('Checking for IntelC compiler... ')
    73 	intelc = Tool("intelc").exists(env) == True
    90 	intelc = Tool("intelc").exists(env) == True
    74 	if intelc:
    91 	if intelc:
    75 		testenv = Environment()
    92 		testenv = Environment()
    76 		Tool("intelc").generate(testenv)
    93 		Tool("intelc").generate(testenv)
    77 		intelcversion = str(testenv['INTEL_C_COMPILER_VERSION']/10.)
    94 		intelcversion = str(testenv['INTEL_C_COMPILER_VERSION']/10.)
    81 		context.Result(intelc)
    98 		context.Result(intelc)
    82 	return intelc
    99 	return intelc
    83 
   100 
    84 def CheckGCC(context):
   101 def CheckGCC(context):
    85 	global gcc, gccversion
   102 	global gcc, gccversion
    86 	context.Message('Checking for GCC... ')
   103 	context.Message('Checking for GCC compiler... ')
    87 	gcc = "g++" in env['TOOLS']
   104 	gcc = "g++" in env['TOOLS']
    88 	if gcc:
   105 	if gcc:
    89 		gccversion = env['CCVERSION']
   106 		gccversion = env['CCVERSION']
    90 		context.Result(gccversion)
   107 		context.Result(gccversion)
    91 	else:
   108 	else:
    92 		gccversion = ''
   109 		gccversion = ''
    93 		context.Result(False)
   110 		context.Result(False)
    94 	return gcc
   111 	return gcc
    95 
   112 
       
   113 def CheckMSVC(context):
       
   114 	global msvc, msvcversion
       
   115 	context.Message('Checking for MSVC compiler... ')
       
   116 	testenv = Environment()
       
   117 	msvc = "msvc" in testenv['TOOLS']
       
   118 	if msvc:
       
   119 		msvcversion = testenv['MSVS_VERSION']
       
   120 		context.Result(msvcversion)
       
   121 	else:
       
   122 		msvcversion = ''
       
   123 		context.Result(False)
       
   124 	return msvc
       
   125 
    96 def CheckCPUFlags(context):
   126 def CheckCPUFlags(context):
    97 	global cpu, cpuflags_gcc, cpuflags_intelc
   127 	global cpu, cpuflags_gcc, cpuflags_intelc
    98 	context.Message('Checking CPU arch and flags... ')
   128 	context.Message('Checking CPU arch and flags... ')
    99 	env.Execute('@$CC tools/cpuflags.c -o tools/cpuflags')
   129 	env.Execute('@$CC tools/cpuflags.c -o tools/cpuflags')
   100 	(cpu, cpuflags_gcc, cpuflags_intelc) = os.popen('tools'+os.sep+'cpuflags %s %s'
   130 	(cpu, cpuflags_gcc, cpuflags_intelc) = os.popen('tools'+os.sep+'cpuflags %s %s'
   101 		% (''.join(gccversion.rsplit('.',1)), intelcversion) ).read().split('\n')[:3]
   131 		% (''.join(gccversion.rsplit('.',1)), intelcversion) ).read().split('\n')[:3]
   102 	context.Result(cpu)
   132 	context.Result(cpu)
   103 	return True
   133 	return True
   104 
   134 
   105 conf = Configure(env,
   135 conf_dir = "#/build/.sconf_temp"
       
   136 log_file="#/build/config.log"
       
   137 config_h="#/include/config.h"
       
   138 conf = Configure(env, conf_dir=conf_dir, log_file=log_file, config_h=config_h,
   106 	custom_tests = {
   139 	custom_tests = {
   107 		'CheckPlatform' : CheckPlatform, 'CheckCPUFlags' : CheckCPUFlags,
   140 		'CheckPlatform' : CheckPlatform, 'CheckCPUFlags' : CheckCPUFlags,
   108 		'CheckIntelC' : CheckIntelC, 'CheckGCC' : CheckGCC})
   141 		'CheckIntelC' : CheckIntelC, 'CheckGCC' : CheckGCC, 'CheckMSVC' : CheckMSVC})
   109 conf.CheckPlatform()
   142 conf.CheckPlatform()
       
   143 
   110 conf.CheckGCC()
   144 conf.CheckGCC()
   111 conf.CheckIntelC()
   145 if platform == 'win32':
   112 conf.CheckCPUFlags()
   146 	conf.CheckMSVC()
   113 
   147 	intelc = False
   114 if intelc and conf.env['intelc']:
   148 else:
   115 	Tool("intelc").generate(conf.env)
   149 	conf.CheckIntelC()
       
   150 	msvc=False
       
   151 
       
   152 if intelc or gcc:
       
   153 	conf.CheckCPUFlags()
       
   154 
       
   155 if intelc and (not gcc or conf.env['intelc']):
       
   156 	Tool('intelc').generate(conf.env)
   116 	cc = 'intelc'
   157 	cc = 'intelc'
       
   158 elif msvc and (not gcc or conf.env['msvc']):
       
   159 	Tool('default').generate(conf.env)
       
   160 	conf.Define("MSVC")
       
   161 	cc = 'msvc'
   117 elif gcc:
   162 elif gcc:
   118 	cc = 'gcc'
   163 	cc = 'gcc'
       
   164 else:
       
   165 	cc = 'none'
       
   166 
       
   167 if platform == 'win32' and cc == 'gcc':
       
   168 	conf.env.Append(LIBPATH=["C:/mingw/lib", "C:/msys/mingw/lib"])
       
   169 	conf.env.Append(CPPPATH=["C:/mingw/include", "C:/msys/mingw/include"])
   119 
   170 
   120 add_flags = ''
   171 add_flags = ''
   121 if cc == 'gcc':
   172 if cc == 'gcc':
   122 	add_flags += cpuflags_gcc + ' -ffast-math '
   173 	add_flags += cpuflags_gcc + ' -ffast-math '
   123 if cc == 'intelc':
   174 if cc == 'intelc':
   124 	add_flags += cpuflags_intelc + ' '
   175 	add_flags += cpuflags_intelc + ' '
       
   176 if cc == 'msvc':
       
   177 	add_flags += '/fp:fast '
       
   178 	if conf.env['simd']:
       
   179 		add_flags += '/arch:SSE '
   125 
   180 
   126 if conf.env['force_flags']:
   181 if conf.env['force_flags']:
   127 	add_flags = conf.env['flags'] + ' '
   182 	add_flags = conf.env['flags'] + ' '
   128 else:
   183 else:
   129 	add_flags += conf.env['flags'] + ' '
   184 	add_flags += conf.env['flags'] + ' '
   130 
   185 
   131 if conf.env['precision'] == 'double':
   186 if conf.env['precision'] == 'double':
   132 	add_flags += '-DPYRIT_DOUBLE '
   187 	conf.Define("PYRIT_DOUBLE")
   133 elif cc == 'gcc':
   188 elif cc == 'gcc':
   134 	add_flags += '-fsingle-precision-constant '
   189 	add_flags += '-fsingle-precision-constant '
   135 
   190 
   136 if not conf.env['simd']:
   191 if not conf.env['simd'] or conf.env['precision'] == 'double':
   137 	add_flags += '-DNO_SSE '
   192 	conf.Define("NO_SIMD")
   138 
   193 
   139 if cc == 'intelc':
   194 if cc == 'intelc':
   140 	conf.env.Append(CCFLAGS="-O3 -w1 " + add_flags)
   195 	conf.env.Append(CCFLAGS="-O3 -w1 " + add_flags)
   141 elif cc == 'gcc':
   196 elif cc == 'gcc':
   142 	conf.env.Append(CCFLAGS="-O3 -Wall -pipe " + add_flags)
   197 	conf.env.Append(CCFLAGS="-O3 -Wall -pipe " + add_flags)
   143 	# CCFLAGS= -fno-strict-aliasing
   198 elif cc == 'msvc':
       
   199 	conf.env.Append(CCFLAGS="/Ox /Ob2 /GS- /Gy /GF /GR- /Zp16 /MD /EHsc /vmb " + add_flags)
   144 else:
   200 else:
   145 	print "No supported compiler found."
   201 	print "No supported compiler found."
   146 	Exit(1)
   202 	Exit(1)
   147 
   203 
   148 print "Using compiler: " + cc
   204 print "Using compiler: " + cc
   149 print "Additional flags: " + add_flags
   205 print "Additional flags: " + add_flags
   150 
   206 
   151 if conf.CheckLibWithHeader('png', 'png.h', 'C'):
   207 pthread = True
   152 	conf.env.Append(CCFLAGS='-DHAVE_PNG')
   208 if conf.env['PLATFORM'] == 'win32':
   153 	conf.env.Append(LIBS=['png'])
   209 	if cc == 'msvc':
   154 
   210 		if not conf.CheckLib('pthreadVC2'):
   155 if not conf.CheckCHeader('pthread.h'):
   211 			pthread = False
       
   212 		conf.env.Append(LIBS=["pthreadVC2"])
       
   213 	elif cc == 'gcc':
       
   214 		if not conf.CheckLib('pthreadGC2'):
       
   215 			pthread = False
       
   216 		conf.env.Append(LIBS=["pthreadGC2"])
       
   217 else:
       
   218 	conf.env.Append(CCFLAGS="-pthread ")
       
   219 
       
   220 if not pthread:
   156 	print 'Error: Cannot build without pthread.'
   221 	print 'Error: Cannot build without pthread.'
   157 	Exit(1)
   222 	Exit(1)
   158 
   223 
   159 if conf.env['PLATFORM'] == 'win32':
   224 if conf.CheckLibWithHeader('png', 'png.h', 'C'):
   160 	conf.env.Append(LIBS=["pthreadGC2"])
   225 	conf.Define('HAVE_PNG')
   161 else:
   226 	conf.env.Append(LIBS=['png'])
   162 	conf.env.Append(CCFLAGS="-pthread ")
   227 elif conf.CheckLib('libpng13'):
       
   228 	conf.Define('HAVE_PNG')
       
   229 	conf.env.Append(LIBS=['libpng13'])
   163 
   230 
   164 if conf.env['profile'] and cc == 'gcc':
   231 if conf.env['profile'] and cc == 'gcc':
   165 	conf.env.Append(CCFLAGS="-pg", LINKFLAGS="-pg")
   232 	conf.env.Append(CCFLAGS="-pg", LINKFLAGS="-pg")
   166 
   233 
   167 env = conf.Finish()
   234 env = conf.Finish()
   168 
   235 
       
   236 # configure SDL
       
   237 sdlenv = env.Clone()
       
   238 if cc != 'msvc':
       
   239 	try:
       
   240 		sdlenv.ParseConfig('sh sdl-config --cflags')
       
   241 		sdlenv.ParseConfig('sh sdl-config --libs')
       
   242 	except:
       
   243 		pass
       
   244 else:
       
   245 	sdlenv.Append(LIBS=['SDL', 'SDLmain'])
       
   246 
       
   247 conf = Configure(sdlenv, conf_dir=conf_dir, log_file=log_file, config_h=config_h)
       
   248 have_sdl = False
       
   249 if conf.CheckLib('SDL'):
       
   250 	have_sdl = True
       
   251 else:
       
   252 	print "SDL not found, some demos will not built."
       
   253 sdlenv = conf.Finish()
       
   254 
       
   255 if cc == 'msvc':
       
   256 	sdlenv.Append(LINKFLAGS="/SUBSYSTEM:WINDOWS")
   169 
   257 
   170 ### build targets
   258 ### build targets
   171 
   259 
   172 lib = SConscript('src/SConscript', build_dir='build/lib', duplicate=0, exports={'env':env,'buildmodule':False})
   260 Export('env sdlenv cc')
   173 pymodule = SConscript('src/SConscript', build_dir='build/pymodule', duplicate=0, exports={'env':env,'buildmodule':True})
   261 lib = SConscript('src/SConscript', build_dir='build/lib', duplicate=0,
   174 
   262 	exports={'buildmodule':False})
   175 SConscript('ccdemos/SConscript', build_dir='build/ccdemos', duplicate=0, exports='env lib')
   263 pymodule = SConscript('src/SConscript', build_dir='build/pymodule', duplicate=0,
       
   264 	exports={'buildmodule':True})
       
   265 
       
   266 if have_sdl:
       
   267 	SConscript('ccdemos/SConscript', build_dir='build/ccdemos', duplicate=0,
       
   268 		exports='lib')
       
   269 
   176 SConscript('demos/SConscript', exports='pymodule')
   270 SConscript('demos/SConscript', exports='pymodule')
       
   271 SConscript('tests/SConscript', build_dir='build/tests', duplicate=0, exports='lib')
       
   272 SConscript('models/SConscript')
       
   273 
   177 env.Alias('demos', ['cc-demos', 'python-demos'])
   274 env.Alias('demos', ['cc-demos', 'python-demos'])
   178 
       
   179 SConscript('tests/SConscript', build_dir='build/tests', duplicate=0, exports='env lib')
       
   180 
       
   181 SConscript('models/SConscript')
       
   182 
       
   183 env.Alias('libs', ['static-lib', 'python-module'])
   275 env.Alias('libs', ['static-lib', 'python-module'])
   184 
       
   185 env.Alias('docs', Command('docs/html', [], 'doxygen'))
   276 env.Alias('docs', Command('docs/html', [], 'doxygen'))
   186 env.Clean('docs', ['docs/html'])
   277 env.Clean('docs', ['docs/html'])
   187 
       
   188 env.Alias('no-docs', ['libs', 'demos', 'models'])
   278 env.Alias('no-docs', ['libs', 'demos', 'models'])
   189 env.Alias('no-download', ['libs', 'demos', 'local-models'])
   279 env.Alias('no-download', ['libs', 'demos', 'local-models'])
   190 
       
   191 env.Alias('all', ['no-docs', 'docs'])
   280 env.Alias('all', ['no-docs', 'docs'])
   192 
       
   193 env.Alias('pyrit', 'no-download')
   281 env.Alias('pyrit', 'no-download')
   194 Default('pyrit')
   282 Default('pyrit')