October 2011

Xcode 4: Setting Compiler Flags for a Single File

In Xcode 4 you can set compiler flags for a single file from the target’s Compile Sources build phase.

  1. Select the project file from the project navigator to open the project editor.
  2. Select the target from the left side of the project editor.
  3. Click the Build Phases button at the top of the editor.
  4. Click the disclosure triangle next to the Compile Sources build phase.

Compiler Flags Single File

Select the file where you want to set the compiler flags. Double-click the Compiler Flags column to open a pop-up editor, which is where you enter the flags.

No comments | Trackback

Event Profiler and Counters Instruments

Xcode 4.2 adds two instruments for Mac applications that users of the Shark performance tool will appreciate. The Event Profiler instrument records a sample when a low-level event occurs. The Counters instrument samples your application and collects PMC (Performance Monitor Counter) events. PMC events are low-level CPU events, such as incorrectly predicted branches and cache misses.

Before you trace with the Event Profiler and Counters instruments, you must first configure them. Click the Info button next to the instrument in the instrument list to open a pop-up editor. The pop-up editor is where you configure the instrument. You must tell the Event Profiler instrument the event that triggers sampling. Choose an event from the Event Name menu.

Event Profiler Instrument Configuration

You must specify the PMC events to collect to use the Counters instrument. Click the + button to add an event to the Counters list. Choose an event from the pop-up cell.

Counters Instrument Configuration

When you choose PMC events to collect for the Counters instrument, Instruments shows only a subset of the available PMC events. Choose Window > Manage PM Events to control the PMC events the Counters instrument can collect.

PMC Event Manager

Most of the PMC events are hidden initially. Choose Visible from the State pop-up cell to make that event visible. When you add an event for the Counters instrument to collect, the event you made visible should be one of the choices in the pop-up cell.

No comments | Trackback

Using Makefiles in Xcode 4

Sometimes I read questions from developers who want to use makefiles in Xcode. The short answer to their questions is to create an external build system project. The rest of this article provides a longer answer for those of you using Xcode 4.

Create an External Build System Project

An external build system project uses something besides Xcode to build the project. By using an external build system project you can use another build tool, such as make, ant, CMake, and SCons to build the project. An external build system also lets you use languages Xcode does not directly support. Supply the path to the language’s compiler when creating the project.

Choose File > New > New Project to create a new project. The external build system project is in the Other section under Mac OS X.

External Build System Project Step 1

After selecting the external build system project, click the Next button to move on to the next step. In the next step you name the project and supply the path to the build tool. Xcode is initially configured to use make so you should not have to change the build tool if you’re using a makefile.

External Build System Project Step 2

If you’re running Xcode 4.2 or later you will see the Use Automatic Reference Counting checkbox. This checkbox applies only to Objective-C code. If you’re not using Objective-C, deselect the checkbox.

After naming the project, click the Next button. Choose a location to save the project, and click the Create button to finish creating the project.

Add Files to the Project

Now that you’ve created an external build system project, you must add the makefile and source code files to the project. If you have existing files, choose File > Add Files to ProjectName to add the files to the project. Choose File > New > New File to add a blank file to your project. Xcode does not have a makefile file template. Add an empty file to the project to add a new makefile. The empty file template is in the Other section under Mac OS X.

Configuring the Build Tool

If you need to configure the build tool, use the project editor. Choose the project file from the project navigator on the left side of the project window to open the project editor.

External Build Tool Configuration

Select the target from the target list. Click the Info button at the top of the editor, which you can see in the screenshot.

Build the Project

Click the Run button or use the Product menu to build the project. Xcode builds the project using the makefile. If you chose a different build tool, Xcode uses the tool you specified to build the project.

No comments | Trackback

Xcode 4 Book Available (Electronic Version)

I am happy to announce that a new electronic version of Xcode Tools Sensei is now available. Go to the book’s site to buy it. You can also read the table of contents, introduction, and a sample chapter at the book’s site.

The current version of the book covers Xcode 4.1. I will update the book for Xcode 4.2 when Apple releases it to the public. Anyone who buys the current electronic version of the book is eligible for a free update to the Xcode 4.2 version of the book when it becomes available. On the book’s order form is a checkbox to sign up for the book’s mailing list. If you sign up for the mailing list, you will be notified when the Xcode 4.2 version comes out.

Update: October 11

The store for the ebook was in test mode, which meant you couldn’t buy the book. The store is now active so you should be able to buy the book now. I apologize for the inconvenience.

No comments | Trackback

Xcode 4 Book Should be Ready Next Week

I just finished laying out the last chapter. Now I have to proofread the book and get the website ready for the book launch.

No comments | Trackback

uDevGames Voting Begins

The entries in the Mac game development contest uDevGames are finished and voting has started. The voting ends on October 13 at 11:59 PM GMT, with the winners announced on October 14. If you have a Mac, you can download and play all the entries by going to the following URL:

http://www.udevgames.com/

No comments | Trackback
Powered by WordPress