Search code examples
scons

Trigger rebuild if header changes


I have non system headers, which I use to compile a program via SCons. Problem is they sometimes change but SCons does not seem to scan for changes in the headers at all. Is there a way to tell SCons to scan the headers for changes?


Solution

  • Assuming you're talking about c/c++, SCons should always scan the header files, assuming the include paths have been correctly set to do so.

    If the include paths have been specified with the CPPPATH construction variable, then the include files in that path will be scanned for changes. The include paths specified with this variable should not have the -I prepended, as SCons will do that in a portable manner.

    This variable can be appended to as follows:

    env = Environment()
    # These paths WILL BE scanned for header file changes
    env.Append(CPPPATH = ['path1', '/another/path', 'path3'])
    

    If the include paths have been specified in the CCFLAGS or CXXFLAGS construction variables, then the include files in that path will not be scanned for changes. The include paths specified in either one of these variables must have the -I prepended. This approach is beneficial when specifying system header include paths that will most likely never change, thus speeding up the build process.

    Paths can be appended to the CXXFLAGS variable:

    env = Environment()
    # These paths will NOT be scanned for header file changes
    env.Append(CXXFLAGS = ['-Ipath1', '-I/another/path', '-Ipath3'])
    

    Here is a list of the rest of the SCons construction variables.