According to Hoyle...
firstname.lastname@example.org May 2007
Moving From CodeWarrior to Xcode (Part II)
by Jonathan Hoyle
We continue our discussion of porting CodeWarrior projects into Xcode. Last month, we discussed a number of modifications you can make to your CodeWarrior project to help prepare for porting. This month, we continue by looking at the Xcode side of the equation. If you wish to follow along, you should have both Metrowerks CodeWarrior 9.x and Xcode 2.4.x installed on your system. Although this process will work with some different versions of these compilers, the screen captures and directions I outline will assume these versions.
Whether you are a expert Xcode user being tasked with converting an old Codewarrior project or a long-time CodeWarrior user having to port your project to Xcode, this article is or you.
Configuring Xcode for a more CodeWarrior-Compatible Experience
For those coming from a CodeWarrior background, this section discusses some preference settings to help make your transition to Xcode a bit easier. If you are comfortable with Xcode as is, you may skip to the next section.
Changing applications after nearly a decade's use will entail a bit of discomfort. You will no doubt experience some of this your self with your move to Xcode. These discomforts include a wide range of aspects of this products use; however, many of these can be ameliorated by taking advantage of a few simple preference changes. One common area of cognitive friction comes from having to relearn a new set of menu key equivalents for common tasks, such as Build or Run. Although Xcode does indeed have a different set of command-key equivalents, Xcode does allow you to modify these within the Key Bindings pane of its Preferences. In fact, there is a Metrowerks Compatible key binding set already available for you:
Since my personal tastes are for key binding in earlier versions of CodeWarrior, I create a new key binding set using the CodeWarrior set as the default, but making Command-M for Build, Command-R for Run and Control-R for Debug. As you can see, Xcode allows you the same flexibility for menu key assignments as CodeWarrior does. Other visual differences between these two environments can be diluted by other Xcode preference settings. For example, within the Fonts & Colors pane, you can adjust the Editor Font to Monaco - 9.0 and change the Syntax Coloring for comments to red to match the CodeWarrior defaults, if you wish.
The most fundamental difference in workflow use between these two environments is the window and control layout. Whereas CodeWarrior separates its project, file editors and compiler responses into separate windows, Xcode's default layout is to combine them all into a single window:
Fortunately, Xcode provides the ability to change the layout in its preferences for users coming from other development environments. The Xcode Layout can be found under the Preferences' General pane. The Layout popup menu allows for three settings: Default (the Project Builder layout), Condensed (the CodeWarrior layout), and All-In-One (the Microsoft Visual Studio layout):
This layout is disabled if a project is already open, so close any open windows if you wish to make changes. If you wish to have the CodeWarrior user experience in Xcode, change the Layout option to Condensed, and reopen your project. It will now appear a little more familiar to you:
This Condensed layout is also more useful for developers in a two monitor system, who like to have multiple edit windows viewable simultaneously. Note that this preference is disabled when any projects are open. You must close down all project files to adjust this setting and reopen them afterwards.
Importing a CodeWarrior Project
To illustrate the Xcode conversion process, we will be importing the Appearance Demo.mcp project found on the CodeWarrior 9 Reference CD. If you wish to follow along, you can find this project folder in CW Reference 9.0/(CodeWarrior Examples)/Mac OS Examples/PowerPlant Examples/Appearance Demo/. Double-clicking on the Appearance Demo.mcp file will launch CodeWarrior and present you with the project file window containing two targets:
Those with a long familiarity with CodeWarrior already know this, but the target you will be interested in is Appearance Demo - Carbon. The poorly named Appearance Demo - PPC target is not, as the name might suggest, the only PowerPC target. Both targets compile for PPC; the PPC target is actually a Classic build and should have been named Appearance Demo - Classic. We will concentrate only on the Carbon target, as the Classic target will be unnecessary by Xcode.
Select the Carbon target from the popup menu and build the project. There should be no warnings or errors upon completion; if you do experience build errors, verify that your CodeWarrior installation is complete and your libraries have been fully built. Running the application will present the following window:
You may wish to test out some of the controls to satisfy yourself that the project built properly. When you are finished, quit the CodeWarrior application.
Now it is time to import this project into Xcode. Launch Xcode 2.4 and select Import Project... from the File menu. From Xcode's Import assistant will be presented. Select the Import CodeWarrior Project item and press the Next button:
In this next screen, the importer allows you to choose the project file; select Choose... and navigate to the Appearance Demo.mcp file. Once selected, press the Finished button:
Xcode's Project Importer will launch Codewarrior and begin porting the files. The process will take a few seconds. Upon completion, the file Appearance Demo.xcodeproj will be created:
At this point, it is worth noting that your original CodeWarrior project, Appearance Demo.mcp, is still intact and functioning. That is to say, you will be able to build the Appearance Demo with either CodeWarrior or Xcode or both. This may be useful during the debugging phase of your own project.
As you may recall from the previous section, this project had two targets: Appearance Demo PPC and Appearance Demo Carbon. As it is redundant to have both in Xcode, we will remove the former target. Click on the Targets tab and click on the Targets disclosure triangle to reveal the two targets. Select the Appearance Demo PPC target. Right-Click or Control-Click on this item to reveal a contextual menu and select the Delete menu item:
Once selected, a confirmation sheet will be presented; click on the Delete button. Now you are ready to for the next phase: getting your application to compile.
Building the Project
Select Clean All Targets from the Build menu. Once the clean operation is completed, select Build from the Build menu.
Note: It is vital that you wait until the clean is completely finished before attempting to build; Xcode has a known bug/feature that will cause the clean to stop if a build is attempted in the midst of a clean operation. When the build command has finished, the compiler will tell you that it failed with 17 errors and 1 warning. These errors can be viewed by selecting Build Results from the Build menu:
Next Month: Now that our Appearance project is fully converted over into Xcode, we will fix the build errors, explaining why they are happening, and offer helpful suggestions for similar problems you may encounter for your own projects. See you in 30!