Note that there are some explanatory texts on larger screens.

plurals
  1. POIn an Xcode 4 workspace, how do I cascade build settings & configs to subprojects
    primarykey
    data
    text
    <h1>Overview</h1> <p>I'm using static libraries and Xcode 4 workspaces to effect modularity in iOS development, an increasingly common technique. For example, I might have a workspace which contains an App project, and a Library project, like so<sup>1</sup>:</p> <p><img src="https://i.stack.imgur.com/zUWHA.png" alt="Workspace with App &amp; Library"></p> <p>You would then have a scheme to build these that looked something like this:</p> <p><img src="https://i.stack.imgur.com/L0NKm.png" alt="Scheme"></p> <p>What I would like to do is have the "App build" control the "Library build" it initiates, in at least a couple of ways:</p> <ol> <li><p>Map App configurations (e.g. Debug, AdHoc) to arbitrary Library configurations</p></li> <li><p>Passing through some subset of -D defines, and/or specifying these for the library build.</p></li> </ol> <p>I'll deal with each of these in their own section, but it's worth making a few clarifications.</p> <h1>Clarifications</h1> <ul> <li><p>I'm using App/Library here as an easy proxy for any Superproject/Subproject relationship you may have. </p></li> <li><p>From what I've seen, Xcode 3 style embedded subprojects don't seem to work any differently in Xcode 4 than workspace "peers". I'd love to be wrong about this.</p></li> <li><p>I know I could do almost anything with a "Run Build Script" build phase, and xcodebuild. But I'm trying to work within the system here, where the dependencies are specified in the scheme, and otherwise somewhat loosely coupled.</p></li> <li><p>The Library exists to be used in more than just this project, and so you cannot arbitrarily load it up with junk specific to this App's build, or reference anything particular to the App or Workspace. For the general case, this rules out including static .xcconfig from the App project as a way to convey build information from the App to the Library.</p></li> <li><p>Building the Library outside the workspace sacrifices too much, not an option.</p></li> </ul> <h1>Configuration Mapping</h1> <p>As I understand it, building a particular App configuration will:</p> <ol> <li>If a configuration exists in the Library of the same name, it will build the Library using that.</li> <li>Otherwise, it will build the active configuration of the Library, as specified in the Library's project file.</li> </ol> <p>To my knowledge, without resorting to the aforementioned run-build-script hack, that is the extent of the control one has over subproject build configurations. Please tell me different.</p> <p>Ideally, I would be able to specify (in the scheme, presumably):</p> <pre><code>AppConfigA -&gt; LibConfig1 AppConfigB -&gt; LibConfig2 </code></pre> <p>While Debug, AdHoc, &amp; Release may be the only configurations some ever use, complex projects often outgrow that.</p> <h1>Defines</h1> <p>I've not yet found way to pass -D defines from the App build to the Library, without resorting to xcodebuild, which can take, e.g., an .xcconfig file.</p> <p>The App's build settings can be accessed in Library build run-build-script phase. However, doing that introduces a dependency in the Library on the App project, which for good reason is verboten (cf. Clarifications). But even then, I haven't found a way to use those settings to directly control the Library's build (much<sup>2</sup>).</p> <h2>So crazy it just might...</h2> <p>One scheme I came up with while writing this would be:</p> <ol> <li><p>The Library bases it's build configurations on an empty (dummy) <code>LibraryExternals.xcconfig</code> file within it's own project.</p></li> <li><p>A clean of Library deletes that file. A standalone build of the Library will create an empty one if it does not already exist.</p></li> <li><p>That file is overwritten by an App Build run-build-script phase, and contains anything the app wants to communicate to the Library build.</p></li> </ol> <p>Seems kind of complicated, but I'm looking for anything right now. I'll push this to an answer if nothing better comes along.</p> <hr> <p><sup>1</sup> Apps shown are Max OS X. I find command line apps make for simpler tests. Same applies.</p> <p><sup>2</sup> Cf. Info.plist preprocessing, which I learned about during this investigation.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload