xcode xcodebuild - 如何定义预处理器宏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2708380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
xcodebuild - how to define preprocessor macro?
提问by Jaka Jan?ar
How can I define a preprocessor macro when using xcodebuild?
使用 xcodebuild 时如何定义预处理器宏?
I need to build my app using a bunch of different configurations, and I would like to do this using a shell script which runs xcodebuild a number of times with different preprocessor macros.
我需要使用一堆不同的配置来构建我的应用程序,并且我想使用一个 shell 脚本来执行此操作,该脚本使用不同的预处理器宏多次运行 xcodebuild。
采纳答案by kennytm
Cmd + I on the project to open the Info dialog. Then in the "Build" tab, find the "Preprocessor Macros" setting. Add the macros there.
Cmd + I 在项目上打开信息对话框。然后在“构建”选项卡中,找到“预处理器宏”设置。在那里添加宏。
... Where you can find the setting name is GCC_PREPROCESSOR_DEFINITIONS
, so you could add
...您可以在哪里找到设置名称是GCC_PREPROCESSOR_DEFINITIONS
,因此您可以添加
GCC_PREPROCESSOR_DEFINITIONS="foo=bar"
to the xcodebuild arguments.
到 xcodebuild 参数。
回答by lhunath
You pass GCC_PREPROCESSOR_DEFINITIONS
on the xcodebuild
command line.
您传递GCC_PREPROCESSOR_DEFINITIONS
上xcodebuild
的命令行。
Remember that the argument will be re-evaluated for shell-like word splitting and quote handling, so you need to be careful, especially when your macro values aren't just simple 1
s (eg. NSString literals).
请记住,参数将被重新评估以进行类似 shell 的分词和引号处理,因此您需要小心,尤其是当您的宏值不仅仅是简单的1
s(例如 NSString 文字)时。
Also important is to expand the GCC_PREPROCESSOR_DEFINITIONS
inside the value you set (single-quoted, so your script doesn't expand it but the build's shell expands it), otherwise you'll lose your project's build settings for this property.
同样重要的是GCC_PREPROCESSOR_DEFINITIONS
在您设置的值内部展开(单引号,因此您的脚本不会展开它,但构建的外壳会展开它),否则您将丢失此属性的项目构建设置。
The following code puts your defines in a nice bash array and then expands the array in the xcodebuild
command line in a way that shell stuff gets nicely escaped:
以下代码将您的定义放在一个不错的 bash 数组中,然后在xcodebuild
命令行中以一种可以很好地转义 shell 内容的方式扩展该数组:
defines=( TESTING=1 'IWISH_HOST=@"http://192.168.0.101:8080"' )
xcodebuild -verbose -scheme "MyAppScheme" \
GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS '"$(printf '%q ' "${defines[@]}")"