0
votes

I'm building a modular project with SCONS. I'd like to have multiple SW products to be compiled as a colleciton of multiple SW subcomponents:

Eg: *Sconstruct:

Sconscript("SW_PRODUCT_1.Sconscript")
Sconscript("SW_PRODUCT_2.Sconscript")

*With SW_PRODUCT_1.Sconscript:

Sconscript("COMPONENT_A.Sconscript")  
Sconscript("COMPONENT_B.Sconscript")
Sconscript("COMPONENT_C.Sconscript")

*And with SW_PRODUCT_2.Sconscript:

Sconscript("COMPONENT_A.Sconscript")
Sconscript("COMPONENT_B.Sconscript")

ie I'd like the Builder compile once each component as a Library, and then each SW_PRODUCT take the list of components it wants to build an executable.

But I have the next problem , the SCONS tool returns the next error:

"scons: *** Two environments with different actions were specified for the same target"

This is truth since according to the script the components A and B are invoked twice with exactly the same target names but I hope the SCONS would handle the fact that multiple Targets can share libraries. I expected the SCONS to realize in the second call to COMPONENTS_A and B that the target "up to date" but it does not work that way.
I've though about a workaround compiling two diferent Libraries (different name) for each PRODUCT but that is not what I want since the Libraries are exactly the same and I don't want to waste compilation time to build exactly the same N times. I would like just to build the same pool of libraries and then pick such libraries on demand with each product. Is there any easy way to handle this architecture with Scons?

1

1 Answers

1
votes

Simply put all (!) required libraries (=components) and products into the same top-level SConstruct file. You can use SConscript calls to include the build definitions from your different subfolders, but don't leave any of them out. Try to imagine that you want to build everything at once. Don't try to setup build dependencies (or a build order) by how you include SConscripts for "components" in your build files, or not.

This is important, because it ensures that SCons can see the full source tree with all sources, libraries and programs that you might ever need. Then it is able to figure out the build dependencies all by itself.

In the next step, simply define combined targets for your products via the Alias command, i.e.:

env = Environment()
program_a = env.Program('maina', Glob('*.cpp'), LIBS=['compx','compy'])
env.Alias('producta', program_a)

(see also chap. 25 "Alias Targets" in the User Guide). Now you are able to call

scons producta

and SCons will figure out for you, which components are up-to-date or need a rebuild. If you then specify multiple targets

scons producta productb productk

the required libs will only be built once and are shared among the products automatically.

In our SCons Wiki:Recipes you can also find some more examples and setups to give you an impression about how other people setup their projects.