SCons dependencies between SConstruct-independent projects in different directories

怎甘沉沦 提交于 2019-12-11 03:12:17

问题


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:


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

.



来源:https://stackoverflow.com/questions/23894821/scons-dependencies-between-sconstruct-independent-projects-in-different-director

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!