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