3 # Krzysztof KosiĆski 2014
7 Detect the Clang C compiler
8 This version is an attempt at supporting the -target and -sysroot flag of Clang.
11 from waflib
.Tools
import ccroot
, ar
, gcc
12 from waflib
.Configure
import conf
14 import waflib
.extras
.clang_cross_common
18 Target triplet for clang::
19 $ waf configure --clang-target-triple=x86_64-pc-linux-gnu
21 cc_compiler_opts
= opt
.add_option_group('Configuration options')
22 cc_compiler_opts
.add_option('--clang-target-triple', default
=None,
23 help='Target triple for clang',
24 dest
='clang_target_triple')
25 cc_compiler_opts
.add_option('--clang-sysroot', default
=None,
26 help='Sysroot for clang',
32 Finds the program clang and executes it to ensure it really is clang
37 cc
= conf
.find_program('clang', var
='CC')
39 if conf
.options
.clang_target_triple
!= None:
40 conf
.env
.append_value('CC', ['-target', conf
.options
.clang_target_triple
])
42 if conf
.options
.clang_sysroot
!= None:
45 if os
.path
.isabs(conf
.options
.clang_sysroot
):
46 sysroot
= conf
.options
.clang_sysroot
48 sysroot
= os
.path
.normpath(os
.path
.join(os
.getcwd(), conf
.options
.clang_sysroot
))
50 conf
.env
.append_value('CC', ['--sysroot', sysroot
])
52 conf
.get_cc_version(cc
, clang
=True)
53 conf
.env
.CC_NAME
= 'clang'
56 def clang_modifier_x86_64_w64_mingw32(conf
):
57 conf
.gcc_modifier_win32()
60 def clang_modifier_i386_w64_mingw32(conf
):
61 conf
.gcc_modifier_win32()
64 def clang_modifier_x86_64_windows_msvc(conf
):
65 conf
.clang_modifier_msvc()
67 # Allow the user to override any flags if they so desire.
68 clang_modifier_user_func
= getattr(conf
, 'clang_modifier_x86_64_windows_msvc_user', None)
69 if clang_modifier_user_func
:
70 clang_modifier_user_func()
73 def clang_modifier_i386_windows_msvc(conf
):
74 conf
.clang_modifier_msvc()
76 # Allow the user to override any flags if they so desire.
77 clang_modifier_user_func
= getattr(conf
, 'clang_modifier_i386_windows_msvc_user', None)
78 if clang_modifier_user_func
:
79 clang_modifier_user_func()
83 conf
.find_program(['llvm-ar', 'ar'], var
='AR')
85 conf
.gcc_common_flags()
86 # Allow the user to provide flags for the target platform.
87 conf
.gcc_modifier_platform()
88 # And allow more fine grained control based on the compiler's triplet.
89 conf
.clang_modifier_target_triple()