import os Import('config') if not config.get('PROJECT_NAME'): config['PROJECT_NAME'] = 'PROJECT' AddOption( '--build_type', dest = 'build_type', type = 'choice', choices = ('debug', 'release_debug', 'release', 'profile'), nargs = 1, action = 'store', default = 'debug' ) AddOption( '--unity', dest = 'unity_mode', type = 'choice', choices = ('enable', 'disable', 'stress'), nargs = 1, action = 'store', default = 'enable' ) AddOption( '--variant', dest = 'variant', nargs = 1, action = 'store' ) AddOption( '--asan', dest = 'enable_asan', action = 'store_true' ) AddOption( '--config_file', dest = 'config_file', nargs = 1, action = 'store', default = 'config.py' ) build_type = GetOption('build_type') unity_mode = GetOption('unity_mode') variant = GetOption('variant') enable_asan = GetOption('enable_asan') config_file = GetOption('config_file') env = Environment(tools = ['default', 'compilation_db']) # allow compiling to variant directories (each gets their own bin/lib/cache dirs) if variant: variant_dir = f'cache/variant/{variant}' env['BIN_DIR'] = Dir(f'bin_{variant}').abspath env['LIB_DIR'] = Dir(f'lib_{variant}').abspath env['UNITY_CACHE_DIR'] = Dir(f'cache/variant/{variant}/unity') env.Append(CPPDEFINES = [f'{config["PROJECT_NAME"]}_VARIANT={variant}']) else: variant_dir = None env.CompilationDatabase() env['BIN_DIR'] = Dir('bin').abspath env['LIB_DIR'] = Dir('lib').abspath env['UNITY_CACHE_DIR'] = Dir('cache/unity') env['BUILD_TYPE'] = build_type env.Append(LIBPATH = [env['LIB_DIR']]) # to allow submodules to link to each other without hassle # try to detect what compiler we are using compiler_exe = os.path.basename(env['CC']) if 'gcc' in compiler_exe: env['COMPILER_FAMILY'] = 'gcc' elif 'clang' in compiler_exe: env['COMPILER_FAMILY'] = 'clang' elif 'cl' in compiler_exe: env['COMPILER_FAMILY'] = 'cl' else: env['COMPILER_FAMILY'] = 'unknown' # setup unity build depending on mode if unity_mode == 'disable': env['UNITY_DISABLE'] = True elif unity_mode == 'stress': # compile everything in one single file to stress test the unity build env['UNITY_MAX_SOURCES'] = 100000 # I'll hopefully never reach this env['UNITY_MIN_FILES'] = 1 Return('env')