[Scons-users] Code generation and VariantDir?

Jason Fritz jasonfritzpublic at gmail.com
Mon Apr 28 13:52:56 EDT 2014


Hi all,

I'm hoping somebody can give me a recommendation on "best practice" for
arrangement of SConscript files for my situation involving code generation
and different VariantDir's for compilation.

Here's a simplified directory structure:

SConstruct
SConscript
src/
autogen/
foo.h <---- autogenerated from .tsn
foo.cxx <---- autogenerated from .tsn
foo.tsn
SConscript
bar/
bar.cxx <---- includes foo.h
SConscript
release/ <---- VariantDir "release"
src/
autogen/
foo.os <---- Compiled from foo.cxx
libmyfoo.so
bar/
bar.os
libmybar.so
debug/ <---- VariantDir "debug"
src/...


My root SConstruct file looks roughly like this (simplified):
-----
masterEnv = Environment()
releaseEnv = masterEnv.Clone()
debugEnv = masterEnv.Clone()
releaseEnv.Append(CCFLAGS = '-O3')

# codegenEnv is a single environment used for code generation, since code
# generation should be done once and not duplicated per variant.
codegenEnv = masterEnv.Clone()
Export("codegenEnv")

### Define Build Hierarchy
# Release variant
Export(env = releaseEnv)
SConscript('SConscript', variant_dir='release', duplicate=0)

# Debug variant
Export(env = debugEnv)
SConscript('SConscript', variant_dir='debug', duplicate=0)
-----

My SConscript file in the autogen directory looks roughly like this
(simplified):
-----
Import('env codegenEnv')
env = env.Clone()
codegenEnv = codegenEnv.Clone()

tsnFiles = Glob('*.tsn')

objects = []
for tsnFile in tsnFiles:
fileList = codegenEnv.TsncCpp(tsnFile) # Builder, returns Files for .h
and .cxx
for file in fileList:
if str(file).endswith('.cxx') or str(file).endswith('.c'):
obj = env.SharedObject(source=file.name)
env.Depends(obj, file)
objects.append(obj)

env.SharedLibrary('myfoo', objects)
-----


What I'm having trouble with at the moment is that I'm getting errors from
SCons:
scons: warning: Two different environments were specified for target
src/autogen/foo.h,
but they appear to have the same action: $TSNC $TSNC_LANG_FLAG
$_TSNC_SOURCEPATH_FLAGS $TSNC_FLAGS -doxygen $SOURCE
...
scons: *** Multiple ways to build the same target were specified for:
src/autogen/foo.h

I'm guessing that my autogen SConscript file is basically getting executed
twice, which is resulting in "redefined symbols" (so to speak) for the
auto-generated files. I tried to solve this by creating the common
"codegenEnv" environment, but it didn't work.

Is there a way I can fix the problem with the current SConscript structure?
Or maybe I should create a second hierarchy of SConscript files just for
the code generation (maybe call the files SConscript_codegen)?

Thanks for any advice!!!!!
Jason Fritz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://four.pairlist.net/pipermail/scons-users/attachments/20140428/a0d28f9c/attachment.html


More information about the Scons-users mailing list