Browse Source

wscript: refactor adding compiler flags, remove --release flag, instead add mandatory --build-type flag

pull/2/head
Alibek Omarov 6 years ago
parent
commit
847be54457
  1. 96
      wscript

96
wscript

@ -26,6 +26,22 @@ def get_git_version():
return version return version
def get_flags_by_compiler(flags, compiler):
out = []
if compiler in flags:
out += flags[compiler]
elif 'default' in flags:
out += flags['default']
return out
def get_flags_by_type(flags, type, compiler):
out = []
if 'common' in flags:
out += get_flags_by_compiler(flags['common'], compiler)
if type in flags:
out += get_flags_by_compiler(flags[type], compiler)
return out
def options(opt): def options(opt):
opt.load('compiler_cxx compiler_c') opt.load('compiler_cxx compiler_c')
if sys.platform == 'win32': if sys.platform == 'win32':
@ -38,11 +54,7 @@ def options(opt):
opt.add_option( opt.add_option(
'--64bits', action = 'store_true', dest = 'ALLOW64', default = False, '--64bits', action = 'store_true', dest = 'ALLOW64', default = False,
help = 'allow targetting 64-bit engine') help = 'allow targetting 64-bit engine')
opt.add_option(
'--release', action = 'store_true', dest = 'RELEASE', default = False,
help = 'strip debug info from binary and enable optimizations')
opt.add_option( opt.add_option(
'--win-style-install', action = 'store_true', dest = 'WIN_INSTALL', default = False, '--win-style-install', action = 'store_true', dest = 'WIN_INSTALL', default = False,
help = 'install like Windows build, ignore prefix, useful for development') help = 'install like Windows build, ignore prefix, useful for development')
@ -55,9 +67,22 @@ def options(opt):
'--sdl2', action='store', type='string', dest = 'SDL2_PATH', default = None, '--sdl2', action='store', type='string', dest = 'SDL2_PATH', default = None,
help = 'SDL2 path to build(required for Windows)') help = 'SDL2 path to build(required for Windows)')
opt.add_option(
'--build-type', action='store', type='string', dest='BUILD_TYPE', default = None,
help = 'build type: debug, release or none(custom flags)')
opt.recurse(SUBDIRS) opt.recurse(SUBDIRS)
def configure(conf): def configure(conf):
conf.start_msg('Build type')
if conf.options.BUILD_TYPE == None:
conf.end_msg('not set', color='RED')
conf.fatal('Please set a build type, for example "--build-type=release"')
elif not conf.options.BUILD_TYPE in ['release', 'debug', 'none']:
conf.end_msg(conf.options.BUILD_TYPE, color='RED')
conf.fatal('Invalid build type. Valid are "debug", "release" or "none"')
conf.end_msg(conf.options.BUILD_TYPE)
conf.env.MSVC_TARGETS = ['x86'] # explicitly request x86 target for MSVC conf.env.MSVC_TARGETS = ['x86'] # explicitly request x86 target for MSVC
conf.load('compiler_cxx compiler_c') conf.load('compiler_cxx compiler_c')
if sys.platform == 'win32': if sys.platform == 'win32':
@ -72,45 +97,50 @@ def configure(conf):
int check[sizeof(void*) == 4 ? 1: -1]; int check[sizeof(void*) == 4 ? 1: -1];
return 0; return 0;
}''', }''',
msg = 'Checking if compiler create 32 bit code') msg = 'Checking if compiler create 32 bit code')
except conf.errors.ConfigurationError: except conf.errors.ConfigurationError:
# Program not compiled, we have 64 bit # Program not compiled, we have 64 bit
conf.env.DEST_64BIT = True conf.env.DEST_64BIT = True
if(conf.env.DEST_64BIT): if(conf.env.DEST_64BIT):
if(not conf.options.ALLOW64): if(not conf.options.ALLOW64):
conf.env.append_value('LINKFLAGS', ['-m32']) conf.env.append_value('LINKFLAGS', ['-m32'])
conf.env.append_value('CFLAGS', ['-m32']) conf.env.append_value('CFLAGS', ['-m32'])
conf.env.append_value('CXXFLAGS', ['-m32']) conf.env.append_value('CXXFLAGS', ['-m32'])
Logs.info('NOTE: will build engine with 64-bit toolchain using -m32') Logs.info('NOTE: will build engine with 64-bit toolchain using -m32')
else: else:
Logs.warn('WARNING: 64-bit engine may be unstable') Logs.warn('WARNING: 64-bit engine may be unstable')
if(conf.env.COMPILER_CC != 'msvc'): linker_flags = {
if(conf.env.COMPILER_CC == 'gcc') or (conf.env.COMPILER_CC == 'clang'): 'common': {
conf.env.append_unique('LINKFLAGS', ['-Wl,--no-undefined']) 'msvc': ['/DEBUG'],
if(conf.options.RELEASE): 'default': ['-Wl,--no-undefined']
conf.env.append_unique('CFLAGS', ['-O2']) }
conf.env.append_unique('CXXFLAGS', ['-O2']) }
elif(conf.env.COMPILER_CC == 'gcc'):
conf.env.append_unique('CFLAGS', ['-Og', '-g']) compiler_c_cxx_flags = {
conf.env.append_unique('CXXFLAGS', ['-Og', '-g']) 'common': {
else: 'msvc': ['/D_USING_V110_SDK71_'],
conf.env.append_unique('CFLAGS', ['-O0', '-g', '-gdwarf-2']) 'default': ['-g']
conf.env.append_unique('CXXFLAGS', ['-O0', '-g', '-gdwarf-2']) },
'release': {
if conf.options.GCC_COLORS: 'msvc': ['/Zi', '/O2'],
conf.env.append_unique('CFLAGS', ['-fdiagnostics-color=always']) 'default': ['-O3']
conf.env.append_unique('CXXFLAGS', ['-fdiagnostics-color=always']) },
else: 'debug': {
if(conf.options.RELEASE): 'msvc': ['/Z7'],
conf.env.append_unique('CFLAGS', ['/O2']) 'clang': ['-O0', '-gdwarf-2'],
conf.env.append_unique('CXXFLAGS', ['/O2']) 'default': ['-O0']
else: }
conf.env.append_unique('CFLAGS', ['/Z7']) }
conf.env.append_unique('CXXFLAGS', ['/Z7'])
conf.env.append_unique('LINKFLAGS', ['/DEBUG']) conf.env.append_unique('CFLAGS', get_flags_by_type(
conf.env.append_unique('DEFINES', '_USING_V110_SDK71_') # Force XP compability compiler_c_cxx_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC))
conf.env.append_unique('CXXFLAGS', get_flags_by_type(
compiler_c_cxx_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC))
conf.env.append_unique('LINKFLAGS', get_flags_by_type(
linker_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC))
# Force XP compability, all build targets should add # Force XP compability, all build targets should add
# subsystem=bld.env.MSVC_SUBSYSTEM # subsystem=bld.env.MSVC_SUBSYSTEM

Loading…
Cancel
Save