Xcode项目模板中的按文件编译器标志 [英] Per-file compiler flags in Xcode project template

查看:65
本文介绍了Xcode项目模板中的按文件编译器标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个新的Xcode项目模板,并且我想包含一个非ARC的库.但是我的整个项目都是ARC,因此构建项目的唯一方法是在该库中的文件上指定编译器标志(-fno-objc-arc).

I am building a new Xcode project template and I want to include a library that is non-ARC. But my whole project is ARC, so the only way how to build the project is to specify a compiler flag (-fno-objc-arc) on the files from that library.

如何在Xcode项目模板中做到这一点?
我尝试将其设置为Definitions词典中的特定文件,分别为COMPILER_FLAG和CompilerFlag.它们都不起作用.

How do I do that in an Xcode project template?
I tried setting it on specific files in the Definitions dictionary, both as COMPILER_FLAG and CompilerFlag. Neither of them works.

我对此完全没有文档,但是我很确定可以做到.

I have found absolutely no documentation on this, but I am pretty sure it can be done.

更新:
苹果回答了我的支持请求,指出目前无法做到这一点.因此,不幸的是,我们运气不佳,直到他们最终对模板及其文档做出了一定的贡献.

UPDATE:
Apple replied to my support request stating that there is no way of doing that right now. So unfortunately, we are out of luck, until they finally do something about the templates and their documentation.

更新2:
我有一个想法,如何通过使用构建阶段脚本来对此进行一些修改,该脚本将检查Xcode项目并添加所需的标志.我将尽快发布答案.

UPDATE 2:
I've got an idea how to hack this a little bit by using a build phases script, that will check the Xcode project and add the required flags. I will post an answer soon.

推荐答案

好,所以即使我得到了苹果的负面回应(他们在模板解析器中也不支持),我还是找到了一种方法它.

Ok, so even though I got a negative response from Apple (they don't support this in their template parser) I've found a way how to do it.

我基本上会在模板中添加新的构建阶段-运行脚本.该脚本将使用-fno-objc-arc标志标记所需的文件,然后从项目中将其删除.

I would basically add new build phase to the template - run script. This script woudl flag the required files with the -fno-objc-arc flag and then delete itself from the project.

这是添加标志的方法:

PROJ_FILE="${PROJECT_FILE_PATH}/project.pbxproj"
STR_SRCH="\* Class.m \*\/"
STR_RPLC="\* Class.m *\/; settings = {COMPILER_FLAGS = \"-fno-objc-arc\"; };"
sed -i "" "s|${STR_SRCH};|${STR_RPLC}|g" "$PROJ_FILE"

然后以类似的方式扫描项目文件并删除构建阶段(使用脚本),这样就不会每次都运行它.

Then in a similar manner you scan the project file and remove the build phase (with the script), so it doesn't get run each time.

我将尽快用完整的代码更新此答案.

I will update this answer with complete code soon.

这篇关于Xcode项目模板中的按文件编译器标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆