1 # Copyright Vladimir Prus 2004.
2 # Copyright Peter Dimov 2018
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE.txt
6 # or copy at https://www.bfgroup.xyz/b2/LICENSE.txt)
19 feature.extend-subfeature toolset clang : platform : win ;
21 toolset.inherit-generators clang-win <toolset>clang <toolset-clang:platform>win : msvc ;
22 toolset.inherit-flags clang-win : msvc : : YLOPTION ;
23 toolset.inherit-rules clang-win : msvc ;
25 # Override default do-nothing generators.
26 generators.override clang-win.compile.rc : rc.compile.resource ;
27 generators.override clang-win.compile.mc : mc.compile ;
28 generators.override clang-win.compile.c.pch : pch.default-c-pch-generator ;
29 generators.override clang-win.compile.c++.pch : pch.default-cpp-pch-generator ;
32 if [ MATCH (--debug-(clang-(win-)?)?configuration) : [ modules.peek : ARGV ] ]
34 local rule .notice ( messages * )
36 ECHO "notice: [clang-win]" $(messages) ;
41 local rule .notice ( messages * )
46 # [ get-option archiver : 32 : $(options) ]
48 # returns <archiver-32>, or <archiver>
50 local rule get-option ( option : addr : options * )
52 local r = [ feature.get-values "<$(option)-$(addr)>" : $(options) ] ;
53 r ?= [ feature.get-values "<$(option)>" : $(options) ] ;
61 # <assembler>ml.exe (or <assembler-32>, or <assembler-64>)
63 # <manifest-tool>mt.exe
64 # <resource-compiler>rc.exe
66 # <idl-compiler>midl.exe
68 rule init ( version ? : command * : options * )
70 command = [ common.get-invocation-command-nodefault clang-win : clang-cl.exe : $(command) ] ;
74 errors.error "Cannot configure toolset clang-win: no 'clang-cl.exe' command found or given" ;
77 local compiler = "\"$(command)\"" ;
78 compiler = "$(compiler:J= )" ;
80 local version-output = [ SHELL "$(compiler) -v 2>&1" ] ;
82 version ?= [ MATCH "version ([0-9.]+)" : $(version-output) ] ;
83 local target = [ MATCH "Target: ([A-Za-z0-9_]+)" : $(version-output) ] ;
85 local default-addr = 32 ;
86 if $(target) = x86_64 { default-addr = 64 ; }
88 .notice "using compiler '$(compiler)', version '$(version)', target '$(target)', default address-model=$(default-addr)" ;
90 local condition = [ common.check-init-parameters clang-win : version $(version) ] ;
92 common.handle-options clang-win : $(condition) : $(command) : $(options) ;
94 for local addr in 32 64
96 for local arch in x86 arm
101 if $(addr) = 32 { clang-arch = i386 ; } else { clang-arch = x86_64 ; }
103 else if $(arch) = arm
105 if $(addr) = 32 { clang-arch = arm ; } else { clang-arch = aarch64 ; }
108 local config = [ SPLIT_BY_CHARACTERS [ SHELL "$(compiler) --target=$(clang-arch)-pc-windows-msvc -### foo.obj /link 2>&1" ] : "\n" ] ;
115 match = [ MATCH "^ *(\"[^\"]*\")(.*)" : $(config) ] ;
119 items += $(match[1]) ;
120 config = $(match[2]) ;
128 asm = [ regex.replace $(items[1]) "x64\\\\+link\\.exe" "x64\\ml64.exe" ] ;
129 asm = [ regex.replace $(asm) "x86\\\\+link\\.exe" "x86\\ml.exe" ] ;
130 asm = [ regex.replace $(asm) "arm64\\\\+link\\.exe" "arm64\\armasm64.exe" ] ;
131 asm = [ regex.replace $(asm) "arm\\\\+link\\.exe" "arm\\armasm.exe" ] ;
133 if ! [ MATCH "(ml\\.exe)" "(ml64\\.exe)" "(armasm64\\.exe)" "(armasm\\.exe)" : $(asm) ]
139 local assembler = [ get-option "assembler" : $(addr) : $(options) ] ;
140 assembler ?= $(asm) ;
143 if $(addr) = 32 { assembler ?= ml.exe ; } else { assembler ?= ml64.exe ; }
145 else if $(arch) = arm
147 if $(addr) = 32 { assembler ?= armasm.exe ; } else { assembler ?= armasm64.exe ; }
154 linker = [ regex.replace $(items[1]) "\\\\+HostX64\\\\+x86\\\\+" "\\HostX86\\x86\\" ] ;
157 .notice "$(arch)-$(addr):" "using linker '$(linker)'" ;
159 local archiver = [ get-option "archiver" : $(addr) : $(options) ] ;
163 archiver ?= "$(linker) /lib" ;
165 archiver ?= lib.exe ;
167 .notice "$(arch)-$(addr):" "using assembler '$(assembler)'" ;
168 .notice "$(arch)-$(addr):" "using archiver '$(archiver)'" ;
170 local manifest-tool = [ get-option "manifest-tool" : $(addr) : $(options) ] ;
171 local resource-compiler = [ get-option "resource-compiler" : $(addr) : $(options) ] ;
172 local mc-compiler = [ get-option "mc-compiler" : $(addr) : $(options) ] ;
173 local idl-compiler = [ get-option "idl-compiler" : $(addr) : $(options) ] ;
175 for local item in $(items)
177 match = [ MATCH "\"-libpath:(.*)\\\\+Lib\\\\.*\\\\um\\\\+x(.*)\"" : $(item) ] ;
181 local sdk-path = "$(match[1])\\bin\\x$(match[2])" ;
182 .notice "$(arch)-$(addr):" "using SDK path '$(sdk-path)'" ;
184 manifest-tool ?= "\"$(sdk-path)\\mt.exe\"" ;
185 resource-compiler ?= "\"$(sdk-path)\\rc.exe\"" ;
186 mc-compiler ?= "\"$(sdk-path)\\mc.exe\"" ;
187 idl-compiler ?= "\"$(sdk-path)\\midl.exe\"" ;
191 manifest-tool ?= mt.exe ;
192 resource-compiler ?= rc.exe ;
193 mc-compiler ?= mc.exe ;
194 idl-compiler ?= midl.exe ;
196 .notice "$(arch)-$(addr):" "using manifest-tool '$(manifest-tool)'" ;
197 .notice "$(arch)-$(addr):" "using resource-compiler '$(resource-compiler)'" ;
198 .notice "$(arch)-$(addr):" "using mc-compiler '$(mc-compiler)'" ;
199 .notice "$(arch)-$(addr):" "using idl-compiler '$(idl-compiler)'" ;
204 if $(addr) = 32 { linker-arch = x86 ; } else { linker-arch = x64 ; }
206 else if $(arch) = arm
208 if $(addr) = 32 { linker-arch = arm ; } else { linker-arch = arm64 ; }
211 local cond = "$(condition)/<architecture>$(arch)/<address-model>$(addr)" ;
212 if $(addr) = $(default-addr) && $(arch) = x86
214 cond += "$(condition)/<architecture>/<address-model>" ;
215 cond += "$(condition)/<architecture>/<address-model>$(addr)" ;
216 cond += "$(condition)/<architecture>$(arch)/<address-model>" ;
219 toolset.flags clang-win.compile .CC $(cond) : $(compiler) --target=$(clang-arch)-pc-windows-msvc ;
220 toolset.flags clang-win.link .LD $(cond) : $(compiler) --target=$(clang-arch)-pc-windows-msvc ;
221 toolset.flags clang-win.link LINKOPT $(cond) : /link ;
222 toolset.flags clang-win.link LINKFLAGS $(cond) : "/incremental:no" "/manifest" "/machine:$(linker-arch)" ;
225 toolset.flags clang-win.compile .ASM $(cond) : $(assembler) -nologo -c -Zp4 -Cp -Cx ;
226 toolset.flags clang-win.compile .ASM_OUTPUT $(cond) : -Fo ;
228 else if $(arch) = arm
230 toolset.flags clang-win.compile .ASM $(cond) : $(assembler) -machine $(arch) ;
231 toolset.flags clang-win.compile .ASM_OUTPUT $(cond) : -o ;
233 toolset.flags clang-win.archive .LD $(cond) : $(archiver) /nologo ;
234 toolset.flags clang-win.link .MT $(cond) : $(manifest-tool) -nologo ;
235 toolset.flags clang-win.compile .MC $(cond) : $(mc-compiler) ;
236 toolset.flags clang-win.compile .RC $(cond) : $(resource-compiler) ;
237 toolset.flags clang-win.compile .IDL $(cond) : $(idl-compiler) ;
241 toolset.flags clang-win.link LIBRARY_OPTION <toolset>clang-win : "" : unchecked ;
243 # Enable response file control
244 toolset.flags clang-win RESPONSE_FILE_SUB <response-file>auto : a ;
245 toolset.flags clang-win RESPONSE_FILE_SUB <response-file>file : f ;
246 toolset.flags clang-win RESPONSE_FILE_SUB <response-file>contents : c ;