4

I have an Xcode project with many targets. Six of them are aggregates which build final release products (static libraries, frameworks) using Run Scripts under Build Phases. I can build them each individually fine, but I can't find any way to hit "one button" to build them all.

Approach #1

First I tried using -alltargets from the command line, like so:

xcodebuild -project MyProject.xcodeproj -alltargets

With that I get errors on my test targets, claiming that they aren't built for testing. I don't know what that means because they normally "test" correctly. Something is different when attempted this way. But technically it's including targets I'm not interested in. I wouldn't mind much if it worked.

Approach #2

Next I tried making an aggregate which had a run script that individually built each aggregate target, like so:

xcodebuild -project MyProject.xcodeproj -target FirstAggregateTarget
xcodebuild -project MyProject.xcodeproj -target SecondAggregateTarget
xcodebuild -project MyProject.xcodeproj -target ThirdAggregateTarget
xcodebuild -project MyProject.xcodeproj -target FourthAggregateTarget
xcodebuild -project MyProject.xcodeproj -target FifthAggregateTarget
xcodebuild -project MyProject.xcodeproj -target SixthAggregateTarget

It doesn't get any errors from Xcode's point of view, but several of the aggregates just don't build properly. Somehow the run scripts in the individual aggregates were influenced by the top-level aggregate, I guess.

Approach #3

Next I then tried making a new "RELEASE_PRODUCTS" scheme that in the build section had the six aggregates listed. With that I got errors like this:

enter image description here

There were also other obscure errors about build products not being found where they were expected to be.

Approach #4

Next I created a script that I run completely outside of Xcode, like so:

#!/bin/bash

# Builds all release products

xcodebuild -project MyProject.xcodeproj -target FirstAggregateTarget

xcodebuild -project MyProject.xcodeproj -target SecondAggregateTarget

xcodebuild -project MyProject.xcodeproj -target ThirdAggregateTarget

xcodebuild -project MyProject.xcodeproj -target FourthAggregateTarget

xcodebuild -project MyProject.xcodeproj -target FifthAggregateTarget

xcodebuild -project MyProject.xcodeproj -target SixthAggregateTarget

That seems to be the only thing that works. But I wish I could get this to work from within Xcode, preferably as something I could hit from the command line if I wanted to, because then I wouldn't have to leave the IDE and it could report to be success or fail.

Community
  • 1
  • 1
John Bushnell
  • 1,851
  • 22
  • 29

2 Answers2

0

You could make a dummy target that depends on the other six. Use Target Dependencies in the Build Phases tab

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
  • I like how your mind's thinking. I feel that should work too, but it doesn't for me. I get the error "Rm: ... : Directory not empty". I believe the problem must be related to an aggregate having other aggregates with run scripts as dependencies. Something must not work right in that context, because I know dependencies like this certainly work in other cases. – John Bushnell Nov 02 '17 at 18:04
0

Inspired by sansumbrella's answer in another forum.

Create a new target in your project (I chose to use a CLI tool since my project is CLI based).

According to sansumbrella, you can create an application and delete its plist. My approach does not rely on any special (or non-existent) plists.

  1. Give your target a name, such as ALL, satisfy the remaining fields, and press "Finish".

  2. Click on the new target's Build Phases link and:

  3. Delete the entry in the Compile Sources, which will be main.c if you're doing it how I did.

  4. Open the Target Dependencies and add all the other targets by clicking the + or dragging targets into this space.

You can now build and clean your whole project when you have this target selected as the active schema.

shim
  • 9,289
  • 12
  • 69
  • 108
gone
  • 1,079
  • 5
  • 13
  • 31