Xcode workspaces with sub-projects and project dependencies triggering builds

38,912

Solution 1

This solution was intended for another problem, but maybe it fills your needs.

After adding your subproject to the workspace:

  1. Select the Target which should use the newly added subproject
  2. In "Link Binaries with Libraries" under Build Phases hit the + button
  3. If the Library does´t show up hit "Add Other..."
  4. Navigate to the Folder where the project file (*.xcodeproj) lies
  5. Mark it and hit "Open"
  6. Now you should see the Project File show up under "Link Binaries with Libraries"
  7. Under "Target Dependencies" in the same tab, hit the + button
  8. Now you should see the necessary files
  9. Check yours and hit "Add"
  10. Again in the "Link Binaries with Libraries" hit the + button
  11. Now your .a file should show up and you can choose and add it

Now you are using the chosen library for your target. Repeat those steps for every target which needs this subproject. Hope that helps! For me it did because i could not manage to add dependencies to it before...

Greetz, Tomte

Solution 2

Just in case somebody else is having problems with this in Xcode 7: Make sure the project you want to add as subproject it's not open, before you add it or drop it.

Solution 3

In Xcode 5 you have to:

  • Select the project on the left tab
  • Choose the target in the TARGETS section
  • Then in Build Phases > Target Dependencies press "+"
  • Choose the added project as target it will appear in the Target Dependencies list

If it works, when building all target dependencies will be build together if needed.

Solution 4

You could create a scheme that builds all targets.

Solution 5

This is derived from Tomte's answer. His approach was causing me a Dependency Analysis Error. This is a more straight forward approach and explains why Tomte's answer works:

  1. Click on the sub-project and drag it into the project that needs to target the sub-project.
  2. The options alert should now be displayed. Make sure Copy items if needed is not selected. Make sure Create groups is selected. Make sure none of the project's targets are selected. Press the Finish button.
  3. Click on the project that you just added the sub-project reference to.
  4. Click on the target that you want to have a dependency on the sub-project.
  5. Click the Target Dependecies + button.
  6. Notice the sub-project's product is listed as an option. Select it.

Note that when using Tomte's approach, when the project is added to Link Binary With Libraries, a project reference is created. This project reference can be found in the Frameworks group of the project.

I'm conflicted as to whether this is a good approach or not. The scheme approach is not much better, in my opinion. I'm actually wondering why workspace project's don't have this relationship by default.

At the very least, this should clear up the magic in Tomte's solution.

Share:
38,912
Jay
Author by

Jay

Dude who loves the happy C family of languages (Objective-C, C++, C#) on many platforms.. Building the house modeler @houzeModeller

Updated on July 09, 2022

Comments

  • Jay
    Jay almost 2 years

    I wish there was better documentation for this for Xcode 5 but I couldn't find anything decent describing best practices for working with workspaces, so..

    In a workspace with several projects (couple frameworks, 1 app) is it possible to have Xcode build all dependent projects only when required (i.e. changes found) w/o having to include all projects in all dependent projects?

    I'd rather like to just have the frameworks in the project depending on it instead of having 5-6 sub projects in it as this is just a mess in the Navigation View -
    files inside sub-projects show up in search results all the time, sub-projects in the NavView expand for whatever reason within projects..

    However, w/o including projects a particular project depends on I couldn't find a way to have Xcode 5 re-build the frameworks automatically if one of the dependencies has changed.