Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

iphone - xcodebuild - how to define preprocessor macro?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...