SCons: modify intermediate builder calls

99封情书 提交于 2019-12-11 00:36:23

问题


Is it possible to change the calls to intermediate builders, e.g. by passing a target prefix, to avoid environment conflicts?

As an example, suppose you want to use a source file for two different libraries using different compiler macros like this:

env.Library('libraryA', 'source.c', CCFLAGS=['-DCONFIG_X'])
env.Library('libraryB', 'source.c', CCFLAGS=['-DCONFIG_Y'])

SCons detects a conflict, because the Library-Builder invokes the Object-Builder to compile the source file first with different CCFlags.

The obvious solution is to split the compilation from the linking, like this:

objectA = env.Object('objectA', 'source.c', CCFLAGS=['-DCONFIG_X'])
objectB = env.Object('objectB', 'source.c', CCFLAGS=['-DCONFIG_y'])
env.Library('libraryA', objectA)
env.Library('libraryB', objectB)

I was wondering if there is a more elegant way, which would be especially useful if there are multiple files used as source.

Thanks!


回答1:


This could be achieved using the SCons VariantDir() function, which will place the build targets in a subdirectory.

Here's an example:

VariantDir('buildA', '.', duplicate=0)
VariantDir('buildB', '.', duplicate=0)

env.Library('libraryA', 'buildA/source.c', CCFLAGS=['-DCONFIG_X'])
env.Library('libraryB', 'buildB/source.c', CCFLAGS=['-DCONFIG_Y'])

This will build a different version of source.c in both buildA and buildB. Although the actual source.c source file is not in those build directories, you refer to it as if it was, so SCons knows where to put the output.

There's a better description for the VariantDir() function in the SCons man pages.




回答2:


VariantDir() is the right general answer, but for simple cases you can use OBJPREFIX to put the objs for a given target in a subdir or just make them unique.

env.Library('libraryA', 'source.c', CCFLAGS=['-DCONFIG_X'], OBJPREFIX='libA-')


来源:https://stackoverflow.com/questions/19010576/scons-modify-intermediate-builder-calls

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