Search code examples
scons

Vary CPPPATH based on file compiled


I have some .c files that will compile to .o files. These .c files include a third party .h file. I would like to only include the third party folder as an include location for only the files that need it.

Here are pseudo code of what I am looking to do:

gcc -o one.o -Imypath/include one.c
gcc -o two.o -Imypath/include two.c
gcc -o thirdpartyinterface.o -Imypath/include -Ithirdpartypath/include thirdparty.c
gcc -o theexe one.o two.o thirdpartyinterface.o

Note that I only want the thirdpartypath included for my thirdpartyinterface code.

The problem I am facing is that scons seems to like to use one CPPPATH for all things compiled with the one env.

Upon reflection I think I could build my thirdpartyinterface as a .a if that would help.


Solution

  • You can include keyword arguments to do temporary overrides when calling a builder. Those are active only for the specific build and don't change the active environment. For example:

    obj = Object('hello.c', CCFLAGS='-MD -MF hello.d', CPPPATH='.')