Search code examples
c++gccscons

scons - How to add search directories to an existing scanner


My main goal is to add support of -isystem include paths in scons, like this is proposed here : https://stackoverflow.com/a/2547261/4042960

The solution of creating new variables works fine: I do that:

#### Add support for system headers
env['SYSTEMINCPREFIX'] = '-isystem '
env['SYSTEMINCSUFFIX'] = ''
env['_CPPSYSTEMINCFLAGS'] = '$( ${_concat(SYSTEMINCPREFIX, CPPSYSTEMPATH, SYSTEMINCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
env['_CCCOMCOM'] += ' $_CPPSYSTEMINCFLAGS'

I use it by adding for instance:

env.Append(CPPSYSTEMPATH = ['/my/include/path'])

My problem is that now, the path /my/include/path is not scanned by the C (or C++) dependency scanner. After many search, I failed to find how to add my variable "CPPSYSTEMPATH" to be treated like "CPPPATH" by the dependency scanner.

Does anyone know how I could add the search path contained in "CPPSYSTEMPATH" to the existing C scanner ?

I hope that my problem is clear enough, else do not hesitate to tell me.


Solution

  • Here's a basic recipe for replacing the FindPath method of the default C scanner, but be warned it's an ugly hack:

    # Create environment
    env = Environment()
    # Define your new env variable as combination of both paths
    env['MYCPPPATHS'] = ['$CPPPATH','$CPPSYSTEMPATH']
    
    # Replace the path_function of the standard C scanner by:
    import SCons.Tool
    import SCons.Scanner
    setattr(SCons.Tool.CScanner,'path_function',SCons.Scanner.FindPathDirs('MYCPPPATHS'))
    
    # Do your build stuff...
    env['CPPSYSTEMPATH'] = 'myinclude'
    env.Program('main','main.cpp')
    

    By the way, why not ask these kind of questions on our user mailing list scons-users@scons.org? ;)