Search code examples
c++gccincludescons

SCons VariantDir and isystem include paths


We have a SConscript for a library which consists largely of autogenerated code. This produces a lot of compiler warnings, so instead of including the header files via CPPPATH I tried to use -isystem.

However, due to the VariantDir, the include paths for the header files do not match In the SConscript file of the library we had:

envGlobal.Append(CPPPATH=[Dir('./include')])

This correctly produced the compiler includes (despite VariantDir): -I<library root>/include.

When using isystem like this:

envGlobal.Append(CCFLAGS=['-isystem', Dir('./include')])

The result is: -isystem build/<library_root>/include where the header files are not available and not copied to.

Is there any easy solution to that situation. For example, can get the actual source path from inside the SConscript without the redirection from VariantDir? Something like this:

source_dir = PathWithoutVariantDir('.')
envGlobal.Append(CCFLAGS=['-isystem', os.path.join(source_dir, './include')])

Solution

  • To answer the very last part of the original question: yes, you can obtain the original path of something that would appear translated for a variant dir: node objects have a method srcnode() for that, see https://scons.org/doc/production/HTML/scons-man.html#node_objects.

    But - it is still the case that SCons doesn't yet know about -isystem. Or rather - only the ParseFlags method knows about it, and only to the extent that it should be added to CCFLAGS. It doesn't actually act on it itself (as in, instructing the scanner to handle things as system headers), just lets the flag be passed through to the compiler. There are existing issues filed on that.

    EDIT: here's a link to this in the SCons issue tracker: https://github.com/SCons/scons/issues/3064