2
votes

I want to be able to selectively build a hierarchical source tree based on common build patterns defined at the top-level. The source tree is comprised of a number of different modules, sometimes at different levels within the hierarchy, something like this:

  • Large Module Package
    • Submodule Package A
      • Module A1
      • Module A2
    • Submodule Package B
      • Module B1
  • Small Module Package
    • Module C1
    • Module C2

Each module may depend on any number of other modules (without cycles, of course).

Each module needs to be able to activate a selection of a set of template targets, defined at the top-level, that will look for certain source files and build certain outputs. For example, the Library template target will simply build the current module's shared library. The UnitTest target will make sure all upstream dependencies have their libraries built, look for the unit test source, build and then run a unit test executable.

The goal is to have each module to have its own encapsulated SConscript file that would list a) its dependencies and b) the names of the top-level targets that should be enabled for it.

Ideally, I'd like to ensure these targets can be built in a manner similar to this:

scons ModuleA1_UnitTest

How can I set up scons to do this for me, particularly in a way that is friendly to adding new modules?

1

1 Answers

2
votes

If I understand your question correctly, you can use the SCons Alias() function to do this.

The nice thing about the Alias() function (better description in the SCons man pages) is that you can assign several targets to the same alias, like this:

Module A SConscript:

libAtarget = env.Library(target='a', src=libASrcFiles)
env.Alias('libraries', libAtarget)

Module B SConscript:

libBtarget = env.Library(target='b', src=libBSrcFiles)
env.Alias('libraries', libBtarget)

The scope of the alias is project-wide, meaning it can be added to in different SConscript scripts. Im not sure if you will be able to define an alias in the root SConstruct (for the creation of your template targets) without specifying the target.

Assuming you correctly list the libraries etc needed by the binaries, you shouldnt have to do anything special regarding dependencies on other modules, as SCons should manage that internally.