1#!/usr/bin/env python 2# encoding: utf-8 3# Thomas Nagy 2009-2018 (ita) 4# DragoonX6 2018 5 6""" 7Detect the Clang++ C++ compiler 8This version is an attempt at supporting the -target and -sysroot flag of Clang++. 9""" 10 11from waflib.Tools import ccroot, ar, gxx 12from waflib.Configure import conf 13import waflib.extras.clang_cross_common 14 15def options(opt): 16 """ 17 Target triplet for clang++:: 18 $ waf configure --clangxx-target-triple=x86_64-pc-linux-gnu 19 """ 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') 27 28@conf 29def find_clangxx(conf): 30 """ 31 Finds the program clang++, and executes it to ensure it really is clang++ 32 """ 33 34 import os 35 36 cxx = conf.find_program('clang++', var='CXX') 37 38 if conf.options.clangxx_target_triple != None: 39 conf.env.append_value('CXX', ['-target', conf.options.clangxx_target_triple]) 40 41 if conf.options.clangxx_sysroot != None: 42 sysroot = str() 43 44 if os.path.isabs(conf.options.clangxx_sysroot): 45 sysroot = conf.options.clangxx_sysroot 46 else: 47 sysroot = os.path.normpath(os.path.join(os.getcwd(), conf.options.clangxx_sysroot)) 48 49 conf.env.append_value('CXX', ['--sysroot', sysroot]) 50 51 conf.get_cc_version(cxx, clang=True) 52 conf.env.CXX_NAME = 'clang' 53 54@conf 55def clangxx_modifier_x86_64_w64_mingw32(conf): 56 conf.gcc_modifier_win32() 57 58@conf 59def clangxx_modifier_i386_w64_mingw32(conf): 60 conf.gcc_modifier_win32() 61 62@conf 63def clangxx_modifier_msvc(conf): 64 v = conf.env 65 v.cxxprogram_PATTERN = v.cprogram_PATTERN 66 v.cxxshlib_PATTERN = v.cshlib_PATTERN 67 68 v.CXXFLAGS_cxxshlib = [] 69 v.LINKFLAGS_cxxshlib = v.LINKFLAGS_cshlib 70 v.cxxstlib_PATTERN = v.cstlib_PATTERN 71 72 v.LINK_CXX = v.CXX + ['-fuse-ld=lld', '-nostdlib'] 73 v.CXXLNK_TGT_F = v.CCLNK_TGT_F 74 75@conf 76def clangxx_modifier_x86_64_windows_msvc(conf): 77 conf.clang_modifier_msvc() 78 conf.clangxx_modifier_msvc() 79 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() 84 85@conf 86def clangxx_modifier_i386_windows_msvc(conf): 87 conf.clang_modifier_msvc() 88 conf.clangxx_modifier_msvc() 89 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() 94 95def configure(conf): 96 conf.find_clangxx() 97 conf.find_program(['llvm-ar', 'ar'], var='AR') 98 conf.find_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() 105 conf.cxx_add_flags() 106 conf.link_add_flags() 107