Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Hierarchical Build with SCons

Tags:

python

scons

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.

like image 219
ereOn Avatar asked Sep 14 '10 13:09

ereOn


People also ask

What compiler does SCons use?

The Visual C++ compiler option that SCons uses by default to generate PDB information is /Z7 . This works correctly with parallel ( -j ) builds because it embeds the debug information in the intermediate object files, as opposed to sharing a single PDB file between multiple object files.

What is a SCons file?

SCons is a computer software build tool that automatically analyzes source code file dependencies and operating system adaptation requirements from a software project description and generates final binary executables for installation on the target operating system platform.

How do you clean SCons?

When using SCons, it is unnecessary to add special commands or target names to clean up after a build. Instead, you simply use the -c or --clean option when you invoke SCons, and SCons removes the appropriate built files.


2 Answers

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')
like image 191
S.Lott Avatar answered Sep 21 '22 11:09

S.Lott


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).

like image 27
d.b Avatar answered Sep 18 '22 11:09

d.b