As I understand it, you only want to generate the .cc version if any of the source files changes, and you want to create the library only if version.cc changes or if any of the library source files changes. That is, consider version.cc as one of the source files for the library.
If so, you can consider two sets of dependencies, both of which will be controlled by the SCons dependency check.
It is not clear what version.cc generation consists of, but suppose the python GenerateVersionCode () function will do just that: generate the .cc version, but will not have any dependency related to the dependency logic.
Here is the SConscript code:
def GenerateVersionCode(env, target, source): # fill in generation code here # The version.cc checking env.Command(target='version.cc', source=['a.cc', 'b.cc'], action=GenerateVersionCode) # The library env.Library(target='test', source=['version.cc', 'a.cc', 'b.cc'])
It does not have to be necessary, but it can be done one more step by explicitly setting the dependency on the Library target to target.cc using the SCons Depends () function.
Here is the result that I get when creating, and instead of using the GenerateVersionCode () function, I use the simple shell script versionGen.sh, thereby changing the Command () call to this:
env.Command(target='version.cc', source=['a.cc', 'b.cc'], action='./versionGen.sh')
Here is the first build:
> scons scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... g++ -o ao -c a.cc g++ -o bo -c b.cc ./versionGen.sh g++ -o version.o -c version.cc ar rc libtest.a version.o ao bo ranlib libtest.a scons: done building targets.
Then, without changing anything, I build again, and he does nothing:
> scons scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... scons: `.' is up to date. scons: done building targets.
Then I modify a.cc and build again, and it generates a new version of version.cc:
> vi a.cc > scons scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... g++ -o ao -c a.cc ./versionGen.sh g++ -o version.o -c version.cc ar rc libtest.a version.o ao bo ranlib libtest.a scons: done building targets.