您可以将要传递给编译器的标志添加到CCFLAGS(通用)-或CFLAGS(C-specific)或CXXFLAGS(C++-specific)。这可以通过附加到 CCFLAGS 或调用 MergeFlags() 来完成,-isystem 应该发送到 CCFLAGS。
这是一个简单的 sconscript 文件,显示了这一点:
env = Environment()
env.MergeFlags("-isystem other/include")
env.Program("hello", "hello.c")
如果源文件包含 other/include 中存在的标头 inc.h,则构建如下所示:
$ scons -Q --tree=prune
gcc -o hello.o -c -isystem other/include hello.c
gcc -o hello hello.o
+-.
+-SConstruct
+-hello
| +-hello.o
| | +-hello.c
| | +-/bin/gcc
| +-/bin/gcc
+-hello.c
+-[hello.o]
该标志被传递给 gcc,因此那里的处理应该是正确的。请注意,SCons 在其依赖关系树中没有记录对标头的依赖性 - SCons 在通过 CPPPATH 的内容告知它的标头目录中查找,但我们在这里没有这样做。这实际上使 -isystem 给出的标头的默认处理与 SCons 的其他系统标头一致 - 注意 stdio.h 也没有作为依赖项进行跟踪。如果你想在 3rd 方项目中对标头进行依赖跟踪,你可以还将目录添加到CPPPATH。该目录将在命令行中出现两次,但根据 gcc 文档,这没关系:“如果标准系统包含目录,或用-isystem指定的目录,也用-I指定,则忽略-I选项。“
因此,如果需要跟踪,修改后的脚本可以是:
env = Environment()
env.MergeFlags("-isystem other/include")
env.Append(CPPPATH=["other/include"])
env.Program("hello", "hello.c")
现在:
$ scons -Q --tree=prune
gcc -o hello.o -c -isystem other/include -Iother/include hello.c
gcc -o hello hello.o
+-.
+-SConstruct
+-hello
| +-hello.o
| | +-hello.c
| | +-other/include/inc.h
| | +-/bin/gcc
| +-/bin/gcc
+-hello.c
+-[hello.o]
+-other
+-other/include
+-other/include/inc.h