From d0540066250360ff80d6344f69e0c02a345134bc Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Thu, 6 Mar 2014 00:16:14 -0800 Subject: [PATCH] Round out environment setup; restore mode stuff --- site_scons/site_init.py | 57 ++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/site_scons/site_init.py b/site_scons/site_init.py index 874833e..e0612dc 100644 --- a/site_scons/site_init.py +++ b/site_scons/site_init.py @@ -15,19 +15,6 @@ LIB_DIR = Dir('#lib') SRC_DIR = Dir('#src') TEST_DIR = Dir('#test') -# -# SCons Command Line Options -# - -AddOption('--show-build-cmds', - dest='build_cmds', - action='store_true', - help='Show build commands instead of friendly build messages') -AddOption('--mode', - dest='mode', - metavar='MODE', - help='The build mode') - # # Environment Configuration # @@ -38,14 +25,48 @@ def has_clang(env): return any([cc_tail.startswith('clang'), cxx_tail.startswith('clang')]) default_env = SCons.Defaults.DefaultEnvironment() -default_env['CC'] = binaries.first(['clang', 'gcc']) -default_env['CXX'] = binaries.first(['clang++', 'g++']) +default_env.Replace(CC=binaries.first(['clang', 'gcc']), + CXX=binaries.first(['clang++', 'g++'])) -default_env.Append(CCFLAGS=['-Wall', '-Wextra', '-pedantic']) +default_env.Append(CCFLAGS=['-Wall', '-Wextra', '-pedantic'], + CFLAGS=['-std=c99'], + CXXFLAGS=['-std=c++11']) if has_clang(default_env): # Only clang supports color. default_env.Append(CCFLAGS=['-fcolor-diagnostics']) -default_env.Append(CFLAGS=['-std=c99']) -default_env.Append(CXXFLAGS=['-std=c++11']) +debug_env = default_env.Clone(MODE='debug', + CCFLAGS=['-O0', '-g'], + CPPDEFINES=['DEBUG']) +release_env = default_env.Clone(MODE='release', + CCFLAGS=['-O2'], + CPPDEFINES=['RELEASE']) + +MODES = { + 'debug': debug_env, + 'release': release_env +} + +# +# Command Line Options +# + +def process_modes_option(option, opt, value, parser): + modes = value.split(',') + for m in modes: + setattr(parser.values, 'modes', set(modes)) + +AddOption('--show-build-cmds', + dest='build_cmds', + action='store_true', + help='Show build commands instead of friendly build messages') +AddOption('--modes', + type='string', + action='callback', + dest='modes', + metavar='MODES', + default=set(['debug']), + callback=process_modes_option, + help=('A comma separated list of modes. Choose from: {}. Default is ' + 'debug.').format(', '.join(MODES.keys())))