Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force Xcode to use a custom compiler?

Tags:

xcode

llvm

clang

I want to force Xcode to use a custom compiler ('clang-llvm' build from the src) so I can use the clang plugin. My Xcode version is 7.3.1.

like image 668
许金龙 Avatar asked Sep 05 '16 09:09

许金龙


1 Answers

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}")
like image 107
Stanislav Pankevich Avatar answered Sep 28 '22 00:09

Stanislav Pankevich