tags:

views:

18

answers:

1

I have an SCons project set up as follows:

proj/
    SConstruct
    src/
        c/
        h/
    app1/SConscript
    app2/SConscript
    ...

All source/header files for each application are located in src/c and src/h.


  1. At first step I created a SConstruct in app1 which use the Repository function.

...

src=Split("main.c first.c second.c")

env = Environment(CC='g++', CCFLAGS=['-O0', '-ggdb'], CPPPATH=['.'])

env.Program('appone', src)

Repository("../src/c", "../src/h")

All works fine. scons found all necessary source/header files from repository to build the appone application.


But if I try to build appone hierarchical it will not work :-(

I renamed app1/SConstruct to app1/SConscript and put

SConscript('app1/SConscript')

into proj/SConstruct

Now I get following error:

scons: *** [app1/main.o] Source `app1/main.c' not found, needed by target `app1/main.o'.

How do I configure my proj/SConstruct or proj/app1/SConscript to search for all source files in my Repository directory?

A: 

SCons is looking for your source files in the app1 directory. If you specify the sources like this:

src=Split("#main.c #first.c #second.c")

then scons will search the Repositories for the source files.

A couple extra thoughts:

  1. You may want main.c to be in the app1 directory to avoid conflicts with main.c for other executables. In this case, remove the # from main.c in your source list.

  2. It's probably a good idea to define the Repositories in your top-level SConstruct if multiple apps share the repositories.

  3. It's often useful to build libraries from the shared sources so that unit tests can have their own main functions, but link the same sources as your apps (or so apps can share common modules). It may be easier to do this by putting SConscripts in the shared repository directory to build common libraries. Beyond the scope of this question, but something to consider as your project grows.

Dave Bacher