Per-File Compiler Flags in Xcode 4

I had written previously (twice) about missing debug symbols and strangeness related to compiler optimization in Xcode. I’d specifically mentioned per-file compiler flags. You may be wondering where they went in Xcode 4. “Ur flagz … let me show you them.”

The “old way” (Xcode 3 and lower) was per-file. That is, no matter the build target, the same source file would use the same per-file compiler flags. In Xcode 4, you have somewhat better control as you’re now allowed to set per-file flags per-target. That is, select your project in the Project Navigator, select the relevant target (you may have only one), then select the Build Phases tab. Expand the Compile Sources phase and viola! A Compiler Flags column lets you set each file’s flags for that target.

It would be nice to be able to further break it down into per-file-per-target-per-build-configuration so we can only apply -funroll-loops and -O3 to targets built for release. That’d save a lot of headaches when you’re suddenly jumping around wildly in the debugger when you enter a for loop.

3 Comments

  1. Many thanks for this: it helped me enormously when integrating some classes that use ARC, and therefore therefor needed the -fobjc-arc flag.

    • Josh (Author)

      Happy to help. I’ve found lots of little gems along the way. The hard thing is remembering to post them. :-)

  2. David Carson

    This sounds like what I’m looking for, but I can’t find anything called the ‘build phases’ tab.

Leave a Comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Back

© Joshua Nozzi. All rights reserved.