6

I have a library project that contains some samples in a subfolder.

The library itself has a SConstruct file and each sample has its own folder and its own SConstruct file.

I'd like to add a target to the main (root) SConstruct file which would allow me to compile the library as usual, and all the samples, at once.

Is there an existing mechanism/builder for this ?

P.S: I don't want to have only one big SConstruct file because I want the samples folders to remain independant.

ereOn
  • 53,676
  • 39
  • 161
  • 238

2 Answers2

8

http://www.scons.org/doc/production/HTML/scons-man.html

Creating a Hierarchical Build

Notice that the file names specified in a subdirectory's SConscript file are relative to that subdirectory.

SConstruct:

env = Environment()
env.Program(target = 'foo', source = 'foo.c')

SConscript('sub/SConscript')

sub/SConscript:

env = Environment()
# Builds sub/foo from sub/foo.c
env.Program(target = 'foo', source = 'foo.c')

SConscript('dir/SConscript')

sub/dir/SConscript:

env = Environment()
# Builds sub/dir/foo from sub/dir/foo.c
env.Program(target = 'foo', source = 'foo.c')
S.Lott
  • 384,516
  • 81
  • 508
  • 779
4

For those like me coming to this question from Google, I found a more complete example of building a library and code that called it here.

(Apologies if this answering of an old question is frowned upon--a large number of searches for various combinations of "scons" "subdirectory" "hierarchical" "build", etc. suggest this page, and I'd like to save others the 8+ hours I just spent trying to get hierarchical builds to work cleanly).

d.b
  • 403
  • 5
  • 10
  • That's a good reference indeed. After several years, [I could finally achieve my goals](https://github.com/freelan-developers/freelan-all) using SCons hierarchical builds: the project is separated into several libs/samples/apps that all use the same SCons files. – ereOn Jul 22 '14 at 07:01