0

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')])
the_summer
  • 439
  • 3
  • 10
  • why are you using os.path.abspath() and os.path.join? – bdbaddog Mar 28 '23 at 14:07
  • is your autogenerated code output into the variant dir? – bdbaddog Mar 28 '23 at 14:08
  • @bdbaddog no, it is saved in a repository and only generated manually, not generated by scons. – the_summer Mar 28 '23 at 14:10
  • You may try to add `#` at the beginning of our paths. (https://scons.org/doc/production/HTML/scons-user/ch14s03.html) It tells SCons to start at root level of the project. Btw, if you just use `-isystem` SCons wont recognize it to build the dependency tree correctly. See here: https://stackoverflow.com/q/74624187/3052438 – Piotr Siupa Mar 28 '23 at 16:02
  • are you using `duplicate=True` (which is the default if you're not specifying when using VariantDir or SConscript()'s variant_dir). Are you specifying variant dirs via VariantDir(), or via the variant_dir argument to SConscript()? – bdbaddog Mar 28 '23 at 18:47
  • @bdbaddog we used `duplicate=False`. I also tried with `duplicate=True`, but this didn't change anything. I guess because this only applies to source files and not the header files. And we are using `env.VariantDir` not the argument to SConscript. – the_summer Mar 29 '23 at 07:25
  • It depends what your CPPPATH includes. If it includes your variant dir, or the source to your variant dir. If it only includes your variant dir, the files will be duplicated into the variant dir. SCons doesn't know about header files and source files. All files are the same (at least as far as variant dir is concerned) – bdbaddog Mar 29 '23 at 18:04

2 Answers2

1

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

Mats Wichmann
  • 800
  • 6
  • 6
  • Thank you very much that helped. I could make it work now with `envGlobal.Append(CCFLAGS=['-isystem', Dir('./include').srcnode()])`. Do you want to update your answer with that? And could you maybe put a link to the open issue? – the_summer Mar 29 '23 at 07:29
0

Try

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

or

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

If you want to include the source directory of your variant dir, instead of the path to your variant dir assuming the above is in a variant dir try the following: (haven't tried, but think it should work)

envGlobal.Append(CPPPATH=[Dir('./include').srcnode()])
envGlobal.Append(CCFLAGS=['-isystem', Dir('./include').srcnode()])
bdbaddog
  • 3,357
  • 2
  • 22
  • 33
  • Thanks `Dir` is indeed easier to read, but the problem is the same. With CPPPATH I get the correct path for the header files, with CCFLAGS, I get a directory inside the VariantDir ("build") where the header files are not available. – the_summer Mar 28 '23 at 14:14