Implicit List of All Build Targets in SCONS?
I have an scons project that force includes several header files as a compiler flag.
# Forced include files passed directly to the compiler
env.Append(CCFLAGS = 开发者_运维技巧['/FIinclude.h'])
These files are not included by any files in the project. I need to add an explicit dependency for them.
forced_include_headers = ['include.h']
# Trying to add an explicit dependency for each build target
for object in BUILD_TARGETS:
env.Depends(object, forced_include_headers)
The problem I'm running into is that BUILD_TARGETS
list is empty. It seems to only contain things passed from COMMAND_LINE_TARGETS
or DEFAULT_TARGETS
. All of the targets in our project are built implicitly. We do not make use of env.Default
, etc. Is there a way to get the implicit target list, or do I have to manually build it? I noticed that TARGETS
is reserved and does not seem to contain what I want either.
I can add an env.Depends(target, forced_include_headers)
for all of the targets in their respective SConscript files, but the project is quite large.
I'm not sure that this is the best way to solve the problem (in fact, I think the idea of creating a pseudo-builder works better), but this code will return a list of Object
targets:
# Typical SConstruct / SConscript
env = Environment()
env.Program('foo.c')
lib = env.SharedLibrary('bar.c')
env.Program('foo2.c', LIBS=[lib])
SConscript('subdir/SConscript', exports={'env':env})
# Get a list of all Object targets
def get_all_targets(env, node='.'):
def get_all_targets_iter(env, node):
if node.has_builder() and node.get_builder().get_name(env) in ('Object', 'SharedObject'):
yield node
for kid in node.all_children():
for kid in get_all_targets(env, kid):
yield kid
node = env.arg2nodes(node, env.fs.Entry)[0]
return list(get_all_targets_iter(env, node))
# Force them all to depend upon some header
env.Depends(get_all_targets(env), 'site_wide.h')
精彩评论