如何定义预处理器宏?

时间:2022-10-12 16:53:35

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多次。

2 个解决方案

#1


19  

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在项目上打开信息对话框。然后在“Build”选项卡中,找到“预处理器宏”设置。添加宏。

... Where you can find the setting name is GCC_PREPROCESSOR_DEFINITIONS, so you could add

…在哪里可以找到设置名gcc_preprocessor_definition,以便添加

GCC_PREPROCESSOR_DEFINITIONS="foo=bar"

to the xcodebuild arguments.

xcodebuild参数。

#2


31  

You pass GCC_PREPROCESSOR_DEFINITIONS on the xcodebuild command line.

在xcodebuild命令行上传递gcc_preprocessor_definition。

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 1s (eg. NSString literals).

记住,参数将被重新评估为shell式的单词拆分和引号处理,所以您需要小心,特别是当您的宏值不仅仅是简单的1时(例如)。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_definition展开到您设置的值中(单引号,因此您的脚本不会展开它,但是构建的shell会展开它),否则您将丢失项目对该属性的构建设置。

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[@]}")"

#1


19  

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在项目上打开信息对话框。然后在“Build”选项卡中,找到“预处理器宏”设置。添加宏。

... Where you can find the setting name is GCC_PREPROCESSOR_DEFINITIONS, so you could add

…在哪里可以找到设置名gcc_preprocessor_definition,以便添加

GCC_PREPROCESSOR_DEFINITIONS="foo=bar"

to the xcodebuild arguments.

xcodebuild参数。

#2


31  

You pass GCC_PREPROCESSOR_DEFINITIONS on the xcodebuild command line.

在xcodebuild命令行上传递gcc_preprocessor_definition。

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 1s (eg. NSString literals).

记住,参数将被重新评估为shell式的单词拆分和引号处理,所以您需要小心,特别是当您的宏值不仅仅是简单的1时(例如)。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_definition展开到您设置的值中(单引号,因此您的脚本不会展开它,但是构建的shell会展开它),否则您将丢失项目对该属性的构建设置。

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[@]}")"