I am trying to get SCons to generate multiple targets (number unknown directly in SConscript).
I have directory like:
headers/
Header1.h
Header2.h
Header3.h
Header4.h
meta/
headers_list.txt
Now I want SConscript to read headers_list.txt, basing on its contents pick files from headers/ directory (i.e. it might contain only Header1 and Header3), for each of those I want to generate source using some function.
I have been trying to use env.Command to do that, but the issue is that it requires caller to specify targets list which for obvious reasons is not known when invoking env.Command.
The only thing I can think of is running:
for header in parse( headers_file ):
source = mangle_source_name_for_header( header )
env.Command( source, header, generator_action )
But this means I will be running parse( headers_file ) each time I invoke scons.
If parsing is costly and the file is not often changed this step could be easily cached.
What SConsc construct/class/technique I am missing to achieve that caching?
edit:
It seems my question is similar to Build-time determination of SCons targets, but isn’t there a technique without artificial dummy file?
Also, even with temporary file, I don’t see how I am supposed to pass target variable from Command that generates variable number of targets to second one that would iterate over them.
edit 2:
This looks promising.
The only way I found I can do it is with
emitter.Below example consists of 3 files:
SConstructsrc/SConscriptsrc/source.txtOutput:
Also this has one thing I don’t really like, which is parsing of
headers_list.txtwith eachsconsexecution. I feel like there should be a way to parse it only if the file changed. I could cache it by hand, but I still hope there is some trick to make SCons handle that caching for me.And I couldn’t find a way to not duplicate files (
aanda.cbeing the same).One way would be to simply generate library in my_action instead of sources (which is approach I used in my final solution).