简体   繁体   English

scons:对象,源代码,可执行文件,都在单独的目录中

[英]scons: objects, sources, executables, all in separate directories

I'm new to scons and I managed to figure out how to redirect the binaries (executables+objects) that one (con)script produces into another directory. 我是scons的新手,我设法弄清楚了如何将一个(脚本)脚本生成的二进制文件(可执行文件和对象)重定向到另一个目录。

In my main project directory (root), I have a single SConstruct file, which contains the following line: 在主项目目录(根目录)中,我有一个SConstruct文件,其中包含以下行:

SConscript("source/SConscript", variant_dir="bin")

As evident, it sets the build (variant) directory of the source/SConscript script to be bin . 显而易见,它将source/SConscript脚本的build(变量)目录设置为bin

source/SConscript : source/SConscript

common = []

env = Environment()
env.Program("test", ["test.cpp"] + common)
env.Program("sdl-test", ["sdl_test.cpp"] + common, LIBS=["SDL2"])

My current setup is less than idea... 我当前的设置还不尽如人意...

I'd like to have all the object files end up in object , keep all the source files in source , and have the final program binaries be built in bin directory. 我想将所有目标文件都存储在object ,将所有源文件保留在source ,并在bin目录中构建最终的程序二进制文件。

How can I achieve that with scons? 如何用scons实现呢? (Preferably without any messing with imperative (regular) Python, I hope that this is a built-in feature.) (最好不要弄乱命令式(常规)Python,我希望这是一个内置功能。)

You can do it by adding another SConscript script for the objects where you would set the variant_dir to a different directory, it would look something like this: 您可以通过为对象添加另一个SConscript脚本来实现此目的,在该脚本中,您将variant_dir设置为其他目录,它看起来像这样:

SConstruct SConstruct

env = Environment()
SConscript('source/SConscript_obj', variant_dir='object',
           duplicate=0, exports='env')
SConscript('source/SConscript', variant_dir='bin',
           duplicate=0, exports='env')

source/SConscript_obj 源极/ SConscript_obj

Import('env')

env.Object("test.cpp")
env.Object("sdl_test.cpp")

source/SConscript 源极/ SConscript

Import('env')

env.Program("test", ["#/object/test.o"])
env.Program("sdl-test", ["#/object/sdl_test.o"], LIBS=["SDL2"])

Or, in SConscript_obj, you could make a library instead of just compiling objects. 或者,在SConscript_obj中,您可以创建一个库,而不仅仅是编译对象。

You could also consider adding calls to VariantDir in the existing SConscript, but Im not sure how well that would work. 您也可以考虑在现有的SConscript中添加对VariantDir的调用,但是我不确定这样做的效果如何。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM