How can I force Xcode to use a custom compiler?

People say it is possible with custom toolchains. I didn’t make a research on them because easier solution worked well for me:

It is also possible to run frontend plugins directly by setting appropriate “build settings” of Xcode. (Several ways to do this, you can set them on the command line for instance: xcodebuild build FOO=bla.) Here are a few build settings that I found useful to inject C flags:

OTHER_CFLAGS, OTHER_CPLUSPLUSFLAGS or to replace the compiler(s) and linker(s):

CC, CPLUSPLUS, LD, LDPLUSPLUS, LIBTOOL

The same approach works to control the “analyze” action: CLANG_ANALYZER_EXEC, CLANG_ANALYZER_OTHER_FLAGS

Disclaimer: some of those build settings are undocumented (afaik). Use at your own risk.

(Taken from [cfe-dev] Compile/refactor iOS Xcode projects)

For me it was enough to define the following User-Defined Settings in Build Settings of Xcode projects:

CC=my-c-compiler

CXX=my-cxx-compiler

LIBTOOL=my-linker-for-static-libraries

If you use CMake, the way to inject your compiler automatically is to use

set_target_properties(your-target PROPERTIES XCODE_ATTRIBUTE_CC "${YOUR_CC}")
set_target_properties(your-target PROPERTIES XCODE_ATTRIBUTE_CXX "${YOUR_CXX}")

Leave a Comment