Sunday, 15 February 2015

python - SCons: Different variant_dir in single SConscript file -



python - SCons: Different variant_dir in single SConscript file -

i need utilize scons generate release , debug build big project. both release , debug build generates shared , static library. after build directory construction should follows:

project_dir/ |_ src |_ include |_ lib |_ lib_rel |_ lib_dbg |_ dll |_ dll_rel |_ dll_dbg

how implement sconstruct , sconscript adhere above requirements ?

sconstruct implementation:

env = environment() relenv = env.clone(ccflags = ['-o3', '-pthread')] dbgenv = env.clone(ccflags = ['-o0', '-g', '-pthread')] sconscript(dirs = 'src', name = 'sconscript', exports = {'env' : relenv}, variant_dir = 'lib_rel', duplicate = 0) sconscript(dirs = 'src', name = 'sconscript', exports = {'env' : dbgenv}, variant_dir = 'lib_dbg', duplicate = 0)

src/sconscript implementation:

import('env') src_list = glob('*.cpp') inc_list = ['dir_1/include', 'dir_2/include', 'common/include'] env.sharedlibrary(target = 'foo', source = src_list, cpp_path=inc_list) env.staticlibrary(target = 'foo', source = src_list, cpp_path=inc_list)

using above implementation generate shared , static library in lib_rel folder , related object files, there way can utilize variant dir in such way sharedlibrary utilize target directory {dll/lib_rel , dll/lib_dbg} , staticlibrary method uses variant_dir {lib/lib_rel, lib/lib_dbg}

one approach can possible have separate sconscript sharedlibrary , staticlibrary. typical 2 different files required each library builder methods.

kindly suggest proper solution this.

i treat static-ness , debug-ness 2 dimensions , phone call sconscript 4 times, so:

env = environment() relenv = env.clone(ccflags = ['-o3', '-pthread']) dbgenv = env.clone(ccflags = ['-o0', '-g', '-pthread']) sconscript(dirs = 'src', name = 'sconscript', exports = {'env' : relenv, 'library' : relenv.staticlibrary}, variant_dir = 'lib/lib_rel', duplicate = 0) sconscript(dirs = 'src', name = 'sconscript', exports = {'env' : dbgenv, 'library' : dbgenv.staticlibrary}, variant_dir = 'lib/lib_dbg', duplicate = 0) sconscript(dirs = 'src', name = 'sconscript', exports = {'env' : relenv, 'library' : relenv.sharedlibrary}, variant_dir = 'dll/dll_rel', duplicate = 0) sconscript(dirs = 'src', name = 'sconscript', exports = {'env' : dbgenv, 'library' : dbgenv.sharedlibrary}, variant_dir = 'dll/dll_dbg', duplicate = 0)

of course, that's ugly, i'd utilize loop:

env = environment() relenv = env.clone(ccflags = ['-o3', '-pthread']) dbgenv = env.clone(ccflags = ['-o0', '-g', '-pthread']) env, envpath in ((relenv, 'rel'), (dbgenv, 'dbg')): lib, libpath in ((env.staticlibrary, 'lib'), (env.sharedlibrary, 'dll')): sconscript(dirs = 'src', name = 'sconscript', exports = {'env' : env, 'library' : lib}, variant_dir = '{libpath}/{libpath}_{envpath}'.format(**locals()), duplicate = 0)

the sconscript needs import library, of course:

import('env', 'library') src_list = glob('*.cpp') inc_list = ['dir_1/include', 'dir_2/include', 'common/include'] library(target = 'foo', source = src_list, cpp_path=inc_list)

python c++ build scons build-tools

No comments:

Post a Comment