[Scons-users] How to build variants from generated source files

Dirk Baechle tshortik at gmx.de
Thu Oct 6 11:30:53 EDT 2016


Hi Peterri,

and thanks for your question. You want to do two phases for your build. Use a separate SConscript (not using variant_dir) to create only the C++ sources with your generator as step 1. After that you can call your current SConscript with as many variants as you like, but remove the absolute paths (#generator/...). That should do the trick...untested and from the top of my head. 

Best regards,

Dirk


Am 6. Oktober 2016 15:32:35 MESZ, schrieb Petteri Hintsanen <petterih at iki.fi>:
>Hello all,
>
>I'm stuck with an embarrassingly simple problem with variant builds.
>
>Greatly simplified, I have a code generator tool in a sub-directory. 
>It
>reads some input files and generates C++ source files from the input.
>The generator uses hard-coded file names for its inputs, and it writes
>files into its own sub-directory, again using hard-coded file names.  I
>cannot easily change these.
>
>From the build's standpoint, the generator should be run whenever its
>inputs are modified.  After that the generated sources should be
>recompiled and the object files wrapped into a static library.  The
>object files and the library should go to a separate variant build
>directory.  Visually it should look like this:
>
>./
>| SConstruct
>|- build/                  <-- variant dir
>   |- generated.o
>   |- libmylib.a
>|- generator/
>   |- SConscript
>   |- generator.sh         <-- generator tool
>   |- hello.txt            <-- generator input
>   |- generated.h          <-- generator output
>   |- generated.cpp        <-- generator output
>
>The problem is that generated.o is compiled into the source directory,
>that is, generator/generated.o instead of build/generated.o
>
>How could I get the object file into the build directory?  This is
>important because I have multiple variants, each on its own build
>sub-tree.
>
>My sconscripts look like this:
>
>---------------------------
>
>./SConstruct:
>
>env = Environment()
>Export("env")
>env.SConscript("generator/SConscript", variant_dir = "build", duplicate
>= 0)
>
>./generator/SConscript:
>
>Import('*')
>
>generator_input = Split("""
>hello.txt
>""")
>
>generator_output = Split("""
>#generator/generated.h
>#generator/generated.cpp
>""")
>
>env.Command(target = generator_output,
>            source = generator_input,
>            action = "generator/generator.sh")
>lib = env.Library("mylib", ["#generator/generated.cpp"])
>
>----------------------------
>
>The only workaround I have been able to figure out is to use
>
>obj = env.StaticObject("generated.o", "#generator/generator.cpp")
>lib = env.Library("mylib", obj)
>
>but this gets cumbersome with multiple source files.
>
>I'm afraid I'm lacking some fundamental understanding here.  Any advice
>is greatly appreciated!
>
>Thanks,
>Petteri
>_______________________________________________
>Scons-users mailing list
>Scons-users at scons.org
>https://pairlist4.pair.net/mailman/listinfo/scons-users

-- 
Sent from my Android with K-9 Mail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20161006/0e38ab54/attachment.html>


More information about the Scons-users mailing list