Can you batch change per-file compiler flags in Xcode 4? - xcode

I'd like to be able to change compiler flags for a whole set of files.
When accessing per-file compiler flags from the "Build Phases" area you can change flags one at a time, however say I'd like to change the flags for every file in a group (e.g., the DropBox or Facebook SDK).
Anyone know how to do this in Xcode 4.0.x?

Fortunately, YES :-)
In Targets->Build Phaes->Compile Sources, mark all the files you like to set a compiler flag for, press RETURN (hit the enter key!), put the flag in the upcoming window and you're done!

Related

Per file compiler flags in Xcode 8.1

I need to add some specific compiler flags only for certain files in my project. I did some googling and found out that this used to be possible in the file inspector in older Xcode versions. I'm on Xcode 8.1, however, and I can't seem to find where I can add custom compiler flags for certain files.
Could anybody please tell me how this is possible with Xcode 8.1?
Go to the navigation bar of your project
Click on your project
Click on the target you want to modify
Click on Build Phases
Look for the file you want to add the compiler flag in the Compile Sources list; in this list you should see two columns: name and compiler flags
Click on the latter column and a popup window should come up; add the compiler flags to that specific file

XCode 4 - Release Mode Flags, Build Flags, Link Flags

I'm working with XCode 4.6 on MAC OS X 10.8.
I'm new to this IDE and platform.
I have a project I compile and optimizations are turned off by XCode.
It doesn't matter if I set Release Scheme.
I saw at the thread named "Cannot Disable Debugger with XCode 4.5" that it has to do with the flags '-O0' and '-Os'.
I know that some flag set "Debugging Mode" which means no optimization is done and more data is generated by the code to help debugging.
I just can't find the single parameter which controls this behavior in XCode (Like /Mtd in VS).
Which parameter in the XCode options controls this parameter?
Moreover, In VS it is easy to see the build parameters as a command line (Under options, both Linker, and Build).
Where can I see that in XCode?
Thanks.
All the compiler and linker flags can be found within a project's or a target's "Build Settings" (targets can overwrite their projects' settings). To get there, select the project file, then select your current target, and go to "Build Settings". Select "All" and "Levels" at the top to display all available options and where they are set (project or target -- left-most wins).
The options are grouped, e.g., linker options and compiler options, and most of them refer to flags. Xcode shows a descriptive name rather than the full flag name. To see the latter, select the line of interest and select the "Quick Help Inspector" in the right panel ("Utilities" panel). The flag you seem to look for is called "Optimization Level" in Xcode.
You can set each option's value, and Xcode may display some meta information next to the raw value, e.g., "Fastest, Smallest" for -Os, or "None" for -O0. You can set all options for each configuration (by default, Release and Debug) independently. Which configuration is actually used depends on your build action. If you build & run, Debug is used by default. If you archive an application, Release is used by default. However, you can change most of that by editing the schemes.
Update:
To get an idea of the differences between the Release and Debug configuration, look at the "Build Settings" of a given target. If an option's value differs in both configurations (or any other configuration you may have), there's an arrow in front of the option's name which indicates the differing values. E.g., take the "Build Active Architecures Only" setting. In debug mode, it assumes you build for a particular testing device so there's no need to include code generated for other platforms as well. However, if you build your app for distribution, you want to build one app that includes code for all target devices/hardware architectures.
Other options to look into:
-Debug Information Format: The way debug information (crash reports) are stored. In Release mode, this is set to "DWARF with dSym", which means that your crash reports are encrypted so no one else can get meaningful information (symbol names) out of them.
-Strip Debug Symbols During Copy
-Optimization Level, as mentioned above
-Preprocessor Macros: This allows you to make your code (statically) dependent on the build configuration, e.g., to log only in Debug mode
Xcode provides more (and probably more accurate) information on all these options in the above-mentioned "Quick Help Inspector", just select any option.
From my experience, despite the optimisation, Release builds are often faster (i.e., they build faster) and definitely smaller in size.

How can I enable Xcode refactor options for an external build project?

I want to use XCode as an IDE for developing some AVR code. I did the following
1) create new project
2) select external build system
3) indicated i want it to be make, and told it NOT to "Pass build settings in environment"
4) copied my .c/.h/Makefile into the same directory i created the project in
5) added the .c/.h files to the project/target
6) verified that i can build (make) from both command line and Xcode
But I cannot use any of the refactor menu options, or jump to/reveal options. There appears to be no symbol information. Is there no way to use Xcode as more than just a simple C editor that uses an external build system????
If not, it's a bust for embedded development. Please tell me I'm wrong :(
I found a workaround/solution. Create a second target called "Dummy" or something like that, that is based on the Command Line Tool template of type C. Select all the .c files and in the "Targets" pane on the left side bar, check the new Dummy project (or if the options change, as they seem to often, do whatever gestures necessary to make Dummy depend on your C files).
It will create a Dummy directory and a couple of other Dummy files which you can remove if you want. You never bother building 'Dummy', in fact, if it's an embedded project with separate toolchain, likelihood is nearly 100% that it won't compile as a Command Line Tool for OSX anyway. :)
Apparently XCode needs this indirect hint to know that your .c files are indeed real C files and can be parsed/introspected as such.
As you add new .c files which your external build system likely see automatically, make sure you include them as a dependent for the Dummy target.
I was able to get this to work using XCode 6.1. In my case I'm using C++ but it should also work with C as some of my C++ files make C function calls. Here's what I did:
Create a dummy target using: File->New->Target
For the template choose: OS X->Application->Command Line Tool
Click Next
Fill out the Product Name, etc.
Select C++ for the Language field.
Click Finish.
Back in the Project Navigator pane:
Right click on the new 'dummy' target
Select: Add files to 'your project name'
Browse to select your directories/files to add.
Once the files were added to the Dummy target, I could then open a file under my normal target, right click on a method and Refactor, Jump To Definition, etc.

How to disable Xcode4.2 Automatic Reference Counting

Today, I have update my xCode to 4.2 version, And I want to disable the ARC, I also search with the google. but can't fix my problem. According the search results, In the target setting, I can't find the 'Objective-C Automatic reference counting' item, So have no chance to set it to NO. I find the item one by one, and also use the search field.
And one know the newest Xcode4.2 ,how to disable the ARC for the project, not for the specific file.
Thanks very much.
Click on you project, in the left hand organizer.
Select your target, in the next column over.
Select the Build Settings tab at the top.
Scroll down to "Objective-C Automatic Reference Counting" (it may be listed as "CLANG_ENABLE_OBJC_ARC" under the User-Defined settings group),
and set it to NO.
This is on Xcode 4.2 (Build 4D199).
In Xcode 4.2 beta, there were 2 places per target that you could toggle the use of ARC... now there seems to be NONE.
Also, the "Convert to ARC" menu item seems to have disappeared.
Now, yes, I suppose that the ARC stuff was never meant for Mac Developers, as 4.2 beta was iOS only, but not exactly sure what Mac developers who did play with the ARC stuff in their Mac Apps are supposed to do now....
File Radar Reports. Wait for 4.3? redo the app? Edit the .xcode XML manually? Not sure.
Disable ARC or enable MRC
You should operate by C flags
//enable ARC
-fobjc-arc
//disable ARC
-fno-objc-arc
You have three options:
Local - Compile Sources
Global - OTHER_CFLAGS
Global - CLANG_ENABLE_OBJC_ARC
[Under the hood]

Xcode: Is there a location/flag to prevent a Class from compiling?

Is there a place (or flag) in Xcode for files that you don't want to compile? There are some classes that are/may become part of a project but currently won't compile. The main project doesn't link to them but Xcode still tries to compile them. Is there a way to prevent blocking the rest of project from compiling until these new Classes are "ready"?
Note that for every source file you can specify which target(s) it belongs to - look at the inspector window for a file (Get Info) and then hit the Targets tab. If you deselect a target for a given source file then it won't be compiled as part of the build process for that target.
[This amounts to much the same thing as what Eimantas has said in his answer - it's just a different way of looking at it.]
Look for unneeded files in "Compile sources" in Target -> {AppName} branch. Remove them from there and they won't be compiled on next build (make sure to Clean before you Build again)
In Xcode 8.3.3, in the utilities window, click on File Inspector tab at the top of the window. Uncheck the file in the Target Membership area of the File Inspector. Please see image below.
You can use preprocessor statements:
#ifndef HIDE_<insert name here>
CODE
#endif
And then use:
#define HIDE_<insert name here>
above the aforementioned code in the files you don't want to compile.

Resources