不同目录下的SConscript到源文件 [英] SConscript in different directory to source files

查看:79
本文介绍了不同目录下的SConscript到源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建具有多个环境的代码,输出到多个目标目录.管理这个的自然方法似乎是使用变体目录.所以我可能想用不同的选项和不同的 VariantDirs 多次构建相同的文件集.所以我希望能够在不同位置拥有多个 SConscript 文件,所有这些文件都指向同一个源目录.

I'm building code with multiple environments, outputting to multiple target directories. The natural way to manage this seems to be with variant directories. So I might want to build the same set of files multiple times with different options and different VariantDirs. So I want to be able to have multiple SConscript files in different locations, all referring back to the same source directory.

我尝试过的一种选择是这样做:

One option I've tried is to do this:

SConstruct
src/test.cpp
src/magic/SConscript

这是我的 SConstruct:

This is my SConstruct:

env = Environment()

SConscript('src/magic/SConscript',
    variant_dir = 'build/src',
    src_dir = 'src',
    exports={'env':env},
    duplicate=0)

这是 src/magic/SConscript:

and this is src/magic/SConscript:

Import('env')

source = 'test.cpp'

env.Object(source)

我得到这个输出:

scons: *** [build/src/magic/test.o] Source `src/magic/test.cpp' not found, needed by target `build/src/magic/test.o'.

这看起来 variant_dirsrc_dir 都没有被 Object 尊重,因为它们都没有提到 magic完全没有.

This looks like both the variant_dir and src_dir are not being respected by Object, since neither mention magic at all.

我是否误解了 variant_dir/src_dir 的工作原理,以及构建具有不同目标的同一组文件的最佳方法是什么?

Have I misunderstood how variant_dir/src_dir are meant to work, and what is the best way to build the same set of files with different targets?

推荐答案

您的文件/文件夹层次结构不符合 SConstruct/SConscript 文件中的构建规范.请注意 SCons 中的文件路径通常如何与当前 SConscript 的位置相关,因此:

Your file/folder hierarchy doesn't fit the build specification in your SConstruct/SConscript files. Note how file paths in SCons are usually relative to the location of the current SConscript, so:

source = 'test.cpp'
env.Object(source)

src/magic/SConscript 中被扩展为 src/magic/test.cpp...这显然不存在.您可以使用 ../test.cpp 作为文件名,或者直接将 SConscript 从 src/magic 移动到 src 文件夹.

in src/magic/SConscript gets expanded to src/magic/test.cpp...which obviously doesn't exist. You could use ../test.cpp as filename, or move the SConscript one up from src/magic to the src folder directly.

一些补充说明:

1.) 当您在 SConscript 调用中为 SConscript 文件的名称指定路径时:

1.) When you specify a path for the name of the SConscript file in the SConscript call:

SConscript('src/SConscript',
    variant_dir = 'build',
    exports={'env':env},
    duplicate=0)

SCons 将自动从第一个参数的路径中导出 src_dir 参数.

SCons will automatically derive the src_dir argument from the path of the first argument.

2.) 请查看用户指南中的第 14 章分层构建"(http://www.scons.org/doc/production/HTML/scons-user.html).

2.) Please check out the chapter 14 "Hierarchical Builds" in the UserGuide ( http://www.scons.org/doc/production/HTML/scons-user.html ).

这篇关于不同目录下的SConscript到源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆