3

Here is the case I'm faced with when building my mac app.

The project has three targets: target A is comprised of UI src code and produces the final app; target B produces command-line test program that executes some unit tests(I'm not using the auto generated XXXTests target); and target C is comprised of backend src codes, and produces a static library for target A and target B to link to.

The problem is that target B need target C being built with flag "-DZS_TEST", but target A need target C being built without that flag. So, how to set up xcode project/target settings so that I don't have to change any setting when switching from building target A and target B? Because changing build setting causes git reporting unstaged files, which feels unnecessary because I just want to build a different target.

I'm wondering if xcode can forward flag from depending target to depended target then I can let B forward "-DZS_TEST=1" to C and let target A forward "-DZS_TEST=0" to C.

Or is there better way of dividing the project into different targets?

I googled and found many xcode build setting related articles but they don't share the specific need as this project. So thanks in advance.

bestOfSong
  • 81
  • 1
  • 6

2 Answers2

1

I end up using two kernel targets, i.e. target c1, and c2 which use the same source code but different compile flags and c1 build with ZS_TEST defined but c2 not. Then target A and B depend on whichever they need.

bestOfSong
  • 81
  • 1
  • 6
1

What I do is set up a separate configuration, call it "Test", say, as a copy of the standard Debug configuration. Put your additional flags into the Test configuration in Target C, and B if necessary.

Edit the scheme for Target B and have Run build the Test configuration. The configuration gets passed on to the dependencies, so their Test configurations get built and everything should work correctly.

Gamma Draconis
  • 1,166
  • 1
  • 9
  • 11