Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode compiles entire project each time I run

Tags:

xcode4

On a new project I have started, XCode has decided that it will compile every file in the project every time I run it, rather than just compiling files that change (and files dependent on those). As there are getting to be more and more files in the project, this becomes a bigger and bigger burden in both time and battery life.

It is possible that I have changed a setting somewhere that affected this; or, maybe not. What are some project settings that I should be looking at?

like image 624
leecbaker Avatar asked Sep 29 '11 11:09

leecbaker


People also ask

What is compilation mode Xcode?

The 'Compilation Mode' tells the compiler whether to build all files in the project or only the modified files. 'Incremental' says to compile only the files that are modified and 'Whole module' denotes to build all files in the project irrespective of the changes made.

How do I run an existing project in Xcode?

Importing into XcodeOpen Xcode and select Open Another Project or File, Open. Open the folder you unzipped from your Dropsource download and locate the file with “. xcodeproj” extension in the root directory. Select the file and click Open.


2 Answers

If Xcode recompiles most or all of your source files whenever you do a build, that usually means that those files are all directly or indirectly dependent on some header file that has changed. Here are some things to look for:

  1. Do your source files tend to #import some top-level header file that itself recursively imports a bunch of lower-level header files? If any file in that tree of dependent headers is modified, it will force recompilation of any .m file that imports the top-level header file. You may be able to reduce these dependencies by importing headers for lower level submodules, or better yet, for just the specific headers you need for each file. (Note: Some libraries that aren't designed to be used this way can make this approach challenging or impossible in some cases.)

  2. Some third party development tools and static libraries run scripts that generate or modify code as part of their build process. If your source files are dependent on a header file that's generated by a script, they'll be recompiled every time the script regenerates that header file. Even if the code generated by the script doesn't change, dependent source files will be recompiled if the last-modified date of the header file changes. It may take some clever hacking to eliminate redundant compilation if this is your issue.

  3. Don't forget to check your precompiled header (.pch) file to see what's being imported there. The contents of that file are effectively injected at the top of every .m file in your project at compile time.

  4. Try to minimize dependencies by moving as many #import statements as possible out of your .h files and into your .m files. You can generally get away with just importing the headers for your class's superclass and any protocols your class implements in its .h file. You can use forward declarations instead of #import statements for any other classes, data types, or protocols you use in your class's @interface.

like image 144
cduhn Avatar answered Sep 27 '22 16:09

cduhn


I realize this question is over a month old, but I had a similar problem in moving an old project to Xcode 4. After much hair-rending, I discovered that Xcode 4 (4.2 in my case) has a bug where, if there are any non-ASCII characters in the full path either of a source file, or in the full path of any headers the source file includes, it will be recompiled every time you build. This includes the prefix header, in which case a full compile will be triggered every time. In my case, the previous programmer had appended 'ƒ' to several folder names, and once I removed those, it worked perfectly.

Anyway, I stumbled upon this question during my (unsuccessful) attempts to Google an answer and thought I'd share my solution.

like image 21
Boaz Stuller Avatar answered Sep 27 '22 16:09

Boaz Stuller