How to differentiate multiple targets with Xcode 4.2 - xcode

I've developed a lite version of an app. Now I want to create a paid version.
So I've duplicated the target, changed its name (so change plist and other stuff with that name) and now I have to differentiate in code. I'm using Xcode 4.2 and I see on the web that I have to create a preprocessor flag. My problem is that this flag in Xcode 4.2 is only in the project's build setting and not in the target's build setting.
I will need to be able to do something like this:
#ifdef paid
...
#else
...
#endif

Use preprocessor macros to do this.
Go to Target -> Build Setting and choose "All configurations" (this is very important).
Next find field "Preprocessor Macros".
In this field, add the flag in ex. PAID_VERSION. Now you can use this flag in code:
#ifdef PAID_VERSION
NSLog(#"Paid version");
#else
NSLog(#"Lite version");
#endif

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.

Validate Project Settings won't go away in XCode 4.4.1

I am trying to get the Second Life Open Source Viewer to succeed compiling on 10.8.1 with XCode 4.4.1. I have managed to get it to run a few times but after cleaning my build folder, now the "Validate Project Settings" warning keeps popping up, telling me that I should change the compiler to the recommended one, Apple LLVM 4.0. However there are many compiler flags in my project that are incompatible with Clang. I must use GCC 4.2. So I uncheck all boxes and click Done, but then when I try to build again, I keep getting the same "Validate Project Settings" warning.
I think the only way I got it to go away before was by accepting it, letting it make all its changes, then reverting to the snapshot it makes before doing the changes. However this is a very time-consuming work-around, since creating the snapshot takes forever.
I was trying to find an option to "ignore compiler version" orĀ "don't validate project settings" but I couldn't find any such option. Can someone help?
Set 'LastUpgradeCheck = 0440;' at pbxproj and also 'LastUpgradeVersion = "0440"' for each xcscheme in your project.
To be precise:
1. open your project.pbxproj with some text editor (e.g. XCode) and find the next block:
/* Begin PBXProject section */
<somehash> /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0440;
};
...
};
/* End PBXProject section */
Make sure LastUpgradeCheck is set to latest version (0440). It should look like:
<Scheme
LastUpgradeVersion = "0440"
version = "1.3">
2.open your *.xcscheme with some text editor and for the root element Scheme make sure its attribute LastUpgradeVersion is set to "0440" value.
Repeat for all projects in your workspace (Find&Replace, regexp and other batch edit tools may be useful).
If it doesn't help, you can try to validate project settings with Xcode, check diff with original project and scheme and manually revert options you care about, leaving aside all the others. Do it for one project and check if it helps. On success - make the same changes for all the other projects&schemes. This is the way I figured out the previous solution and it works for me just fine.
VCS with a fine diff tool would help a lot.

precompiled header name gets stuck

I'm new to xcode and I must be missing something.
Create a new command-line project. Call it tempprog (for instance).
Select Project/Edit Project Settings.
Edit the name of the prefix header (tempprog_Prefixz.pch).
Build - it will fail, of course, looking for tempprog_Prefixz.pch
Now change the name of the prefix header back to tempprog_Prefix.pch.
Build again - it should work, but doesn't. It's still looking for tempprog_Prefixz.pch
Cleaning does not rectify the situation. What am I missing here? Where is the Prefixz.pch name being retained? If you look in the build output at the ProcessPCH command you can see that it still wants to use Prefixz.
It turns out there's a system of setting priorities.
From Working With Xcode Build Settings:
The levels at which build settings can be set, and their precedences are:
xcodebuild command-line flags (only applicable for command-line builds)
The target, editable via a target's Info inspector
The project, editable via a project's Info inspector
Xcode application settings, as set in Xcode > Preferences...
Xcode's built in defaults
The user environment, perhaps as set in a user's ~/.MacOSX/environment.plist file
Restarting your mac fixes the problem.

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