64
63
########################################################################
65
def IsBuildOrRunTests():
66
return BuildTests or RunTests
66
68
def CheckSettings(main_env):
67
69
global Cc, Cxx, BuildDir, Targets, RunTests, BuildTests
69
print 'Building and running tests'
72
print 'Building with tests'
74
print 'Tests: on (only building)'
74
76
def_env = GetDefEnv()
75
77
# for SCons =<0.96 we need to warn that just 'scons' is not enough:
98
100
# we use TestSConscript() function instead of SConscript()
100
102
def TestSConscript(*args, **kwds):
101
if BuildTests or RunTests:
103
if IsBuildOrRunTests():
102
104
def_env.SConscript(*args, **kwds)
103
105
def_env.Export('TestSConscript')
104
106
# make test Builder
106
def generate_test_actions(source, target, env, for_signature):
107
return '%s' % (source[0])
108
#test_bld = Builder(action = '$SOURCE $TARGET')
109
test_bld = main_env.Builder(generator = generate_test_actions)
111
def TestingString(target, source, env):
112
return '\nRunning tests: %s' % (source[0])
113
test_bld.action.strfunction = TestingString
108
#def generate_test_actions(source, target, env, for_signature):
109
# return '%s' % (source[0])
110
#test_bld = main_env.Builder(generator = generate_test_actions)
112
#def TestingString(target, source, env):
113
# return '\nRunning tests: %s' % (source[0])
114
#test_bld.action.strfunction = TestingString
116
# :TODO: now all tests have the same args; should be fixed
117
# by storing dict of (test_bin_Node, args) and using it in make_test_str()
119
# --catch_system_errors=no is needed because Boost.Test of new Boost versions conflicts
120
# with other software (e.g. GTK) by handling signals its own way.
121
# Attention: UNIX signals are CRAP!!! I hate you.
122
UT_ARGS = '--catch_system_errors=no'
124
def make_test_str(source, is_cmd):
125
res = '%s' % (source[0])
126
if is_cmd or (not BuildBrief):
131
def generate_test_actions(source, target, env, for_signature):
132
return make_test_str(source, True)
134
def generate_test_str(target, source, env):
135
return '\nRunning tests: %s' % (make_test_str(source, False))
137
test_act = MakeGenAction(generate_test_actions, generate_test_str)
138
test_bld = main_env.Builder(action = test_act)
115
140
main_env.Append( BUILDERS = {'UnitTest_': test_bld} )
117
142
def UnitTest(test_program_name, env):
119
144
# use non-existent target to run command always
120
env.UnitTest_(target = '_fiction_target_', source = test_program_name)
145
env.UnitTest_(target = '%s.run' % test_program_name, source = test_program_name)
121
146
main_env.Export('UnitTest')
123
148
# set brief output
288
313
return SCons.Options.Options(*args, **kw)
315
def VariantDir(variant_dir, src_dir, duplicate=1):
316
def_env = GetDefEnv()
318
def_env.VariantDir(variant_dir, src_dir, duplicate)
320
def_env.BuildDir(variant_dir, src_dir, duplicate)
290
322
################################################################
291
323
# Autoconfig stuff
312
344
str = GetArch().lower()
313
345
return str.startswith('alpha')
348
# all those compilers who understand gcc extensions: gcc, clang
349
return UserOptDict['IS_GCC']
315
351
def IsGccCompiler():
316
352
#return Cc == 'gcc'
317
return UserOptDict['IS_GCC']
353
return UserOptDict['IS_GCC'] and not UserOptDict['IS_CLANG']
355
def IsClangCompiler():
356
def has_tail(name, tail):
357
ln = len(name) - len(tail)
358
return name[ln:] == tail
360
#res = has_tail(BV.Cc, 'clang')
361
res = UserOptDict['IS_CLANG']
363
assert( has_tail(Cxx, 'clang++') )
319
366
def MakeObjectComment(obj_name, is_one_set):
320
367
prefix = "Define "
434
481
GetSrcBuildDir.obj = GetDefEnv().Dir(BuildDir + '/' + GetSrcDirPath())
435
482
return GetSrcBuildDir.obj
484
def IsToBuildQuick():
485
can_bq = IsGccLike() # gcc and clang only (because of PCH)
487
val = UserOptDict['BUILD_QUICK']
488
want_bq = val != 'false'
490
want_bq = IsDebugCfg()
496
elif not IsReenter(IsToBuildQuick):
498
print 'BUILD_QUICK=true is not supported for current compiler(%s)!' % Cc
502
def CreateEnvVersion2(**kw):
438
503
tools = ['default', 'AuxTools']
439
504
if kw.has_key('tools'):
440
505
tools += kw['tools']
441
506
kw['tools'] = tools
443
return GetDefEnv().Environment(ENV = os.environ, toolpath = ['tools/scripts'], **kw)
445
def CreateLEnv(**kw):
446
env = CreateEnv(**kw)
508
env = GetDefEnv().Environment(ENV = os.environ, toolpath = ['tools/scripts'], **kw)
448
509
env.Prepend(CPPPATH = [GetSrcBuildDir(), '#/' + GetSrcDirPath()])
511
# :TRICKY: relatively new ar (from binutils) needed for such things (Hardy doesn't have such)
512
# so turn it off for releases completely
514
# thin archives ('T' option) are to speed up static libraries build
515
# :TRICKY: libmpeg2.a and etc have to be built directly to build/lib (withour copying/symlinking)
516
env.Replace(ARFLAGS = str(env['ARFLAGS']) + 'T')
451
519
def MakeMainEnv():
452
if UserOptDict['BUILD_QUICK']:
524
elif IsClangCompiler():
453
529
def SetPCH(env, header_name, additional_envs=[]):
454
530
# :COMMENT: the "is_def" version is done to
455
531
# check gcc' .gch using; once not used, dummy_pc_.h
459
535
# versions and so should be tested, resp.
538
def make_pch(pch_env):
539
# we need to set args definitely to override SCons '# and BuildDir' dualism
540
return pch_env.Gch(target = header_name + env['GCHSUFFIX'], source = env.File(header_name).srcnode())[0]
543
pch_file = make_pch(env.Clone())
544
# :KLUDGE: CPPFLAGS is right way but it breaks if there is an C file
546
env.Append(CXXFLAGS = '-include %s' % env.File(header_name).path)
548
pch_file = make_pch(env)
549
env.Depends(pch_file, env.InstallAs(target = './'+header_name, source = '#tools/scripts/dummy_pc_.h'))
462
551
env['DepGch'] = 1
464
# No need for this anymore
466
# # we need make own env for pch
467
# # because it should not include dummy_pc_.h,
468
# # so we modify CPPPATH
469
# copy_env = env.Copy()
471
# cpp_path = copy_env['CPPPATH']
474
# del_pos = cpp_path.index(GetSrcBuildDir())
475
# cpp_path.pop(del_pos)
477
# # no path - no problem
481
# print "cpp_path - ValueError"
483
# env['Gch'] = copy_env.Gch(target = header_name + env['GCHSUFFIX'], source = env.File(header_name).srcnode())[0]
485
# we need to set args definitely to override SCons '# and BuildDir' dualism
486
env['Gch'] = env.Gch(target = header_name + env['GCHSUFFIX'], source = env.File(header_name).srcnode())[0]
488
env.Depends(env['Gch'], env.InstallAs(target = './'+header_name, source = '#tools/scripts/dummy_pc_.h'))
490
552
for add_env in additional_envs:
491
553
add_env['DepGch'] = 1
493
env['Gch'] = env.Gch(header_name)[0]
555
pch_file = env.Gch(header_name)[0]
557
env['Gch'] = pch_file
495
558
for add_env in additional_envs:
496
add_env['Gch'] = env['Gch']
498
UserOptDict['SetPCH'] = SetPCH
500
env = CreateLEnv(tools = ['gch'])
559
add_env['Gch'] = pch_file
561
env = CreateEnvVersion2(tools = ['gch'])
562
suffix = '.pch' if is_clang else '.gch'
563
env['GCHSUFFIX'] = suffix
502
565
# 2 - reduce SCons' C scanner area, CPPPATH -> CPP_POST_FLAGS
503
566
env['_CPPINCFLAGS'] = env['_CPPINCFLAGS'] + ' $CPP_POST_FLAGS'
505
568
def SetPCH(env, header_name, additional_envs=[]):
507
UserOptDict['SetPCH'] = SetPCH
570
env = CreateEnvVersion2()
572
UserOptDict['SetPCH'] = SetPCH
511
573
# we use function Dir() so SCons do not change it
513
env.Append(LIBPATH = env.Dir(UserOptDict['LIB_BUILD_DIR']))
575
env.Append(LIBPATH = [env.Dir(UserOptDict['LIB_BUILD_DIR'])])
514
576
CheckSettings(env)
545
607
tgt = env.InstallAs(dst_list, src_list)
610
def make_source_files(fpath, lst):
614
lst = GetDefEnv().Split(lst)
616
return [ os.path.join(fpath, fname) for fname in lst ]
618
def InitUOD(user_options_dict):
620
UserOptDict = user_options_dict
621
UserOptDict['make_source_files'] = make_source_files