Question

I'm currently using xcodebuild to automate testing for iOS.

Right now, I'm stuck on trying to pass compiler flags through Xcode directly to the compiler. These flags are: -fprofile-arcs -ftest-coverage.

I don't have the liberty of modifying the xcodeproj, that's why I want to inject these flags via the xcodebuild command.

It would be something like:

xcodebuild -project path/to/my.xcodeproj -scheme MyApp -fprofile-arcs -ftest-coverage

Is that feasible? How?

Was it helpful?

Solution

Apparently most compiler flags can be expressed as constants, and these can be passed to the compiler via xcodebuild easily.

To get them, simply select the option in the xcode build settings view, and hit command-C (copy). In my case, they were GCC_GENERATE_TEST_COVERAGE_FILES and GCC_INSTRUMENT_PROGRAM_FLOW_ARCS.

My command roughly looks like this:

xcodebuild GCC_GENERATE_TEST_COVERAGE_FILES=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES ...

OTHER TIPS

To set compiler flags with xcodebuild, you need to put them in the OTHERCFLAGS option.

For example:

xcodebuild -project path/to/my.xcodeproj -scheme MyApp \
    OTHERCFLAGS="-fprofile-arcs -ftest-coverage"

Yes, all of the compiler setting actually boils down to string key-value pairs. I answered a very similar question about setting preprocessor macros from the command line that is just as applicable to these settings you would like to set:

Setting a #define from the command line in xcode 4.6

I would also like to call attention to the use of ${inherited} -- using this values allows you to use the Xcode project-specified values AND append your own. Documentation for each of the build settings including those that you located via copy-paste can be found here:

http://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html

Glad you were able to get it to work -- now you can really make xcodebuild do even more for you without requiring changes of the target Xcode project!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top