Reputation: 16449
I have this SConstruct
file:
lib=Library("foo", "foo.c", CPPFLAGS="-include foo.h")
Because of -include
, I need to recompile whenever foo.h
changes. SCons doesn't automatically figure this out.
I tried adding a dependecy - Depends(lib, "foo.h")
- but it only causes a useless relink.
How can I make foo.c
recompile when foo.h
changes?
Extra credit - what I really need is to recompile not only when foo.h
changes, but also when headers it includes change. But detecting foo.h
changes are good enough.
Upvotes: 0
Views: 831
Reputation: 4052
As a first shot this is the best I can come up with:
# Construct special environment
env = Environment()
env.Append(CPPFLAGS = ['-include', 'foo.h'])
# Compile objects separately
objs = env.Object(Glob('*.c'))
# Add explicit dependencies
add_deps = ['foo.h']
for o in objs:
env.Depends(o, add_deps)
# Create final library
env.Library('myfoo', objs)
The extension *.o
isn't mentioned directly anywhere in the build description, and add_deps
can easily be extended by the headers that get included via "foo.h
".
Upvotes: 1