[英]How do I set up scons to build a project that has generated source files?
我正在一个C ++项目中,该项目具有一些手动编码的源文件,以及一些由命令行工具生成的源文件和头文件。 生成的实际源文件和头文件由该工具读取的JSON文件的内容确定,因此无法硬编码到scons脚本中。 我想设置scons,以便在清理项目然后进行创建时,它将知道运行命令行工具来生成生成的源文件和头文件,这是第一步,然后在编译完我的手动编码后文件和生成的源文件,并将它们链接为二进制文件。 这可能吗? 我对如何实现这一目标不知所措,因此我们将不胜感激。
是的,这是可能的。 根据您用于创建头文件/源文件的工具,您要查看我们的ToolIndex, 网址为https://bitbucket.org/scons/scons/wiki/ToolsIndex ,或阅读我们的指南https://bitbucket.org / scons / scons / wiki / ToolsForFools来编写您自己的Builder。 根据您的描述,您可能必须编写自己的Emitter,该Emitter解析JSON输入文件并返回最终将由调用产生的文件名。 然后,您需要做的就是:
# creates foo.h/cpp and bar.h/cpp
env.YourBuilder('input.json')
env.Program(Glob('*.cpp'))
即使文件在硬盘上还不存在, Glob
也会找到它们,并将它们添加到整体依赖项中。 如果您还有其他疑问或问题,请考虑通过scons-users@scons.org订阅我们的用户邮件列表(另请参见http://scons.org/lists.html )。
多亏了Dirk Baechle,我才开始工作了-对这里感兴趣的其他人是我使用的代码。
import subprocess
env = Environment( MSVC_USE_SCRIPT = "c:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\bin\\vcvars32.bat")
def modify_targets(target, source, env):
#Call the code generator to generate the list of file names that will be generated.
subprocess.call(["d:/nk/temp/sconstest/codegenerator/CodeGenerator.exe", "-filelist"])
#Read the file name list and add a target for each file.
with open("GeneratedFileList.txt") as f:
content = f.readlines()
content = [x.strip('\n') for x in content]
for newTarget in content:
target.append(newTarget)
return target, source
bld = Builder(action = 'd:/nk/temp/sconstest/codegenerator/CodeGenerator.exe', emitter = modify_targets)
env.Append(BUILDERS = {'GenerateCode' : bld})
env.GenerateCode('input.txt')
# Main.exe depends on all the CPP files in the folder. Note that this
# will include the generated files, even though they may not currently
# exist in the folder.
env.Program('main.exe', Glob('*.cpp'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.