创建 Xcode 项目的自定义构建
我将使用 Xcode 构建一个用 Obj-C 编写的 Mac 应用程序。为了便于论证,我们假设它将有 10 个可选功能。我需要一种方法来启用或禁用这些功能来创建应用程序的自定义版本。这些构建将是自动化的(最有可能通过 Mac OS X 终端),因此我需要一种方法来说明在构建时启用/禁用哪些功能(配置文件或 CLI 参数将是理想的。)
那么什么是实现这一目标的最佳方法是什么?我试图在开始编码之前对此进行计划,以便在我的代码库中进行适当的分离,以允许这些功能来来去去。理想情况下,自定义构建仅包含其应具有的功能的编译代码。换句话说,我不想总是编译所有功能并在运行时调整它们。
I am going to build a Mac application written in Obj-C with Xcode. For argument's sake let's say it will have 10 optional features. I need a way to enable or disable those features to create custom builds of the application. These builds would be automated (most likely through the Mac OS X Terminal) so I would need a way to state which of these features are enabled/disabled at build time (a configuration file or CLI arguments would be ideal.)
So what is the best way to accomplish this? I'm trying to plan this out before I start coding so that there is proper separation in my code base to allow for these features to come and go. Ideally the custom build would only contain compiled code for the features it should have. In other words I don't want to always compile all the features and condition them out at runtime.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Xcode 配置来实现此目的;例如,对于每个配置,您可以包含不同的前缀标头。然后您可以通过 xcodebuild 从命令行触发构建。
如果您更喜欢配置文件方法,则可以使用 .xcconfig 文件来定义任何 Xcode 构建设置。
Xcode 构建系统指南描述 这两种方法。
You can use Xcode configurations for this purpose; for each configuration you could include a different prefix header, for example. Then you can trigger builds form the command line via
xcodebuild
.If you'd prefer the config file approach, you can use a .xcconfig file instead to define any of the Xcode build settings.
The Xcode Build System Guide describes both of these approaches.
使用 #ifdef 和编译器标志下的 -D 标志来控制是否编译内容。如果您愿意,您可以通过这种方式设置许多不同的配置,并且让 xcode 构建配置正常工作。
输出 1:
输出 2:
来源:http://www.network-theory .co.uk/docs/gccintro/gccintro_34.html
use #ifdef and the -D flag under the compiler flags to control whether stuff is compiled in or out. You can set up lots of different configs this way if you want, and just have the xcode build configurations work nicely.
output 1:
output 2:
source: http://www.network-theory.co.uk/docs/gccintro/gccintro_34.html