SCons dependencies between SConstruct-independent

2019-07-18 09:28发布

Right now I have a project structure similar to this one:

project1/SConstruct (creates library1 and executable1)
         files
project2/SConstruct (creates library2 and executable2)
         files
project3/SConstruct (creates executable3 without libraries
                     creates executable4 with library1 and library2)
         files

I can build all projects with SCons without problems, but I'd like to add a dependency from projects 1 and 2 into project 3. When running scons in project 3, if projects 1 or 2 are not up-to-date, I'd like them to be built.

This is similar to SCons: directory dependency in a parallel build with the difference that I have several SConstruct files, one for each project.

I'd also like to pass command-line options to the dependencies projects, i.e., when running scons debug=1 in project 3, projects 1 and 2 are rebuilt with debug=1.

Is there a way to achieve this or should I change my directory/build structure?

1条回答
叼着烟拽天下
2楼-- · 2019-07-18 10:21

You don't have to change your basic build structure. All you need is to combine your single projects into a common dependency tree, such that SCons can automatically figure out the rest for you. For this, add a top-level SConstruct file in the same folder as your "project_x" dirs and call your sub-projects like this:

SConscript('project1/SConstruct')
SConscript('project2/SConstruct')
SConscript('project3/SConstruct')

Then in your project3, add the library from project1 (let's name it "libproj1.a") and its path:

env = Environment()
env.Append(LIBS = ['proj1'])
env.Append(LIBPATH = ['../project1'])
env.Program('main3','main3.cpp')

and you're done. Like this, the "debug=1" option reaches all the projects, and automatically triggers rebuilds if required. If you want to build a single project/target, you can specify it on the command line:

scons project1

or

scons project3/main3

.

查看更多
登录 后发表回答