Re: adding an OS X target to an iPhone project
Re: adding an OS X target to an iPhone project
- Subject: Re: adding an OS X target to an iPhone project
- From: Jocelyn Houle <email@hidden>
- Date: Thu, 10 Dec 2009 12:13:38 -0500
Let me offer a different stance...
I've faced the same choice (split Cocoa and CocoaTouch targets into separate Xcode project files or not), and I eventually decided to have the same project contain both targets. Disclaimer: there are a few caveats, but also a few advantages. I'll try to summarize both here.
In our environment, we have half a dozen libraries being linked into the final executable. Although some libraries incrementally make use of one another, we like to view each as a separate "project" in itself. In such a context, we like having a single Xcode project file for each component, each containing all of the targets for that component (shared library, static library, cli regression test executable, and sometimes GUI application).
Having separate Xcode project files for Cocoa and CocoaTouch would double the amount of work we need to do every time we add/remove/rename source files. Xcode's "Details" panel is quite useful here, as we only need to add files once in the project file, and use the checkbox to decide which files are compiled for which target. Using folder *references* might have avoided needing to do anything in the common case (Xcode automatically detects new files), but that only works if we compile all of the directory's content, and that isn't always our case (namely, when doing aggressive refactoring which disables some functionality for a few weeks).
As James Bucanek states, there are many settings which are different between iPhone and Mac OS X targets. But the opposite is quite true as well: many settings are actually shared as well. In fact, I've found that most of the settings I wanted to specify were actually shared across all targets (warnings, optimizations, rtti, exceptions, include paths, etc.). On that front, effective use of .xcconfig files proved quite effective to allow sharing settings across Xcode project files (albeit, with a few gotchas).
All of the argument about sharing source code and build directories is moot: sharing the same project files give you that implicitly. Same thing goes for using cross-project dependencies.
That said, I wouldn't dare say merging Cocoa and CocoaTouch targets in the same Xcode project file is a panacea. It has some shortcomings.
Namely, switching between Cocoa and CocoaTouch targets makes Xcode change SDK, and has others have noticed, this operation is a bit brittle in Xcode. Whenever you do so, Xcode will likely burp with a gcc tool error (it'll try to use the compiler from the previously-selected target, which is for the wrong platform). This seems to happen when you use the Base SDK (SDKROOT="" in the .xcconfig files). Changing your target *AND* its SDK to a specific one usually solves the issue. Otherwise, closing and reopening the project file always fixed it for me... so far (strong hint that this is an Xcode issue, one which I hope will eventually get fixed).
Also, as your revision control system will sometimes report, some SDKs will store comments using a different name (some SDKs use the product name, while others use the target name). These are only in comments (delimited by /*...*/), but it can get annoying at time. Closing a project after always selecting the same SDK (iPhone vs. Mac OS X) works around this, but it is an annoyance...
So, in the end, I guess you need to pick your poison...
Either path will have pros and cons; it's a matter of personal taste, to some extent...
On 2009-12-10, at 11:08, James Bucanek wrote:
> Roland King <mailto:email@hidden> wrote (Thursday, December 10, 2009 11:48 PM +0800):
>
>> Should I even be really doing this? Is trying to add an OSX app to the same
>> project as an iPhone one just asking for pain and misery because there is
>> basic configuration information baked in which says 'this is an iPhone app' or
>> 'this is a Cocoa app'? I could just make a brand new project, keep the few
>> common files in a single directory and reference them without copying, but I
>> always thought it should/would/could be easy to add nicely totally independent
>> targets and executables to the same project and have one nice codebase you
>> just compile different targets with.
>
> I would suggest that these should be two projects. There are scores of build settings and other aspects of an iPhone and Mac OS X project that are fundamentally different. Trying to mix them in the same project seems like a recipe for disaster--which you've already discovered.
>
> Here's how I'd do it:
>
> 1) Create a second Mac OS X project. Close it.
>
> 2) Move the project document from the new OS X project folder (and any other source files) into the project folder of your iPhone project.
>
> You now have two (!) project documents sharing the same project folder. This has a number of advantages:
>
> - They can share the same source files, and all source files are contained in the project folder.
>
> - They can/will share the same build folder so you can reference target products from one project in the other.
>
> - Each has a completely independent set of build settings, configurations, and active target settings.
>
> - You can add one project to the other project as a source item. Once you do that, you can make cross-project target dependencies so that targets in on project automatically build targets in the other project.
>
> The only things you really have to worry about are:
>
> - Be careful of conflicting product names. Two products with the same name sharing the same build folder will overwrite each other. I'm not sure about module names, but it's worth checking out. You might need to do some fiddling with the build settings so that intermediate files for one project are written to a (slightly) different location in the build folder.
>
> - If there are two or more project documents a the project folder, you must explicitly tell the xcodebuild tool which project document to build.
>
>
>
> James Bucanek
> ____________________________________________________________________
> Author of Beginning Xcode ISBN: 047175479X
> <http://www.beginningxcode.com/>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Xcode-users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden