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

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.

Related

xcode product packaging Metallink

I have an xcode project which generates *.metal shaders using a custom build rule.
Somehow xcode tried to automatically compile these generated shaders during the "Process product packaging" build step.
This fails, as these shaders are not meant to be compiled at that point. Is there a way to exclude the build rule outputs from building? If i remove the build rule inputs files from the "Copy Bundle Resources" list, the rule does not get called.
Adding the metal extension to the "Excluded Source File Names" also doesnt help.
I kinda have a solution for you, but it's not perfect.
Open your project in Xcode. Select the .metal file that's giving you trouble. If you go into File Inspector (View -> Inspectors -> File). There you can either uncheck all the targets under Target Membership so that Xcode doesn't try to build it at all. Or you can also try and change it's Type to like a text file or something.

Is there a way to build selective files in Xcode?

Is there any way that I can select some files only build selective files and make the build ignore some files in a project?
What compiler flags or Xcode options do I need to use?
In Xcode, show the project navigator (Cmd-1), click the file you want to remove from the current build. Show the file inspector (Cmd-Opt-1), locate "Target Membership" pane and uncheck the current target. Just check it to add it back.
You can do the same in the target "Compile Sources" phase but you'll need more clicks and if you have a few dozen files you'll need to search it in the list.
The fastest way to stop building temporarily a few lines that you know are wrong or incomplete is to wrap them with
#if 0
// code you want to skip
#endif
Also, if you want to run some experiments you can add a new target that includes those experimental files and add an scheme to build the experiment.
It would be much better if you use git and create an experimental branch, but that's a different story.
In the project settings, in Build Settings you can add and remove individual files. However, there is no way to only build some files and not others; you are building all the files in the project.

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.

Xcode easily add multiple files to a target

I've created a new target for unit tests in Xcode 4.2, and obviously i need to bring in certain application files into that target. But there is a lot, and it seems cumbersome to click each .m file then click TargetMembership and tick the new target box.
Is there an easier way to do this in Xcode that i'm missing?
Thanks
I though't i'd return to this with an improved answer. It's still difficult to do this via Xcode main interface, as if you filter for .m and try and do CMD-A to select all, it selects the folders too, so you can't add these to the target.
However, if you go to Project Settings > Build Phases > Compile Sources. You can click the + button, filter .m files, and you can CMD-A to select all here.
This works.
If the files are all in a single directory, delete the directory from the project (remove reference only), then re-add it. Xcode will ask you which targets you want the files to be added to when you re-add it.
Select all the .m files in the "Project Editor" (cmd-1), show the "Utilities View" (opt-cmd-0) and click the new target in "Target Membership". Be careful not to select files that do not belong to a project such as .h files.
create a static or dynamic library, to which both executables link.
If you duplicate and existing target instead of creating a new one from scratch, all the existing files will be a member of the new(duplicated) target as well.
In 2016 you can now use both an AppTest and LogicTest target so you don't have to fiddle around with target settings.
You don't need to add any files to the AppTest target since it will have access to all main target files, and put pure logic tests in LogicTest.
In Xcode 10
You can also select multiple files in Project navigator and then, in the "Inspectors" right side pane you can modify Target Membership:

Three20 v1.1 and Xcode 4

Is there an easy way of getting Three20 v1.1 to work under xCode 4?
I followed the steps on http://three20.info/article/2011-03-10-Xcode4-Support but that seems to be for the master. I use v1.1 as I use the TTLauncher.
The project builds fine with a normal build, and runs perfect on an iPhone.
But when I want to create the archive (for the IPA for distribution) then I get 18 errors and 8 warnings.
The first one is:
../scripts/Protect.command: line 23: cd: /Users/XXX/Library/Developer/Xcode/DerivedData/iDoms-cmyivarwxpbvqdfnyclqdrikrtmw/ArchiveIntermediates/iDoms/BuildProductsPath/Release-iphoneos/../three20/Three20UICommon: No such file or directory
Most others are 'no such file or directory' on e.g.:
#import "Three20Core/TTGlobalCoreLocale.h"
or 'undeclared (first use of function)' which comes from the 'no such file or directory issue I presume'.
In my 'Header search paths' I have:
$(BUILT_PRODUCTS_DIR)/../three20
$(BUILT_PRODUCTS_DIR)/../../three20
../../three20/Build/Products/three20
/usr/include/libxml2
Any help would be very appreciated!
Just to add to Colin's answer: you can use Xcode's dependent projects feature to use three20, even though the three20 website says it's not "officially supported":
In your workspace, right-click on the empty space in your project navigator. Select "Add files to "My Workspace", and select the three20 project (three20/src/Three20/Three20.xcodeproj). This is the only project you need to add: it is not necessary to manually add the three20 subprojects.
Select your project in the navigator, go to Build Phases, open "Link binary with libraries", click on the "+" in the bottom left corner, and add the Three20 libraries: libThree20.a, libThree20Core.a, libThree20Network.a, libThree20Style.a, libThree20UI.a, libThree20UICommon.a and libThree20Navigator.a. This will cause Xcode to build Three20 when you build your project.
Add ${BUILD_DIR}/three20 to your include path as per Colin's answer: go to build settings, double click on "Header Search Paths", and add ${BUILD_DIR}/three20 (it will show as build/three20 when you close the dialog).
Add three20/src/Three20.bundle to your resources.
It's probably also a good idea to add the linker flags -ObjC and -all_load if you haven't already done so (same dialog, setting "Other Linker Flags").
The steps above are good enough for compiling the code. To make "Archive" work too, you will need to:
Add $(BUILT_PRODUCTS_DIR)/../three20 and $(BUILT_PRODUCTS_DIR)/../../three20 to the Header Search Paths setting. If you don't you will get compilation errors that the three20 headers cannot be found.
For all Three20 projects (so not just the top-level project), go the Build Settings and set "Skip Install" to YES. If you don't, the project will build, but you will not be able to create an IPA.
Make sure that your product name (select your target, go to Build Settings, then setting "Product Name") does not contain spaces, otherwise archiving will not work.
Finally, if you're getting errors such as ld: library not found for -lThree20 and you are using a custom build configuration (such as AdHoc), make sure to add the same build configuration to each of the Three20 projects too (just duplicate the Release configuration).
You should check out this StackOverflow question.
I've reproduced the accepted answer below:
So it looks like the easiest way
to get old Xcode 3.2 projects to work
with Xcode 4 is to do the following:
Go into Xcode 4's preferences (Cmd+,).
Select the "Locations" tab. Where it
says "Build Locations", select the
drop down and pick "Place build
products in locations specified by
targets" I'll write up a three20.info
article going into more details about
this.
Add these two paths to your header search paths in the build settings for your target:
"$(BUILD_DIR)/three20"
"$(BUILD_DIR)/../three20"
The first entry is needed for regular builds and the second entry is needed for archives.
It's that easy.
Incidentally, to create a file in your home directory with a list of all of Xcode's environment variables for your target's environement, add the following Run script build phase to your target with contents:
ENV > ~/xcode-environment.sh
Note that in this case, if your project is not making it through the compile phase of the build process, and your Run script comes later, the script won't get executed, so put it first.

Resources