[英]Implicit List of All Build Targets in SCONS?
我有一個scons項目,強制包含幾個頭文件作為編譯器標志。
# Forced include files passed directly to the compiler
env.Append(CCFLAGS = ['/FIinclude.h'])
項目中的任何文件都不包含這些文件。 我需要為它們添加一個顯式依賴項。
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)
我BUILD_TARGETS
的問題是BUILD_TARGETS
列表是空的。 它似乎只包含從COMMAND_LINE_TARGETS
或DEFAULT_TARGETS
傳遞的內容。 我們項目中的所有目標都是隱式構建的。 我們沒有使用env.Default
等。有沒有辦法獲取隱式目標列表,還是我必須手動構建它? 我注意到TARGETS
是保留的,似乎也不包含我想要的東西。
我可以為各自的SConscript文件中的所有env.Depends(target, forced_include_headers)
添加env.Depends(target, forced_include_headers)
,但項目非常大。
我不確定這是解決問題的最佳方法(事實上,我認為創建偽構建器的想法效果更好),但此代碼將返回Object
目標列表:
# 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')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.