如何使用可变输出文件列表设置 Xcode 构建规则?
构建规则记录在 Xcode 构建系统指南
它们非常适合将一个输入文件转换为固定数量(通常是一个)输出文件的常见情况。
输出文件必须在构建规则定义的“输出文件”区域中进行描述;每个输出文件一行。通常,输出文件与输入文件具有相同的名称,但具有不同的扩展名。
就我而言,一个输入文件被转换为具有相同扩展名的可变数量的文件。输出文件的数量和名称取决于输入文件的内容,并且事先未知。
稍后必须进一步处理输出文件(在本例中它们是要编译的 C 文件)。
我该如何为这种情况设置构建规则?
欢迎任何建议。
(我在苹果开发者论坛上问了同样的问题,但我认为在这里问也是个好主意)。
Build Rules are documented in the Xcode Build System Guide
They are well adapted to the common case where one input file is transformed into a fixed number (usually one) of output files.
The output files must be described in the "Output Files" area of the build rule definition; one line per output file. Typically the output files have the same name as the input file but have different extensions.
In my case, one single input file is transformed into a variable number of files with the same extensions. The number and the names of the output files depend on the content of the input file and are not known in advance.
The output files will have to be further processed later on (they are in this case C files to be compiled).
How can I set up a build rule for such a case?
Any suggestions welcome.
(I asked the same question on the Apple developer forum, but I figured it'd be a good idea to ask here too).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我处理这个问题的方法是,不是生成多个 C 文件,而是将它们全部连接到一个文件中(例如“AUTOGENERATED.c”),并将其指定为输出文件。
只要您的输出文件不包含任何会发生冲突的内容(同名的静态函数、冲突的#defines 等),这种方法就可以正常工作。
I dealt with this by, instead of generating multiple C files, just concatenating them all together into one file (e.g. "AUTOGENERATED.c"), and specifying that as the output file.
So long as your output files don't contain anything that will conflict (static functions with the same name, conflicting #defines etc.) this works well.
请参阅这篇关于《Cocoa With Love》的文章:
http://cocoawithlove.com/2010/02/custom -build-rules- generated-tables-and.html
这有一个生成自定义 C 代码并将其用作正常构建过程的输入的示例。他在输出中使用 ${} 变量语法
See this article on Cocoa With Love:
http://cocoawithlove.com/2010/02/custom-build-rules-generated-tables-and.html
This has an example of generating custom C code and using that as input to the normal build process. He's using ${} variable syntax in the output
我发现向我的 xcode 项目添加任意数量的文件(并进行一些处理)的最佳方法是编写一些 php 脚本。该脚本可以简单地将文件复制到捆绑包中。棘手的部分是与 xcode 的集成。我花了一些时间才找到一种干净的方法。 (您可以通过此方法使用您喜欢的脚本语言)。
首先,使用“添加运行脚本”而不是“添加复制文件”
Shell 参数:
命令参数:
(xcode 中的屏幕截图)
${SRCROOT} 是您的项目目录。
${CONFIGURATION(...) 是捆绑包目录。正是您所需要的:)
这样,您的脚本返回代码可以停止 xcode 构建(使用 die(0) 表示成功,使用 die(1) 表示失败),并且脚本的输出将在 xcode 的构建日志中可见。
您的脚本将如下所示:(不要忘记 chmod +x)
奖励:这里是我的“add_file”函数。
我
The best way I found to add any number of files to my xcode project (and make some processing) is to write a little php script. The script can simply copy files into the bundle. The tricky part is the integration with xcode. It took me some time to find a clean way. (You can use the script language you like with this method).
First, use "Add Run Script" instead of "Add Copy File"
Shell parameter:
Command parameter:
(screenshot in xcode)
${SRCROOT} is your project directory.
${CONFIGURATION(...) is the bundle directory. Exactly what you need :)
This way, your script return code can stop xcode build (use die(0) for success and die(1) for failures) and the output of script will be visible in xcode's build log.
Your script will look like that: (don't forget chmod +x on it)
BONUS: here my 'add_file' function.
l