[Scons-users] How to use -isystem instead of -I to include directories of third-party projects in scons?

Mats Wichmann mats at wichmann.us
Wed Nov 30 10:23:36 EST 2022


On 11/30/22 02:21, Lan Yang wrote:
> On Wed, Nov 30, 2022 at 3:57 PM Mats Wichmann <mats at wichmann.us 
> <mailto:mats at wichmann.us>> wrote:
> 
>     Your approach is a valid one, but SCons does not, unfortunately
>     support -isystem fully (issue #3064 exists to record this). You can
>     add it directly to CCFLAGS and it should be emitted to gcc; and the
>     MergeFlags method knows how to do this also, but - unlike for values
>     in CPPPATH - SCons won't look in that directory for internal
>     dependency calculation.
>     -- 
>     Sent from my Android device with K-9 Mail. Please excuse my brevity.
> 
> 
> 
> Hi Mats,
> 
> Thank you for your email.
> 
> The scons does not support -isystem fully according to issue #3064.
> https://github.com/SCons/scons/issues/3064 
> <https://github.com/SCons/scons/issues/3064>
> 
> "You can add it directly to CCFLAGS and it should be emitted to gcc; and 
> the MergeFlags method knows how to do this also, but - unlike for values 
> in CPPPATH - SCons won't look in that directory for internal dependency 
> calculation."
> This part confused me. I think it is because I lack some knowledge.
> 
> Are there any steps I can take to avoid the warnings in third-party's code?

It should be pretty straightforward.  This sconscript snip shows the 
concept:

env = Environment()
env.MergeFlags("-isystem other/include")
env.Program("hello", "hello.c")

I hand-crafted an example where hello.c includes a simple header found 
in other/include.

#include <stdio.h>
#include "inc.h"

int main() {
     printf(HELLO);
}

A build with dependency printing 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]

It builds, it issued the -isystem instruction to gcc, but SCons does not 
detect other/include/inc.h as a dependency.  That may not be a problem - 
if you're designating it a system header, then gcc's rules apply, and 
SCons' normal behavior is also not to track system headers - notice 
stdio.h doesn't appear in dependencies either.

As I look at the gcc manpage I see they instituted a rule that would 
help us - if -isystem is used, and the *same* directory also appears in 
a -I directive, then the latter is ignored. That is, we can duplicate 
these in SCons, and it will instruct SCons to scan for files there, but 
it won't change the gcc behavior. Thus:

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





More information about the Scons-users mailing list