扩展@LangerJan 和@BenG 提出的想法......这是一个完整的跨平台示例(替换env['IS_WINDOWS']
为您的Windows平台检查)
from SCons.Util import is_List
def enable_extlib_headers(env, include_paths):
"""Enables C++ builders with current 'env' to include external headers
specified in the include_paths (list or string value).
Special treatment to avoid scanning these for changes and/or warnings.
This speeds up the C++-related build configuration.
"""
if not is_List(include_paths):
include_paths = [include_paths]
include_options = []
if env['IS_WINDOWS']:
# Simply go around SCons scanners and add compiler options directly
include_options = ['-I' + p for p in include_paths]
else:
# Tag these includes as system, to avoid scanning them for dependencies,
# and make compiler ignore any warnings
for p in include_paths:
include_options.append('-isystem')
include_options.append(p)
env.Append(CXXFLAGS = include_options)
现在,在配置使用外部库时,而不是
env.AppendUnique(CPPPATH=include_paths)
称呼
enable_extlib_headers(env, include_paths)
就我而言,这在 Linux 上将修剪后的依赖树(使用 生成--tree=prune
)减少了 1000 倍,在 Windows 上减少了 3000 倍!它将无操作构建时间(即所有目标都是最新的)加快了 5-7 倍。在此更改之前修剪的依赖关系树有 400 万个来自 Boost 的包含。这太疯狂了。