Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode: How to add preprocessor define for a single source file?

I want to add preprocessor macros for a couple files in my project, but not all the files. They're 3rd party sources, so I don't want to edit the files, as to avoid merge maintenance hassle when new versions come along. They happen to interfere with #defines used in other files in the project.

Can XCode 4 compile only certain files with different preprocessor settings than the others?

like image 620
vercellop Avatar asked May 27 '26 12:05

vercellop


1 Answers

In your target's Build Phases tab, you can set compiler flags for individual files under the Compile Sources drop-down. GCC provides a lengthy list of options, but they should work equally well for LLVM.

To define a macro, say FOO, for a specific file, add the -D FOO flag to the "Compiler Flags" entry next to that file.

To un-define a macro FOO, add the flag -U FOO.

like image 188
Aurelius Avatar answered May 31 '26 20:05

Aurelius