-
Notifications
You must be signed in to change notification settings - Fork 49
/
intel-win.jam
588 lines (532 loc) · 18.7 KB
/
intel-win.jam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# Copyright René Ferdinand Rivera Morell 2022
# Copyright Vladimir Prus 2004.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt
# or copy at https://www.bfgroup.xyz/b2/LICENSE.txt)
# Importing common is needed because the rules we inherit here depend on it.
# That is nasty.
import common ;
import errors ;
import feature ;
import intel ;
import msvc ;
import os ;
import set ;
import toolset ;
import generators ;
import type ;
import path ;
import numbers ;
feature.extend-subfeature toolset intel : platform : win ;
toolset.inherit-generators intel-win <toolset>intel <toolset-intel:platform>win : msvc ;
toolset.inherit-flags intel-win : msvc : : YLOPTION ;
toolset.inherit-rules intel-win : msvc ;
toolset.flags intel-win.compile PCH_SOURCE <pch>on : <pch-source> ;
toolset.add-requirements <toolset>intel-win,<runtime-link>shared:<threading>multi ;
.oneapidir = [ W32_GETREG
"HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Intel\\Products\\IntelOneAPI" : "ProductDir" ] ;
.oneapidir ?= "C:\\Program Files (x86)\\Intel\\oneAPI\\" ;
.oneapidir = [ path.make $(.oneapidir) ] ;
# Intel oneAPI 2020, and onward.
.bin(oneAPI) =
[ path.join $(.oneapidir) compiler/latest/windows/bin ] ;
# Initializes the intel toolset for windows
rule init ( version ? : # the compiler version
command * : # the command to invoke the compiler itself
options * # Additional option: <compatibility>
# either 'vc6', 'vc7', 'vc7.1'
# or 'native'(default).
)
{
if $(version)
{
configure $(version) : $(command) : $(options) ;
}
else
{
if $(command)
{
errors.error "Autodetect of version from command not implemented!" ;
}
local versions ;
{
# On auto config mode the user can still request a msvc backend.
# If some intel compiler doesn't support it, don't try to configure
# it!
local autodetect-versions = [ get-autodetect-versions () ] ;
if $(autodetect-versions)
{
local msvc-version = [ feature.get-values <compatibility> : $(options) ] ;
msvc-version = [ get-msvc-version-from-vc-string $(msvc-version) ] ;
for local v in
{
if [ is-msvc-supported $(v) : $(msvc-version) ]
{
versions += $(v) ;
configure $(v) : : $(options) ;
}
}
}
}
{
local detected_version ;
local detected_command ;
local command_abs_path ;
if ! $(detected_command)
{
local bin_paths = $(.bin(oneAPI)) ;
detected_command = [ common.find-tool icx.exe : $(bin_paths) ] ;
if $(detected_command)
{
command_abs_path = [ common.get-absolute-tool-path $(detected_command) ] ;
}
}
if $(detected_command)
{
local version_cmd = "\"$(detected_command)\" /QV 2>&1" ;
local version_output = [ SHELL $(version_cmd) ] ;
detected_version = [ MATCH "Version ([0-9]+[.][0-9]+)[.][0-9]+" : $(version_output) ] ;
}
versions += $(detected_version) ;
configure $(detected_version) : $(detected_command) : $(options) ;
}
if ! $(versions)
{
errors.error "No intel compiler version found!" ;
return ;
}
}
}
local rule configure ( version ? : command * : options * )
{
local compatibility =
[ feature.get-values <compatibility> : $(options) ] ;
# Allow to specify toolset and visual studio backend from commandline .e.g --toolset=intel-14.0-vc10
local vc_in_version = [ MATCH "(vc[0-9]+(\\.[0-9]+)?)$" : $(version) ] ;
vc_in_version = $(vc_in_version[1]) ;
if $(compatibility) && $(vc_in_version)
{
if $(compatibility) != $(vc_in_version)
{
errors.error "feature compatibility and vc version in toolset present!" ;
}
}
if $(vc_in_version) && ! $(compatibility)
{
# vc Version must be stripped before check-init-parameters is called!
version = [ MATCH (.+)-vc.+$ : $(version) ] ;
compatibility = $(vc_in_version) ;
options += <compatibility>$(vc_in_version) ;
}
if $(compatibility)
{
configure-really $(version) : $(command) : $(options) : $(compatibility) ;
}
else
{
local msvc_versions = [ feature.values <toolset-msvc:version> ] ;
if ! $(msvc_versions)
{
ECHO notice\: no msvc versions detected. trying auto detect ;
toolset.using msvc : all ;
msvc_versions = [ feature.values <toolset-msvc:version> ] ;
}
if ! $(.iclvars-$(version)-supported-vcs)
{
errors.error "Supported msvc versions not known for intel" $(version) ;
}
for local v in $(msvc_versions)
{
if [ MATCH "($(v))" : $(.iclvars-$(version)-supported-vcs) ]
{
# Strip trailing .0 from msvc version as intel compiler uses atm only major version for Qvc
local m = [ MATCH "([0-9]+).0$" : $(v) ] ;
if $(m)
{
v = $(m) ;
}
v = "vc$(v)" ;
local options_really = $(options) ;
options_really += <compatibility>$(v) ;
if $(.debug-configuration)
{
ECHO "configure: intel version: $(version) msvc version: $(v)" ;
}
configure-really $(version) : $(command) : $(options) : $(v) ;
}
}
if ! [ feature.values <toolset-intel:version> ]
{
errors.error "Failed to register an intel toolset!" ;
}
}
}
local rule configure-really ( version ? : command * : options * : compatibility )
{
local rewrite-setupscript = [ feature.get-values <rewrite-setup-scripts> : $(options) ] ;
local condition = [ common.check-init-parameters intel-win
: version $(version) : compatibility $(compatibility) ] ;
local m = [ MATCH "([0-9]+).*" : $(version) ] ;
local major = $(m[1]) ;
if ! $(major)
{
errors.error "Major version not found: $(version)" ;
}
local msvc-version = [ get-msvc-version-from-vc-string $(compatibility) ] ;
if ! $(msvc-version)
{
errors.user-error "Invalid value for compatibility option:"
$(compatibility) ;
}
command = [ get-compiler-invocation-cmd $(major) : $(command) ] ;
common.handle-options intel-win : $(condition) : $(command) : $(options) ;
local root = [ feature.get-values <root> : $(options) ] ;
if $(command) || $(root)
{
local bin ;
if $(command)
{
bin = [ common.get-absolute-tool-path $(command[-1]) ] ;
if $(bin) && ( $(major) = 2022 || [ numbers.less 2022 $(major) ] )
{
bin = [ path.make $(bin) ] ;
bin = [ path.parent [ path.parent [ path.parent [ path.parent $(bin) ] ] ] ] ;
}
else if $(bin) && ( $(major) = 12 || [ numbers.less 12 $(major) ] )
{
bin = [ path.make $(bin) ] ;
bin = [ path.parent $(bin) ] ;
}
}
root ?= $(bin) ;
root = $(root)/ ;
}
local setup ;
local setup_astk_bat ;
local setup_bat ;
if $(major) = 21 || [ numbers.less 21 $(major) ]
{
setup_astk_bat = "setvars_*.bat" ;
setup_bat = "setvars.bat" ;
}
else
{
setup_astk_bat = "iclvars_*.bat" ;
setup_bat = "iclvars.bat" ;
}
setup = [ path.glob $(root) : $(setup_astk_bat) ] ;
if ! $(setup)
{
setup = [ path.join $(root) $(setup_bat) ] ;
setup = [ path.native $(setup) ] ;
}
local target_types ;
local iclvars_vs_arg ;
if $(major) = 12 || [ numbers.less 12 $(major) ]
{
# if we have a known intel toolset check for visual studio compatibility
# if not trust parameters
if ! [ is-msvc-supported $(version) : $(msvc-version) ]
{
errors.error "msvc $(msvc-version) not supported for intel toolset version $(version)" ;
}
if $(.iclvars-version-alias-$(compatibility))
{
iclvars_vs_arg = $(.iclvars-version-alias-$(compatibility)) ;
}
else
{
errors.error "Don't know what parameter to pass for vc version ( $(compatibility) )" ;
}
# There are two possible paths for the 64-bit intel compiler,
# one for the IA32-Intel64 cross compiler, and one for the native
# 64 bit compiler. We prefer the latter one if it's installed,
# and don't rely on whether the OS reports whether we're 64 or 32 bit
# as that really only tells us which subsystem bjam is running in:
#
local root_start ;
if $(major) = 21 || [ numbers.less 21 $(major) ]
{
root_start = [ path.join $(root) "compiler/latest/windows/bin" ] ;
root_start = [ path.native $(root_start) ] ;
}
else
{
root_start = $(root) ;
}
local intel64_path = [ path.join $(root_start) intel64 ] ;
if [ path.glob $(intel64_path) : icl.exe ]
{
target_types = ia32 intel64 ;
}
else
{
target_types = ia32 ia32_intel64 ;
}
}
else
{
target_types = default ;
iclvars_vs_arg = $(compatibility) ;
}
local default-assembler-intel64 = ml64 ;
local default-assembler-ia32_intel64 = ml64 ;
local default-assembler-ia32 = "ml -coff" ;
local assembler-flags-intel64 = "-c -Zp4 -Cp -Cx" ;
local assembler-flags-ia32_intel64 = "-c -Zp4 -Cp -Cx" ;
local assembler-flags-ia32 = "-c -Zp4 -Cp -Cx" ;
assembler = [ feature.get-values <assembler> : $(options) ] ;
for local c in $(target_types)
{
local cpu-conditions ;
local setup-call ;
if $(major) = 12 || [ numbers.less 12 $(major) ]
{
cpu-conditions = $(condition)/$(.cpu-arch-$(c)) ;
if ! $(setup)
{
# No setup script
}
else if $(rewrite-setupscript) = off || [ os.name ] != NT
{
setup-call = "call \"$(setup)\" $(c) $(iclvars_vs_arg) > nul " ;
}
else
{
if $(rewrite-setupscript) = always
{
toolset.flags intel-win .REWRITE-SETUP $(cpu-conditions) : true ;
}
toolset.flags intel-win .SETUP-SCRIPT $(cpu-conditions) : $(setup) ;
toolset.flags intel-win .SETUP-OPTIONS $(cpu-conditions) : "$(c) $(iclvars_vs_arg)" ;
}
}
else
{
setup-call = "call \""$(setup)"\" $(compatibility) > nul " ;
cpu-conditions = $(condition) ;
}
if $(setup-call)
{
if [ os.name ] = NT
{
setup-call = $(setup-call)"\n " ;
}
else
{
setup-call = "cmd /S /C "$(setup-call)" \"&&\" " ;
}
toolset.flags intel-win .SETUP $(cpu-conditions) : $(setup-call) ;
}
if $(.debug-configuration)
{
for local cond in $(cpu-conditions)
{
ECHO "notice: [intel-cfg] condition: '$(cond)', setup: '$(setup-call)'" ;
}
}
local cpu-assembler = $(assembler) ;
cpu-assembler ?= $(default-assembler-$(c)) ;
toolset.flags intel-win.compile .CC $(cpu-conditions) : icl ;
toolset.flags intel-win.link .LD $(cpu-conditions) : xilink /nologo ;
toolset.flags intel-win.archive .LD $(cpu-conditions) : xilink /lib /nologo ;
toolset.flags intel-win.link .MT $(cpu-conditions) : mt -nologo ;
toolset.flags intel-win.compile .ASM $(cpu-conditions) : $(cpu-assembler) -nologo $(assembler-flags-$(c)) ;
toolset.flags intel-win.compile .ASM_OUTPUT $(cpu-conditions) : -Fo ;
toolset.flags intel-win.compile .MC $(cpu-conditions) : mc ;
toolset.flags intel-win.compile .RC $(cpu-conditions) : rc ;
}
# Depending on the settings, running of tests require some runtime DLLs.
toolset.flags intel-win RUN_PATH $(condition) : $(root) ;
local C++FLAGS ;
C++FLAGS += /nologo ;
# Reduce the number of spurious error messages
C++FLAGS += /Qwn5 /Qwd985 ;
# Enable ADL
C++FLAGS += -Qoption,c,--arg_dep_lookup ; #"c" works for C++, too
# Disable Microsoft "secure" overloads in Dinkumware libraries since they
# cause compile errors with Intel versions 9 and 10.
if [ numbers.less $(major) 12 ]
{
C++FLAGS += -D_SECURE_SCL=0 ;
}
if [ numbers.less 5 $(major) ]
{
C++FLAGS += "/Zc:forScope" ; # Add support for correct for loop scoping.
}
# Add options recognized only by intel7 and above.
if $(major) = 7 || [ numbers.less 7 $(major) ]
{
C++FLAGS += /Qansi_alias ;
}
if $(compatibility) = vc6
{
C++FLAGS +=
# Emulate VC6
/Qvc6
# No wchar_t support in vc6 dinkum library. Furthermore, in vc6
# compatibility-mode, wchar_t is not a distinct type from unsigned
# short.
-DBOOST_NO_INTRINSIC_WCHAR_T
;
}
else
{
if [ numbers.less 5 $(major) ]
{
# Add support for wchar_t
C++FLAGS += "/Zc:wchar_t"
# Tell the dinkumware library about it.
-D_NATIVE_WCHAR_T_DEFINED
;
}
}
if $(compatibility) && $(compatibility) != native
{
C++FLAGS += /Q$(compatibility) ;
}
else
{
C++FLAGS +=
-Qoption,cpp,--arg_dep_lookup
# The following options were intended to disable the Intel compiler's
# 'bug-emulation' mode, but were later reported to be causing ICE with
# Intel-Win 9.0. It is not yet clear which options can be safely used.
# -Qoption,cpp,--const_string_literals
# -Qoption,cpp,--new_for_init
# -Qoption,cpp,--no_implicit_typename
# -Qoption,cpp,--no_friend_injection
# -Qoption,cpp,--no_microsoft_bugs
;
}
toolset.flags intel-win CFLAGS $(condition) : $(C++FLAGS) ;
# By default, when creating PCH, intel adds 'i' to the explicitly
# specified name of the PCH file. Of course, B2 is not
# happy when compiler produces not the file it was asked for.
# The option below stops this behaviour.
toolset.flags intel-win CFLAGS $(condition) : -Qpchi- ;
if ! $(compatibility)
{
# If there's no backend version, assume 7.1.
compatibility = vc7.1 ;
}
msvc-version = [ msvc.resolve-possible-msvc-version-alias $(msvc-version) ] ;
msvc.configure-version-specific intel-win : $(msvc-version) : $(condition) ;
}
local rule get-autodetect-versions
{
local result ;
for local v in $(.intel-autodetect-versions)
{
local major = [ MATCH "([0-9]+).*" : $(v) ] ; # Use only major version
if [ get-icl-path-from-environment $(major) ]
{
result += $(v) ;
}
}
return $(result) ;
}
local rule get-icl-path-from-environment ( major_version )
{
local path = [ os.environ ICPP_COMPILER$(major_version) ] ;
if $(path)
{
path = [ path.make $(path) ] ;
local cmdpath ;
local subdirs = $(.icl-target-subdirectories) ;
while $(subdirs)
{
cmdpath = [ path.join $(path) "bin/$(subdirs[0])/icl.exe" ] ;
cmdpath = [ path.native $(cmdpath) ] ;
if [ path.exists $(cmdpath) ]
{
subdirs = ;
} else {
cmdpath = ;
subdirs = $(subdirs[2-]) ;
}
}
path = $(cmdpath) ;
}
return $(path) ;
}
local rule get-compiler-invocation-cmd ( major_version : command * )
{
if $(command)
{
return [ common.get-invocation-command intel-win : icl.exe : $(command) ] ;
}
else
{
local path = [ get-icl-path-from-environment $(major_version) ] ;
return [ common.get-invocation-command intel-win : icl.exe : $(path) ] ;
}
}
local rule is-msvc-supported ( intel-version : msvc-version )
{
if ! $(msvc-version)
{
return true ;
}
else
{
if $(.iclvars-$(intel-version)-supported-vcs)
{
if [ MATCH "($(msvc-version))" : $(.iclvars-$(intel-version)-supported-vcs) ]
{
return true ;
}
}
else
{
return true ;
}
}
}
local rule get-msvc-version-from-vc-string ( vc-string )
{
local r = [ MATCH "^vc([0-9]+(\\.[0-9]+)?)$" : $(vc-string) ] ;
return $(r[1]) ;
}
if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]
{
.debug-configuration = true ;
}
# Copied from msvc.jam
# Supported CPU architectures.
.cpu-arch-ia32 =
<architecture>/<address-model>
<architecture>/<address-model>32
<architecture>x86/<address-model>
<architecture>x86/<address-model>32 ;
.cpu-arch-intel64 =
<architecture>/<address-model>64
<architecture>x86/<address-model>64 ;
.cpu-arch-ia32_intel64 =
<architecture>/<address-model>64
<architecture>x86/<address-model>64 ;
.intel-autodetect-versions = 14.0 13.0 12.0 ;
.iclvars-12.0-supported-vcs = "10.0 9.0 8.0" ;
.iclvars-12.1-supported-vcs = "10.0 9.0 8.0" ;
.iclvars-13.0-supported-vcs = "11.0 10.0 9.0" ;
.iclvars-14.0-supported-vcs = "12.0 11.0 10.0 9.0" ;
.iclvars-15.0-supported-vcs = "12.0 11.0 10.0 9.0" ;
.iclvars-16.0-supported-vcs = "14.0 12.0 11.0 10.0 9.0" ;
.iclvars-17.0-supported-vcs = "14.1 14.0 12.0 11.0 10.0" ;
.iclvars-18.0-supported-vcs = "14.1 14.0 12.0 11.0 10.0" ;
.iclvars-19.0-supported-vcs = "14.2 14.1 14.0 12.0" ;
.iclvars-19.1-supported-vcs = "14.2 14.1 14.0 12.0" ;
.iclvars-21.1-supported-vcs = "14.2 14.1" ;
.iclvars-2021.1-supported-vcs = "14.2 14.1" ;
.iclvars-2022.0-supported-vcs = "14.3 14.2 14.1" ;
.iclvars-version-alias-vc14.2 = vs2019 ;
.iclvars-version-alias-vc14.1 = vs2017 ;
.iclvars-version-alias-vc14 = vs2015 ;
.iclvars-version-alias-vc12 = vs2013 ;
.iclvars-version-alias-vc11 = vs2012 ;
.iclvars-version-alias-vc10 = vs2010 ;
.iclvars-version-alias-vc9 = vs2008 ;
.iclvars-version-alias-vc8 = vs2005 ;
.icl-target-subdirectories = ia32 ia32_intel64 intel64 ;
toolset.flags intel-win.link LIBRARY_OPTION <toolset>intel : "" ;
toolset.flags intel-win YLOPTION ;