xcodebuild - how to define preprocessor macro?

老子叫甜甜 提交于 2019-12-29 03:30:47

问题


How can I define a preprocessor macro when using 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.


回答1:


Cmd + I on the project to open the Info dialog. Then in the "Build" tab, find the "Preprocessor Macros" setting. Add the macros there.

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

GCC_PREPROCESSOR_DEFINITIONS="foo=bar"

to the xcodebuild arguments.




回答2:


You pass GCC_PREPROCESSOR_DEFINITIONS on the xcodebuild command line.

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).

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.

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:

defines=( TESTING=1 'IWISH_HOST=@"http://192.168.0.101:8080"' )

xcodebuild -verbose -scheme "MyAppScheme" \
    GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS '"$(printf '%q ' "${defines[@]}")"


来源:https://stackoverflow.com/questions/2708380/xcodebuild-how-to-define-preprocessor-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!