Xcode 中的嵌套聚合目标似乎无法正确传递设置
我有一个项目,其中有一个主要的 Cocoa 应用程序、一堆插件和几个辅助应用程序。帮助应用程序有自己的目标,并且由于我希望应用程序无需插件即可构建,因此主应用程序有自己的目标(称为 AppTarget),但我通常将其全部构建在聚合目标(称为 TargetA)中。我还有另一个带有 TargetA 的聚合目标、另一个插件和一个额外的复制文件构建阶段 (TargetB)。这一切都按预期进行。我正在尝试创建一个新的聚合目标 TargetC,其中包含 TargetA,并且将具有(但尚未)具有运行 Shell 脚本构建阶段。
我遇到的问题是,我试图使用 GCC_PREPROCESSOR_DEFINITIONS 来 #define 符号 TARGETC 进行条件编译(#ifdef TARGETC ... #endif),但当我查看时,它没有包含在构建参数中在构建日志中,并且应用程序的行为与构建日志匹配 - GCC_PREPROCESSOR_DEFINITIONS 失败(我尝试了 TARGETC 和 TARGETC=1。我尝试添加 OTHER_CFLAGS 用户定义的设置(将其设置为 -DTARGETC=1),但是 文档说聚合目标上的用户定义设置会渗透到其子目标,但似乎这只下降了一级-
TargetA 可能会得到它,但 AppTarget 肯定不会。这是一个错误,预期的行为,还是我做错了什么?
I have a project with one main Cocoa application, a bunch of plugins, and a couple of helper apps. The helper apps have their own targets, and as I want the app build-able without the plugins, the main app has it's own target (call it AppTarget), but I usually build it all in an Aggregate Target (call it TargetA). I also have another Aggregate Target with TargetA, another plugin, and an additional Copy Files Build Phase (TargetB). This all works as expected. I'm trying to create a new Aggregate Target, TargetC, which contains TargetA, and which will have (but doesn't yet) have a Run Shell Script Build Phase.
The problem I'm running into is that I'm trying to use GCC_PREPROCESSOR_DEFINITIONS to #define a symbol, TARGETC, for conditional compilation (#ifdef TARGETC ... #endif), but it's not being included in the build parameters when I look in the build log, and the behavior of the app matches the build log -- the GCC_PREPROCESSOR_DEFINITIONS failed (I tried both TARGETC and TARGETC=1. I tried adding an OTHER_CFLAGS User-Defined Setting (setting it to -DTARGETC=1), but that didn't work either.
The documentation says that User-Defined Settings on Aggregate Targets trickle down to their subtargets, but it seems that this only goes down one level - TargetA may be getting it, but the AppTarget sure isn't. Is this a bug, expected behavior, or am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案:这是预期的行为,而且聚合目标根本不会将其用户设置传递给子目标;要么文档是错误的,要么是我读错了。这似乎违背了将 GCC_PREPROCESSOR_DEFINITIONS 作为可用于聚合目标的默认用户设置的目的,但这就是生活。
为了获得我想要的行为,我正在构建一个单独的插件,该插件将添加到新的聚合目标中。我使用单例来加载插件,它将保存对插件中主类的引用(键入
id
),可以将其返回给任何提出请求的人。如果加载尝试失败(因为插件不存在),它将返回 nil,因此if (nil != [[PluginLoader sharedLoader] plugin])
代替#ifdef目标
。这意味着我无法减少交付代码的大小,但至少它可以工作,而且这不是浪费,因为无论如何我还有其他代码将进入插件(仅针对此目标)。I found the answer: this is expected behavior, and furthermore, aggregate targets don't pass their user settings down to subtargets at all; either the documentation is wrong or I misread it. Which kinda seems to defeat the purpose of having GCC_PREPROCESSOR_DEFINITIONS as a default user setting available for aggregate targets, but c'est la vie.
To get the behavior I wanted, instead I'm building a separate plugin that will be added to the new aggregate target. I'm using a singleton to load the plugin, which will hold a reference to the principal class in the plugin (typed as
id <MyPluginProtocol>
), which can be returned to anyone who asks. If the load attempt fails (because the plugin doesn't exist), it will return nil, soif (nil != [[PluginLoader sharedLoader] plugin])
takes the place of#ifdef TARGETC
. It means I don't get to cut down on shipping code size, but at least it works, and it's not a waste as I have other code that was going to go into a plugin (just for this target) anyway.