SConscript in different directory to source files

巧了我就是萌 提交于 2019-12-24 14:01:31

问题


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

This is my SConstruct:

env = Environment()

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

and this is src/magic/SConscript:

Import('env')

source = 'test.cpp'

env.Object(source)

I get this output:

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

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

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?


回答1:


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)

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.

Some further remarks:

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 will automatically derive the src_dir argument from the path of the first argument.

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



来源:https://stackoverflow.com/questions/33480910/sconscript-in-different-directory-to-source-files

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