You can add flags you want passed down to the compiler to CCFLAGS
(generic) - or to CFLAGS
(C-specific) or CXXFLAGS
(C++-specific). This can be done by appending to CCFLAGS
, or by calling MergeFlags()
, which understands that -isystem
should be sent to CCFLAGS
.
Here's a trivial sconscript file that shows this:
env = Environment()
env.MergeFlags("-isystem other/include")
env.Program("hello", "hello.c")
If the source file includes a header inc.h
which exists in other/include
, the build looks like this:
$ 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]
The flag is passed to gcc, so the treatment there should be correct. Notice that SCons has recorded no dependency on the header in its dependency tree - SCons looks in header directories it was told about via the contents of CPPPATH
, but we didn't do that here. This actually makes the default treatment of headers given by -isystem
consistent with other system headers by SCons - notice stdio.h
is also not tracked as a dependency. If you want dependency tracking for headers in a 3rd-party project, you can also add the directory to CPPPATH
. The directory will appear twice on the command line, but according to the gcc documentation, that's okay: "If a standard system include directory, or a directory specified with -isystem
, is also specified with -I
, the -I
option is ignored."
So if tracking is wanted, a modified script could be:
env = Environment()
env.MergeFlags("-isystem other/include")
env.Append(CPPPATH=["other/include"])
env.Program("hello", "hello.c")
and now:
$ 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