This is the first part of a tutorial in which I’d like to introduce you to one of my favorite open-source projects, The Cocotron (imagine the ominous silence of a Soviet nuclear reactor as the backdrop for pronouncing this name).
Cocotron lets you take a Cocoa-based Mac app and port it to Windows without ever leaving Xcode — just add a Windows target to your project and you’re set. Sounds too good to be true? Well, as usual, some limitations apply. Cocoa is a large and rapidly evolving framework, and it would be very difficult for a loose team of open-source volunteers to achieve 100% compatibility with Apple’s latest and greatest. But Cocotron can take you most of the way, and if you have the possibility to plan ahead for compatibility, the odds of being able to make use of Cocotron are further increased.
The Cocotron is not just a vapor framework outlining some kind of theoretical feasibility: it’s been publicly available since late 2006, and ports accomplished using Cocotron are out in the wild. Personally I have used it deploy Mac-developed custom apps on Windows, including a fairly complex GUI subtitling tool used by the Finnish Broadcasting Company for a popular TV game show. (Based on activity in the Cocotron mailing list, there is also a company with a well-known consumer-oriented Mac product who are nearing completion of a Windows port using Cocotron.)
Something that appeals to me in Cocotron is its strict, almost austere “no-frills” policy. Christopher Lloyd, the project’s initiator, runs a tight ship. Unlike some other cross-platform toolkits (* cough Gtk+ and Qt *), the framework is lean: Cocotron’s Windows DLLs for Foundation and AppKit only take about 6-7 MB. And it’s self-contained – there are no other dependencies by default. As fits this culture of independence, Cocotron is MIT-licensed, so you can basically do anything you please with the code as long as credit is given.
True cross-compiling on the Mac is a core part of Cocotron’s promise. As such, its fortunes are closely tied to Apple’s Xcode development environment which has undergone a lot of changes over the past five years. Luckily Xcode has consistently remained open enough to allow custom cross-compilers (perhaps largely thanks to the advent of iOS and Cocoa Touch on ARM CPUs, which has made cross-compiling an essential part of Xcode).
Xcode 4 was the biggest change in the product’s history. I had been long dreading making the leap to Xcode 4 for two reasons: the new UI would force me to re-learn many workflows, and I was worried that Cocotron might not work properly anymore. Now it has been a week since I finally made the change, and I can report that I’m pretty happy about it. That means you could be happy too with Cocotron and Xcode 4.3! This tutorial will tell you how.