I have a problem refactoring a scons based build system. We have a C / C ++ source tree with several different output objects (DLLs, executables, test executables) and a somewhat heterogeneous layout for our source files (although most of them are located in the c module directories src/and inc/directories).
One of my biggest problems with the current setup is that we really want all of these build products to be built using the default default compiler options. Our current layout has a SConstruct master file that calls many sub-SConscript files in subdirectories, which then build chunks of larger build products (for example, .a). By default, a function SConscript()in scons does not pass or inherit the current object of the build environment to the SConstruct file being called. This means that currently all of these sub-SConstript files all use their own development environment.
The new layout I'm trying to assemble has the main building environment, combined at the root of the source tree, with all the necessary CFLAGS and the assembly we need. I would like to build this medium was transferred to sub-SConscript files, so I know that every single file .cand .cppin our build tree is built with the same command line.
I am not sure how to do this in scons. There are functions Import()and Export(), but these are basically ugly global variables - the calling SConstruct file does not have much control over what the sub-SConstruct file does with the global variable Export()'ed, is there any clean way that essentially passes the sub-SConscript file to the current the construction environment as a parameter, not allowing it to necessarily modify it? Something may be similar:
master_env = Environment()
master_env.Append( CXXFLAGS=['-Wall', '-Werror', '-g', '-fPIC', ... ] )
SConscript( 'somelibrary/SConstruct', inherited_environment=master_env.Clone() )
I know that I could do something awkward and kind of rude:
clobber_env = Environment()
master_env = Environment()
master_env.Append( CXXFLAGS=['-Wall', '-Werror', '-g', '-fPIC', ... ] )
call_somelibrary_sconstruct( master_env )
def call_somelibrary_sconstruct(env):
param_env = env.Clone()
Export( 'param_env' )
SConstript( 'somelibrary/SConstruct' )
param_env = clobber_env
Export( 'param_env' )
Is there an elegant way to do this?
Update:
So, I played with this a little more, and it seems that while I am doing this in the main SConstruct file:
def build_somelib( env ):
Export( env=env.Clone() )
somelib = SConscript( 'somelib/SConscript' )
return somelib
master_env = Environment()
master_env.Append( CXXFLAGS=['-Wall', '-Werror', '-g', '-fPIC', ... ] )
build_somelib( master_env )
and then in somelib/SConscript
Import( 'env' )
env.Append( CXXFLAGS=['-weirdoption1', ... ] )
lib = env.StaticLibrary( 'somelib', source=['source1.cpp', 'source2.cpp', ...] )
Return( "lib" )
master_env SConstruct . , Export( env=env.Clone() ) , - -Clone() 'ing - SConscript/SConstruct.
, env .