Search code examples
xcodexcode4xcodebuild

Xcode how to use multiple targets, all with same everything except PCH and info plist file


We want to have multiple build targets where the only difference is either the PCH file or a preprocessor macro setting. (either way will allow us to vary preprocessor directives depending on which target we have.)

We don't want to have to maintain several separate lists of Source files, Bundle Resources, Linked Libraries, etc, that are included.

Basically we want to have this:

  • MyApp (basetarget)
  • MyAppDev (overrides "MyApp" but with different pch/preprocessor macros)
  • MyAppQA (override as well)
  • MyAppProduction (override as well)

And we want it so we just add all our source files to "MyApp" and have a base list of preprocessor macros, plus some that are specific for each build.

Then we will have schemes that correspond and build each target:

  • MyAppDevScheme
  • MyAppQAScheme
  • MyAppProductionScheme

Is this possible with Xcode?

We would also want to use the xcodebuild command line tool in conjunction with this but that should be easy if we can do what I've described above.

I will be delighted if someone can explain this!

Thanks!!


Solution

  • Try this:

    In your project settings (Info), duplicate Release or Debug build configuration. Then adjust build settings for your target, adding different preprocessor vars, or adjusting PCH file name.

    After that you can create a Scheme for each of the configurations, so you can easily build the target you want.

    And for xcodebuild builds, just specify either -configuration or -scheme as you like.

    It's pretty much the same way Apple recommends building for app store.