不同目录中与SConstruct无关的项目之间的SCons依赖关系 [英] SCons dependencies between SConstruct-independent projects in different directories
问题描述
现在我有一个与此项目相似的项目结构:
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
我可以毫无问题地使用SCons构建所有项目,但我想添加项目的依赖项1和2进入项目3。在项目3中运行 scons
时,如果项目1或2不是最新的,我希望它们可以构建。
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.
这类似于 SCons :并行构建中的目录依赖性,区别在于我有几个SConstruct文件,每个项目一个。
This is similar to SCons: directory dependency in a parallel build with the difference that I have several SConstruct files, one for each project.
我还想传递命令-线路优化依赖项项目,即在项目3中运行 scons debug = 1
时,将使用 debug = 1 $重建项目1和2。 c $ c>。
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?
推荐答案
您不必更改基本的构建结构。您所需要做的就是将单个项目组合到一个公共的依赖树中,以便SCons可以自动为您解决其余的问题。
为此,请在与 project_x目录相同的文件夹中添加顶级SConstruct文件,并按如下所示调用子项目:
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')
然后在您的project3中,添加project1中的库(将其命名为 libproj1.a)及其路径:
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')
您就完成了。
这样, debug = 1选项可到达所有项目,并在需要时自动触发重建。
如果要构建单个项目/目标,可以在命令行上指定它:
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
或
scons project3/main3
。
这篇关于不同目录中与SConstruct无关的项目之间的SCons依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!