[Scons-users] Scons and external file generator
Непомнящий Евгений Игоревич
johnny at topazelectro.ru
Thu Nov 20 08:49:02 EST 2014
> Yes. See http://www.scons.org/wiki/DynamicSourceGenerator for more details.
Ok. I read this and write small test. But I dont know how to
1. Add "dynamic" object files to Program builder
2. Set correct build order - generator, than source files, depended
from generated headers
==========================================================================
import os
from os import path
######## prepare files
def write(target, content):
with open(target, "w") as f:
f.write(content)
write("prog.cpp",
'''#include "gen/a.h"
#include "gen/b.h"
int main() { return a+b; }
''')
if not path.exists("gen.in"):
write("gen.in", "a b")
######### emulate external generator
def gen_exe(source):
with open(source, "r") as f:
vars = f.read().split(" ")
for v in vars:
write("gen/%s.h" % v, "extern int %s;" % v)
write("gen/%s.cpp" % v, "int %s;" % v)
###########
def scanDir(target, source, env):
write(str(target[0]), "")
cpp = [f for f in os.listdir("gen") if f.endswith(".cpp")]
for f in cpp:
env.Object(cpp) # ok, but how to add this object to program sources?
env = Environment(tools=['msvc', 'mslink'], TARGET_ARCH='x86')
obj = env.Object(["prog.cpp"])
# prog.cpp include gen/a.h, which can include other files. How to say
# scons, that prog.cpp must be compiled after run gen_exe?
# I cant use env.Depends(), because real program consists of many
# files, some of them include directly or indirectly gen/a.h, some - not
env.Command("gen/dummy", "gen.in",
[lambda target, source, env: gen_exe(str(source[0])),
scanDir])
prog = env.Program(obj)
More information about the Scons-users
mailing list