3 # Thomas Nagy 2009-2018 (ita)
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
, gxx
12 from waflib
.Configure
import conf
13 import waflib
.extras
.clang_cross_common
17 Target triplet for clang++::
18 $ waf configure --clangxx-target-triple=x86_64-pc-linux-gnu
20 cxx_compiler_opts
= opt
.add_option_group('Configuration options')
21 cxx_compiler_opts
.add_option('--clangxx-target-triple', default
=None,
22 help='Target triple for clang++',
23 dest
='clangxx_target_triple')
24 cxx_compiler_opts
.add_option('--clangxx-sysroot', default
=None,
25 help='Sysroot for clang++',
26 dest
='clangxx_sysroot')
29 def find_clangxx(conf
):
31 Finds the program clang++, and executes it to ensure it really is clang++
36 cxx
= conf
.find_program('clang++', var
='CXX')
38 if conf
.options
.clangxx_target_triple
!= None:
39 conf
.env
.append_value('CXX', ['-target', conf
.options
.clangxx_target_triple
])
41 if conf
.options
.clangxx_sysroot
!= None:
44 if os
.path
.isabs(conf
.options
.clangxx_sysroot
):
45 sysroot
= conf
.options
.clangxx_sysroot
47 sysroot
= os
.path
.normpath(os
.path
.join(os
.getcwd(), conf
.options
.clangxx_sysroot
))
49 conf
.env
.append_value('CXX', ['--sysroot', sysroot
])
51 conf
.get_cc_version(cxx
, clang
=True)
52 conf
.env
.CXX_NAME
= 'clang'
55 def clangxx_modifier_x86_64_w64_mingw32(conf
):
56 conf
.gcc_modifier_win32()
59 def clangxx_modifier_i386_w64_mingw32(conf
):
60 conf
.gcc_modifier_win32()
63 def clangxx_modifier_msvc(conf
):
65 v
.cxxprogram_PATTERN
= v
.cprogram_PATTERN
66 v
.cxxshlib_PATTERN
= v
.cshlib_PATTERN
68 v
.CXXFLAGS_cxxshlib
= []
69 v
.LINKFLAGS_cxxshlib
= v
.LINKFLAGS_cshlib
70 v
.cxxstlib_PATTERN
= v
.cstlib_PATTERN
72 v
.LINK_CXX
= v
.CXX
+ ['-fuse-ld=lld', '-nostdlib']
73 v
.CXXLNK_TGT_F
= v
.CCLNK_TGT_F
76 def clangxx_modifier_x86_64_windows_msvc(conf
):
77 conf
.clang_modifier_msvc()
78 conf
.clangxx_modifier_msvc()
80 # Allow the user to override any flags if they so desire.
81 clang_modifier_user_func
= getattr(conf
, 'clangxx_modifier_x86_64_windows_msvc_user', None)
82 if clang_modifier_user_func
:
83 clang_modifier_user_func()
86 def clangxx_modifier_i386_windows_msvc(conf
):
87 conf
.clang_modifier_msvc()
88 conf
.clangxx_modifier_msvc()
90 # Allow the user to override any flags if they so desire.
91 clang_modifier_user_func
= getattr(conf
, 'clangxx_modifier_i386_windows_msvc_user', None)
92 if clang_modifier_user_func
:
93 clang_modifier_user_func()
97 conf
.find_program(['llvm-ar', 'ar'], var
='AR')
99 conf
.gxx_common_flags()
100 # Allow the user to provide flags for the target platform.
101 conf
.gxx_modifier_platform()
102 # And allow more fine grained control based on the compiler's triplet.
103 conf
.clang_modifier_target_triple(cpp
=True)
104 conf
.cxx_load_tools()
106 conf
.link_add_flags()