Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specific compiler flags for specific files in Xcode

I've been tasked to work on a project that has some confusing attributes.

The project is of the nature that it won't compile for the iPhone Simulator And the iPhone Device with the same compile settings. I think it has to do with needing to be specifically compiled for x86 or arm6/7 depending on the target platform.

So the project's build settings, when viewed in Xcode's Build Settings view doesn't enable me to set specific compiler flags per specific files. However, the previous developer that worked on this project has somehow declared the line:

CE7FEB5710F09234004DE356 /* MyFile.m in Sources */ = {isa = PBXBuildFile; fileRef = CE7FEB5510F09234004DE356 /* MyFile.m */; settings = {COMPILER_FLAGS = "-fasm-blocks -marm -mfpu=neon"; }; };

Is there any way to do this without editing the project file by hand? I know that editing the project file can result in breaking it completely, so I'd rather not do that, as I obviously don't know as much as the previous developer.

So to clarify, the question is:

The build fails when compiling for simulator unless I remove the -fasm-blocks flag. The build fails when compiling for device unless I add the -fasm-blocks flag. Is there a way to set this flag per file without editing the project file by hand?

like image 920
Jasarien Avatar asked May 04 '10 11:05

Jasarien


People also ask

How do I add compiler flags in Xcode?

You can then add swift compiler flags so that we can check the current configuration through code. To do that, goto Project (not target)→Build settings → Swift Compiler → Custom flags → Other swift flags section and edit the different configuration flags. Add the flags using the syntax “ -D <flag_name>”.

How do I add a flag to my compiler?

Open your project and then go Project > Build Options > Compiler Flags . You can tick boxes in the "Compiler Flags" tab, and you can write other options in the "Other Options" tab. Do one or the other, e.g. don't tick the "-std=c++98" box and also put "-std=c++11" in the Other Options.

What are flags in compilers?

Compiler flags are options you give to gcc when it compiles a file or set of files. You may provide these directly on the command line, or your development tools may generate them when they invoke gcc. This section describes just the flags that are specific to Objective-C.

What does the flag do in compiling?

Compile-time flags are boolean values provided through the compiler via a macro method. They allow to conditionally include or exclude code based on compile time conditions. There are several default flags provided by the compiler with information about compiler options and the target platform.


2 Answers

This blog post by Joshua Nozzi explains how to do this in Xcode 4, where he says:

... 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.

like image 96
Rob VS Avatar answered Nov 10 '22 08:11

Rob VS


You can define additional compiler flags for individual source files as follows:

  • first select the target you are going to build
  • right click on the source file
  • select "Get Info"
  • click on the "Build" tab
  • define your additional compiler flags

However it sounds like a better solution in your case is just to duplicate the target and have two targets - one for an actual device and one for the simulator. Inherit common build settings from the project level and just tweak the per-target build settings as necessary.

like image 34
Paul R Avatar answered Nov 10 '22 08:11

Paul R