问题
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