3 # Carlos Rafael Giani, 2006 (dv)
4 # Tamas Pal, 2007 (folti)
5 # Nicolas Mercier, 2009
9 Microsoft Visual C++/Intel C++ compiler support
11 If you get detection problems, first try any of the following::
14 set PYTHONIOENCODING=...
15 set PYTHONLEGACYWINDOWSSTDIO=1
19 $ waf configure --msvc_version="msvc 10.0,msvc 9.0" --msvc_target="x64"
24 conf.env.MSVC_VERSIONS = ['msvc 10.0', 'msvc 9.0', 'msvc 8.0', 'msvc 7.1', 'msvc 7.0', 'msvc 6.0', 'wsdk 7.0', 'intel 11', 'PocketPC 9.0', 'Smartphone 8.0']
25 conf.env.MSVC_TARGETS = ['x64']
31 conf.load('msvc', funs='no_autodetect')
32 conf.check_lib_msvc('gdi32')
33 conf.check_libs_msvc('kernel32 user32')
35 tg = bld.program(source='main.c', target='app', use='KERNEL32 USER32 GDI32')
37 Platforms and targets will be tested in the order they appear;
38 the first good configuration will be used.
40 To force testing all the configurations that are not used, use the ``--no-msvc-lazy`` option
41 or set ``conf.env.MSVC_LAZY_AUTODETECT=False``.
43 Supported platforms: ia64, x64, x86, x86_amd64, x86_ia64, x86_arm, amd64_x86, amd64_arm
47 * msvc => Visual Studio, versions 6.0 (VC 98, VC .NET 2002) to 15 (Visual Studio 2017)
48 * wsdk => Windows SDK, versions 6.0, 6.1, 7.0, 7.1, 8.0
49 * icl => Intel compiler, versions 9, 10, 11, 13
50 * winphone => Visual Studio to target Windows Phone 8 native (version 8.0 for now)
51 * Smartphone => Compiler/SDK for Smartphone devices (armv4/v4i)
52 * PocketPC => Compiler/SDK for PocketPC devices (armv4/v4i)
54 To use WAF in a VS2008 Make file project (see http://code.google.com/p/waf/issues/detail?id=894)
55 You may consider to set the environment variable "VS_UNICODE_OUTPUT" to nothing before calling waf.
56 So in your project settings use something like 'cmd.exe /C "set VS_UNICODE_OUTPUT=& set PYTHONUNBUFFERED=true & waf build"'.
57 cmd.exe /C "chcp 1252 & set PYTHONUNBUFFERED=true && set && waf configure"
58 Setting PYTHONUNBUFFERED gives the unbuffered output.
61 import os
, sys
, re
, traceback
62 from waflib
import Utils
, Logs
, Options
, Errors
63 from waflib
.TaskGen
import after_method
, feature
65 from waflib
.Configure
import conf
66 from waflib
.Tools
import ccroot
, c
, cxx
, ar
68 g_msvc_systemlibs
= '''
69 aclui activeds ad1 adptif adsiid advapi32 asycfilt authz bhsupp bits bufferoverflowu cabinet
70 cap certadm certidl ciuuid clusapi comctl32 comdlg32 comsupp comsuppd comsuppw comsuppwd comsvcs
71 credui crypt32 cryptnet cryptui d3d8thk daouuid dbgeng dbghelp dciman32 ddao35 ddao35d
72 ddao35u ddao35ud delayimp dhcpcsvc dhcpsapi dlcapi dnsapi dsprop dsuiext dtchelp
73 faultrep fcachdll fci fdi framedyd framedyn gdi32 gdiplus glauxglu32 gpedit gpmuuid
74 gtrts32w gtrtst32hlink htmlhelp httpapi icm32 icmui imagehlp imm32 iphlpapi iprop
75 kernel32 ksguid ksproxy ksuser libcmt libcmtd libcpmt libcpmtd loadperf lz32 mapi
76 mapi32 mgmtapi minidump mmc mobsync mpr mprapi mqoa mqrt msacm32 mscms mscoree
77 msdasc msimg32 msrating mstask msvcmrt msvcurt msvcurtd mswsock msxml2 mtx mtxdm
78 netapi32 nmapinmsupp npptools ntdsapi ntdsbcli ntmsapi ntquery odbc32 odbcbcp
79 odbccp32 oldnames ole32 oleacc oleaut32 oledb oledlgolepro32 opends60 opengl32
80 osptk parser pdh penter pgobootrun pgort powrprof psapi ptrustm ptrustmd ptrustu
81 ptrustud qosname rasapi32 rasdlg rassapi resutils riched20 rpcndr rpcns4 rpcrt4 rtm
82 rtutils runtmchk scarddlg scrnsave scrnsavw secur32 sensapi setupapi sfc shell32
83 shfolder shlwapi sisbkup snmpapi sporder srclient sti strsafe svcguid tapi32 thunk32
84 traffic unicows url urlmon user32 userenv usp10 uuid uxtheme vcomp vcompd vdmdbg
85 version vfw32 wbemuuid webpost wiaguid wininet winmm winscard winspool winstrm
86 wintrust wldap32 wmiutils wow32 ws2_32 wsnmp32 wsock32 wst wtsapi32 xaswitch xolehlp
88 """importlibs provided by MSVC/Platform SDK. Do NOT search them"""
90 all_msvc_platforms
= [ ('x64', 'amd64'), ('x86', 'x86'), ('ia64', 'ia64'),
91 ('x86_amd64', 'amd64'), ('x86_ia64', 'ia64'), ('x86_arm', 'arm'), ('x86_arm64', 'arm64'),
92 ('amd64_x86', 'x86'), ('amd64_arm', 'arm'), ('amd64_arm64', 'arm64') ]
93 """List of msvc platforms"""
95 all_wince_platforms
= [ ('armv4', 'arm'), ('armv4i', 'arm'), ('mipsii', 'mips'), ('mipsii_fp', 'mips'), ('mipsiv', 'mips'), ('mipsiv_fp', 'mips'), ('sh4', 'sh'), ('x86', 'cex86') ]
96 """List of wince platforms"""
98 all_icl_platforms
= [ ('intel64', 'amd64'), ('em64t', 'amd64'), ('ia32', 'x86'), ('Itanium', 'ia64')]
99 """List of icl platforms"""
103 vsver
= os
.getenv('VSCMD_VER')
105 m
= re
.match(r
'(^\d+\.\d+).*', vsver
)
107 default_ver
= 'msvc %s' % m
.group(1)
108 opt
.add_option('--msvc_version', type='string', help = 'msvc version, eg: "msvc 10.0,msvc 9.0"', default
=default_ver
)
109 opt
.add_option('--msvc_targets', type='string', help = 'msvc targets, eg: "x64,arm"', default
='')
110 opt
.add_option('--no-msvc-lazy', action
='store_false', help = 'lazily check msvc target environments', default
=True, dest
='msvc_lazy')
112 class MSVCVersion(object):
113 def __init__(self
, ver
):
114 m
= re
.search(r
'^(.*)\s+(\d+[.]\d+)', ver
)
116 self
.name
= m
.group(1)
117 self
.number
= float(m
.group(2))
122 def __lt__(self
, other
):
123 if self
.number
== other
.number
:
124 return self
.name
< other
.name
125 return self
.number
< other
.number
128 def setup_msvc(conf
, versiondict
):
130 Checks installed compilers and targets and returns the first combination from the user's
131 options, env, or the global supported lists that checks.
133 :param versiondict: dict(platform -> dict(architecture -> configuration))
134 :type versiondict: dict(string -> dict(string -> target_compiler)
135 :return: the compiler, revision, path, include dirs, library paths and target architecture
136 :rtype: tuple of strings
138 platforms
= getattr(Options
.options
, 'msvc_targets', '').split(',')
139 if platforms
== ['']:
140 platforms
=Utils
.to_list(conf
.env
.MSVC_TARGETS
) or [i
for i
,j
in all_msvc_platforms
+all_icl_platforms
+all_wince_platforms
]
141 desired_versions
= getattr(Options
.options
, 'msvc_version', '').split(',')
142 if desired_versions
== ['']:
143 desired_versions
= conf
.env
.MSVC_VERSIONS
or list(sorted(versiondict
.keys(), key
=MSVCVersion
, reverse
=True))
145 # Override lazy detection by evaluating after the fact.
146 lazy_detect
= getattr(Options
.options
, 'msvc_lazy', True)
147 if conf
.env
.MSVC_LAZY_AUTODETECT
is False:
151 for val
in versiondict
.values():
152 for arch
in list(val
.keys()):
157 conf
.env
.MSVC_INSTALLED_VERSIONS
= versiondict
159 for version
in desired_versions
:
160 Logs
.debug('msvc: detecting %r - %r', version
, desired_versions
)
162 targets
= versiondict
[version
]
167 for arch
in platforms
:
179 compiler
,revision
= version
.rsplit(' ', 1)
180 return compiler
,revision
,cfg
.bindirs
,cfg
.incdirs
,cfg
.libdirs
,cfg
.cpu
181 conf
.fatal('msvc: Impossible to find a valid architecture for building %r - %r' % (desired_versions
, list(versiondict
.keys())))
184 def get_msvc_version(conf
, compiler
, version
, target
, vcvars
):
186 Checks that an installed compiler actually runs and uses vcvars to obtain the
187 environment needed by the compiler.
189 :param compiler: compiler type, for looking up the executable name
190 :param version: compiler version, for debugging only
191 :param target: target architecture
192 :param vcvars: batch file to run to check the environment
193 :return: the location of the compiler executable, the location of include dirs, and the library paths
194 :rtype: tuple of strings
196 Logs
.debug('msvc: get_msvc_version: %r %r %r', compiler
, version
, target
)
200 except AttributeError:
202 batfile
= conf
.bldnode
.make_node('waf-print-msvc-%d.bat' % conf
.msvc_cnt
)
203 batfile
.write("""@echo off
208 echo INCLUDE=%%INCLUDE%%
209 echo LIB=%%LIB%%;%%LIBPATH%%
210 """ % (vcvars
,target
))
211 sout
= conf
.cmd_and_log(['cmd.exe', '/E:on', '/V:on', '/C', batfile
.abspath()], stdin
=getattr(Utils
.subprocess
, 'DEVNULL', None))
212 lines
= sout
.splitlines()
217 MSVC_PATH
= MSVC_INCDIR
= MSVC_LIBDIR
= None
219 if line
.startswith('PATH='):
221 MSVC_PATH
= path
.split(';')
222 elif line
.startswith('INCLUDE='):
223 MSVC_INCDIR
= [i
for i
in line
[8:].split(';') if i
]
224 elif line
.startswith('LIB='):
225 MSVC_LIBDIR
= [i
for i
in line
[4:].split(';') if i
]
226 if None in (MSVC_PATH
, MSVC_INCDIR
, MSVC_LIBDIR
):
227 conf
.fatal('msvc: Could not find a valid architecture for building (get_msvc_version_3)')
229 # Check if the compiler is usable at all.
230 # The detection may return 64-bit versions even on 32-bit systems, and these would fail to run.
231 env
= dict(os
.environ
)
232 env
.update(PATH
= path
)
233 compiler_name
, linker_name
, lib_name
= _get_prog_names(conf
, compiler
)
234 cxx
= conf
.find_program(compiler_name
, path_list
=MSVC_PATH
)
236 # delete CL if exists. because it could contain parameters which can change cl's behaviour rather catastrophically.
241 conf
.cmd_and_log(cxx
+ ['/help'], env
=env
)
243 st
= traceback
.format_exc()
245 conf
.logger
.error(st
)
246 conf
.fatal('msvc: Unicode error - check the code page?')
247 except Exception as e
:
248 Logs
.debug('msvc: get_msvc_version: %r %r %r -> failure %s', compiler
, version
, target
, str(e
))
249 conf
.fatal('msvc: cannot run the compiler in get_msvc_version (run with -v to display errors)')
251 Logs
.debug('msvc: get_msvc_version: %r %r %r -> OK', compiler
, version
, target
)
253 conf
.env
[compiler_name
] = ''
255 return (MSVC_PATH
, MSVC_INCDIR
, MSVC_LIBDIR
)
257 def gather_wince_supported_platforms():
259 Checks SmartPhones SDKs
261 :param versions: list to modify
264 supported_wince_platforms
= []
266 ce_sdk
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, 'SOFTWARE\\Wow6432node\\Microsoft\\Windows CE Tools\\SDKs')
269 ce_sdk
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, 'SOFTWARE\\Microsoft\\Windows CE Tools\\SDKs')
273 return supported_wince_platforms
278 sdk_device
= Utils
.winreg
.EnumKey(ce_sdk
, index
)
279 sdk
= Utils
.winreg
.OpenKey(ce_sdk
, sdk_device
)
284 path
,type = Utils
.winreg
.QueryValueEx(sdk
, 'SDKRootDir')
287 path
,type = Utils
.winreg
.QueryValueEx(sdk
,'SDKInformation')
290 path
,xml
= os
.path
.split(path
)
292 path
,device
= os
.path
.split(path
)
294 path
,device
= os
.path
.split(path
)
296 for arch
,compiler
in all_wince_platforms
:
297 if os
.path
.isdir(os
.path
.join(path
, device
, 'Lib', arch
)):
298 platforms
.append((arch
, compiler
, os
.path
.join(path
, device
, 'Include', arch
), os
.path
.join(path
, device
, 'Lib', arch
)))
300 supported_wince_platforms
.append((device
, platforms
))
301 return supported_wince_platforms
303 def gather_msvc_detected_versions():
304 #Detected MSVC versions!
305 version_pattern
= re
.compile(r
'^(\d\d?\.\d\d?)(Exp)?$')
306 detected_versions
= []
307 for vcver
,vcvar
in (('VCExpress','Exp'), ('VisualStudio','')):
308 prefix
= 'SOFTWARE\\Wow6432node\\Microsoft\\' + vcver
310 all_versions
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, prefix
)
312 prefix
= 'SOFTWARE\\Microsoft\\' + vcver
314 all_versions
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, prefix
)
321 version
= Utils
.winreg
.EnumKey(all_versions
, index
)
325 match
= version_pattern
.match(version
)
327 versionnumber
= float(match
.group(1))
330 detected_versions
.append((versionnumber
, version
+vcvar
, prefix
+'\\'+version
))
334 detected_versions
.sort(key
= fun
)
335 return detected_versions
337 class target_compiler(object):
339 Wrap a compiler configuration; call evaluate() to determine
340 whether the configuration is usable.
342 def __init__(self
, ctx
, compiler
, cpu
, version
, bat_target
, bat
, callback
=None):
344 :param ctx: configuration context to use to eventually get the version environment
345 :param compiler: compiler name
346 :param cpu: target cpu
347 :param version: compiler version number
349 :param bat: path to the batch file to run
353 self
.is_valid
= False
356 self
.compiler
= compiler
358 self
.version
= version
359 self
.bat_target
= bat_target
361 self
.callback
= callback
368 vs
= self
.conf
.get_msvc_version(self
.compiler
, self
.version
, self
.bat_target
, self
.bat
)
369 except Errors
.ConfigurationError
:
370 self
.is_valid
= False
373 vs
= self
.callback(self
, vs
)
375 (self
.bindirs
, self
.incdirs
, self
.libdirs
) = vs
378 return str((self
.compiler
, self
.cpu
, self
.version
, self
.bat_target
, self
.bat
))
381 return repr((self
.compiler
, self
.cpu
, self
.version
, self
.bat_target
, self
.bat
))
384 def gather_wsdk_versions(conf
, versions
):
386 Use winreg to add the msvc versions to the input list
388 :param versions: list to modify
391 version_pattern
= re
.compile(r
'^v..?.?\...?.?')
393 all_versions
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, 'SOFTWARE\\Wow6432node\\Microsoft\\Microsoft SDKs\\Windows')
396 all_versions
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, 'SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows')
402 version
= Utils
.winreg
.EnumKey(all_versions
, index
)
406 if not version_pattern
.match(version
):
409 msvc_version
= Utils
.winreg
.OpenKey(all_versions
, version
)
410 path
,type = Utils
.winreg
.QueryValueEx(msvc_version
,'InstallationFolder')
413 if path
and os
.path
.isfile(os
.path
.join(path
, 'bin', 'SetEnv.cmd')):
415 for target
,arch
in all_msvc_platforms
:
416 targets
[target
] = target_compiler(conf
, 'wsdk', arch
, version
, '/'+target
, os
.path
.join(path
, 'bin', 'SetEnv.cmd'))
417 versions
['wsdk ' + version
[1:]] = targets
420 def gather_msvc_targets(conf
, versions
, version
, vc_path
):
421 #Looking for normal MSVC compilers!
424 if os
.path
.isfile(os
.path
.join(vc_path
, 'VC', 'Auxiliary', 'Build', 'vcvarsall.bat')):
425 for target
,realtarget
in all_msvc_platforms
[::-1]:
426 targets
[target
] = target_compiler(conf
, 'msvc', realtarget
, version
, target
, os
.path
.join(vc_path
, 'VC', 'Auxiliary', 'Build', 'vcvarsall.bat'))
427 elif os
.path
.isfile(os
.path
.join(vc_path
, 'vcvarsall.bat')):
428 for target
,realtarget
in all_msvc_platforms
[::-1]:
429 targets
[target
] = target_compiler(conf
, 'msvc', realtarget
, version
, target
, os
.path
.join(vc_path
, 'vcvarsall.bat'))
430 elif os
.path
.isfile(os
.path
.join(vc_path
, 'Common7', 'Tools', 'vsvars32.bat')):
431 targets
['x86'] = target_compiler(conf
, 'msvc', 'x86', version
, 'x86', os
.path
.join(vc_path
, 'Common7', 'Tools', 'vsvars32.bat'))
432 elif os
.path
.isfile(os
.path
.join(vc_path
, 'Bin', 'vcvars32.bat')):
433 targets
['x86'] = target_compiler(conf
, 'msvc', 'x86', version
, '', os
.path
.join(vc_path
, 'Bin', 'vcvars32.bat'))
435 versions
['msvc %s' % version
] = targets
438 def gather_wince_targets(conf
, versions
, version
, vc_path
, vsvars
, supported_platforms
):
439 #Looking for Win CE compilers!
440 for device
,platforms
in supported_platforms
:
442 for platform
,compiler
,include
,lib
in platforms
:
443 winCEpath
= os
.path
.join(vc_path
, 'ce')
444 if not os
.path
.isdir(winCEpath
):
447 if os
.path
.isdir(os
.path
.join(winCEpath
, 'lib', platform
)):
448 bindirs
= [os
.path
.join(winCEpath
, 'bin', compiler
), os
.path
.join(winCEpath
, 'bin', 'x86_'+compiler
)]
449 incdirs
= [os
.path
.join(winCEpath
, 'include'), os
.path
.join(winCEpath
, 'atlmfc', 'include'), include
]
450 libdirs
= [os
.path
.join(winCEpath
, 'lib', platform
), os
.path
.join(winCEpath
, 'atlmfc', 'lib', platform
), lib
]
451 def combine_common(obj
, compiler_env
):
452 # TODO this is likely broken, remove in waf 2.1
453 (common_bindirs
,_1
,_2
) = compiler_env
454 return (bindirs
+ common_bindirs
, incdirs
, libdirs
)
455 targets
[platform
] = target_compiler(conf
, 'msvc', platform
, version
, 'x86', vsvars
, combine_common
)
457 versions
[device
+ ' ' + version
] = targets
460 def gather_winphone_targets(conf
, versions
, version
, vc_path
, vsvars
):
461 #Looking for WinPhone compilers
463 for target
,realtarget
in all_msvc_platforms
[::-1]:
464 targets
[target
] = target_compiler(conf
, 'winphone', realtarget
, version
, target
, vsvars
)
466 versions
['winphone ' + version
] = targets
469 def gather_vswhere_versions(conf
, versions
):
473 Logs
.error('Visual Studio 2017 detection requires Python 2.6')
476 prg_path
= os
.environ
.get('ProgramFiles(x86)', os
.environ
.get('ProgramFiles', 'C:\\Program Files (x86)'))
478 vswhere
= os
.path
.join(prg_path
, 'Microsoft Visual Studio', 'Installer', 'vswhere.exe')
479 args
= [vswhere
, '-products', '*', '-legacy', '-format', 'json']
481 txt
= conf
.cmd_and_log(args
)
482 except Errors
.WafError
as e
:
483 Logs
.debug('msvc: vswhere.exe failed %s', e
)
486 if sys
.version_info
[0] < 3:
487 txt
= txt
.decode(Utils
.console_encoding())
489 arr
= json
.loads(txt
)
490 arr
.sort(key
=lambda x
: x
['installationVersion'])
492 ver
= entry
['installationVersion']
493 ver
= str('.'.join(ver
.split('.')[:2]))
494 path
= str(os
.path
.abspath(entry
['installationPath']))
495 if os
.path
.exists(path
) and ('msvc %s' % ver
) not in versions
:
496 conf
.gather_msvc_targets(versions
, ver
, path
)
499 def gather_msvc_versions(conf
, versions
):
501 for (v
,version
,reg
) in gather_msvc_detected_versions():
504 msvc_version
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, reg
+ "\\Setup\\VC")
506 msvc_version
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, reg
+ "\\Setup\\Microsoft Visual C++")
507 path
,type = Utils
.winreg
.QueryValueEx(msvc_version
, 'ProductDir')
510 msvc_version
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, "SOFTWARE\\Wow6432node\\Microsoft\\VisualStudio\\SxS\\VS7")
511 path
,type = Utils
.winreg
.QueryValueEx(msvc_version
, version
)
515 vc_paths
.append((version
, os
.path
.abspath(str(path
))))
518 vc_paths
.append((version
, os
.path
.abspath(str(path
))))
520 wince_supported_platforms
= gather_wince_supported_platforms()
522 for version
,vc_path
in vc_paths
:
523 vs_path
= os
.path
.dirname(vc_path
)
524 vsvars
= os
.path
.join(vs_path
, 'Common7', 'Tools', 'vsvars32.bat')
525 if wince_supported_platforms
and os
.path
.isfile(vsvars
):
526 conf
.gather_wince_targets(versions
, version
, vc_path
, vsvars
, wince_supported_platforms
)
528 # WP80 works with 11.0Exp and 11.0, both of which resolve to the same vc_path.
529 # Stop after one is found.
530 for version
,vc_path
in vc_paths
:
531 vs_path
= os
.path
.dirname(vc_path
)
532 vsvars
= os
.path
.join(vs_path
, 'VC', 'WPSDK', 'WP80', 'vcvarsphoneall.bat')
533 if os
.path
.isfile(vsvars
):
534 conf
.gather_winphone_targets(versions
, '8.0', vc_path
, vsvars
)
537 for version
,vc_path
in vc_paths
:
538 vs_path
= os
.path
.dirname(vc_path
)
539 conf
.gather_msvc_targets(versions
, version
, vc_path
)
542 def gather_icl_versions(conf
, versions
):
546 :param versions: list to modify
549 version_pattern
= re
.compile(r
'^...?.?\....?.?')
551 all_versions
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, 'SOFTWARE\\Wow6432node\\Intel\\Compilers\\C++')
554 all_versions
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, 'SOFTWARE\\Intel\\Compilers\\C++')
560 version
= Utils
.winreg
.EnumKey(all_versions
, index
)
564 if not version_pattern
.match(version
):
567 for target
,arch
in all_icl_platforms
:
568 if target
=='intel64':
569 targetDir
='EM64T_NATIVE'
573 Utils
.winreg
.OpenKey(all_versions
,version
+'\\'+targetDir
)
574 icl_version
=Utils
.winreg
.OpenKey(all_versions
,version
)
575 path
,type=Utils
.winreg
.QueryValueEx(icl_version
,'ProductDir')
579 batch_file
=os
.path
.join(path
,'bin','iclvars.bat')
580 if os
.path
.isfile(batch_file
):
581 targets
[target
] = target_compiler(conf
, 'intel', arch
, version
, target
, batch_file
)
582 for target
,arch
in all_icl_platforms
:
584 icl_version
= Utils
.winreg
.OpenKey(all_versions
, version
+'\\'+target
)
585 path
,type = Utils
.winreg
.QueryValueEx(icl_version
,'ProductDir')
589 batch_file
=os
.path
.join(path
,'bin','iclvars.bat')
590 if os
.path
.isfile(batch_file
):
591 targets
[target
] = target_compiler(conf
, 'intel', arch
, version
, target
, batch_file
)
593 versions
['intel ' + major
] = targets
596 def gather_intel_composer_versions(conf
, versions
):
598 Checks ICL compilers that are part of Intel Composer Suites
600 :param versions: list to modify
603 version_pattern
= re
.compile(r
'^...?.?\...?.?.?')
605 all_versions
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, 'SOFTWARE\\Wow6432node\\Intel\\Suites')
608 all_versions
= Utils
.winreg
.OpenKey(Utils
.winreg
.HKEY_LOCAL_MACHINE
, 'SOFTWARE\\Intel\\Suites')
614 version
= Utils
.winreg
.EnumKey(all_versions
, index
)
618 if not version_pattern
.match(version
):
621 for target
,arch
in all_icl_platforms
:
622 if target
=='intel64':
623 targetDir
='EM64T_NATIVE'
628 defaults
= Utils
.winreg
.OpenKey(all_versions
,version
+'\\Defaults\\C++\\'+targetDir
)
630 if targetDir
== 'EM64T_NATIVE':
631 defaults
= Utils
.winreg
.OpenKey(all_versions
,version
+'\\Defaults\\C++\\EM64T')
634 uid
,type = Utils
.winreg
.QueryValueEx(defaults
, 'SubKey')
635 Utils
.winreg
.OpenKey(all_versions
,version
+'\\'+uid
+'\\C++\\'+targetDir
)
636 icl_version
=Utils
.winreg
.OpenKey(all_versions
,version
+'\\'+uid
+'\\C++')
637 path
,type=Utils
.winreg
.QueryValueEx(icl_version
,'ProductDir')
641 batch_file
=os
.path
.join(path
,'bin','iclvars.bat')
642 if os
.path
.isfile(batch_file
):
643 targets
[target
] = target_compiler(conf
, 'intel', arch
, version
, target
, batch_file
)
644 # The intel compilervar_arch.bat is broken when used with Visual Studio Express 2012
645 # http://software.intel.com/en-us/forums/topic/328487
646 compilervars_warning_attr
= '_compilervars_warning_key'
647 if version
[0:2] == '13' and getattr(conf
, compilervars_warning_attr
, True):
648 setattr(conf
, compilervars_warning_attr
, False)
649 patch_url
= 'http://software.intel.com/en-us/forums/topic/328487'
650 compilervars_arch
= os
.path
.join(path
, 'bin', 'compilervars_arch.bat')
651 for vscomntool
in ('VS110COMNTOOLS', 'VS100COMNTOOLS'):
652 if vscomntool
in os
.environ
:
653 vs_express_path
= os
.environ
[vscomntool
] + r
'..\IDE\VSWinExpress.exe'
654 dev_env_path
= os
.environ
[vscomntool
] + r
'..\IDE\devenv.exe'
655 if (r
'if exist "%VS110COMNTOOLS%..\IDE\VSWinExpress.exe"' in Utils
.readf(compilervars_arch
) and
656 not os
.path
.exists(vs_express_path
) and not os
.path
.exists(dev_env_path
)):
657 Logs
.warn(('The Intel compilervar_arch.bat only checks for one Visual Studio SKU '
658 '(VSWinExpress.exe) but it does not seem to be installed at %r. '
659 'The intel command line set up will fail to configure unless the file %r'
660 'is patched. See: %s') % (vs_express_path
, compilervars_arch
, patch_url
))
662 versions
['intel ' + major
] = targets
665 def detect_msvc(self
):
666 return self
.setup_msvc(self
.get_msvc_versions())
669 def get_msvc_versions(self
):
671 :return: platform to compiler configurations
674 dct
= Utils
.ordered_iter_dict()
675 self
.gather_icl_versions(dct
)
676 self
.gather_intel_composer_versions(dct
)
677 self
.gather_wsdk_versions(dct
)
678 self
.gather_msvc_versions(dct
)
679 self
.gather_vswhere_versions(dct
)
680 Logs
.debug('msvc: detected versions %r', list(dct
.keys()))
684 def find_lt_names_msvc(self
, libname
, is_static
=False):
686 Win32/MSVC specific code to glean out information from libtool la files.
687 this function is not attached to the task_gen class. Returns a triplet:
688 (library absolute path, library name without extension, whether the library is static)
691 'lib%s.la' % libname
,
695 for path
in self
.env
.LIBPATH
:
697 laf
=os
.path
.join(path
,la
)
699 if os
.path
.exists(laf
):
700 ltdict
= Utils
.read_la_file(laf
)
702 if ltdict
.get('libdir', ''):
703 lt_libdir
= ltdict
['libdir']
704 if not is_static
and ltdict
.get('library_names', ''):
705 dllnames
=ltdict
['library_names'].split()
706 dll
=dllnames
[0].lower()
707 dll
=re
.sub(r
'\.dll$', '', dll
)
708 return (lt_libdir
, dll
, False)
709 elif ltdict
.get('old_library', ''):
710 olib
=ltdict
['old_library']
711 if os
.path
.exists(os
.path
.join(path
,olib
)):
712 return (path
, olib
, True)
713 elif lt_libdir
!= '' and os
.path
.exists(os
.path
.join(lt_libdir
,olib
)):
714 return (lt_libdir
, olib
, True)
716 return (None, olib
, True)
718 raise self
.errors
.WafError('invalid libtool object file: %s' % laf
)
719 return (None, None, None)
722 def libname_msvc(self
, libname
, is_static
=False):
723 lib
= libname
.lower()
724 lib
= re
.sub(r
'\.lib$','',lib
)
726 if lib
in g_msvc_systemlibs
:
729 lib
=re
.sub('^lib','',lib
)
734 (lt_path
, lt_libname
, lt_static
) = self
.find_lt_names_msvc(lib
, is_static
)
736 if lt_path
!= None and lt_libname
!= None:
738 # file existence check has been made by find_lt_names
739 return os
.path
.join(lt_path
,lt_libname
)
742 _libpaths
= [lt_path
] + self
.env
.LIBPATH
744 _libpaths
= self
.env
.LIBPATH
754 'lib%s.dll.lib' % lib
,
765 libnames
=dynamic_libs
+ static_libs
767 for path
in _libpaths
:
768 for libn
in libnames
:
769 if os
.path
.exists(os
.path
.join(path
, libn
)):
770 Logs
.debug('msvc: lib found: %s', os
.path
.join(path
,libn
))
771 return re
.sub(r
'\.lib$', '',libn
)
773 #if no lib can be found, just return the libname as msvc expects it
774 self
.fatal('The library %r could not be found' % libname
)
775 return re
.sub(r
'\.lib$', '', libname
)
778 def check_lib_msvc(self
, libname
, is_static
=False, uselib_store
=None):
780 Ideally we should be able to place the lib in the right env var, either STLIB or LIB,
781 but we don't distinguish static libs from shared libs.
782 This is ok since msvc doesn't have any special linker flag to select static libs (no env.STLIB_MARKER)
784 libn
= self
.libname_msvc(libname
, is_static
)
787 uselib_store
= libname
.upper()
789 if False and is_static
: # disabled
790 self
.env
['STLIB_' + uselib_store
] = [libn
]
792 self
.env
['LIB_' + uselib_store
] = [libn
]
795 def check_libs_msvc(self
, libnames
, is_static
=False):
796 for libname
in Utils
.to_list(libnames
):
797 self
.check_lib_msvc(libname
, is_static
)
801 Configuration methods to call for detecting msvc
803 conf
.autodetect(True)
805 conf
.msvc_common_flags()
807 conf
.cxx_load_tools()
810 conf
.link_add_flags()
811 conf
.visual_studio_add_flags()
814 def no_autodetect(conf
):
815 conf
.env
.NO_MSVC_DETECT
= 1
819 def autodetect(conf
, arch
=False):
824 compiler
, version
, path
, includes
, libdirs
, cpu
= conf
.detect_msvc()
829 v
.INCLUDES
= includes
831 v
.MSVC_COMPILER
= compiler
833 v
.MSVC_VERSION
= float(version
)
835 v
.MSVC_VERSION
= float(version
[:-3])
837 def _get_prog_names(conf
, compiler
):
838 if compiler
== 'intel':
839 compiler_name
= 'ICL'
840 linker_name
= 'XILINK'
847 return compiler_name
, linker_name
, lib_name
851 """Due to path format limitations, limit operation only to native Win32. Yeah it sucks."""
852 if sys
.platform
== 'cygwin':
853 conf
.fatal('MSVC module does not work under cygwin Python!')
855 # the autodetection is supposed to be performed before entering in this method
858 compiler
= v
.MSVC_COMPILER
859 version
= v
.MSVC_VERSION
861 compiler_name
, linker_name
, lib_name
= _get_prog_names(conf
, compiler
)
862 v
.MSVC_MANIFEST
= (compiler
== 'msvc' and version
>= 8) or (compiler
== 'wsdk' and version
>= 6) or (compiler
== 'intel' and version
>= 11)
865 cxx
= conf
.find_program(compiler_name
, var
='CXX', path_list
=path
)
867 # before setting anything, check if the compiler is really msvc
868 env
= dict(conf
.environ
)
870 env
.update(PATH
= ';'.join(path
))
871 if not conf
.cmd_and_log(cxx
+ ['/nologo', '/help'], env
=env
):
872 conf
.fatal('the msvc compiler could not be identified')
876 v
.CC_NAME
= v
.CXX_NAME
= 'msvc'
880 conf
.find_program(linker_name
, path_list
=path
, errmsg
='%s was not found (linker)' % linker_name
, var
='LINK_CXX')
883 v
.LINK_CC
= v
.LINK_CXX
887 stliblink
= conf
.find_program(lib_name
, path_list
=path
, var
='AR')
890 v
.ARFLAGS
= ['/nologo']
892 # manifest tool. Not required for VS 2003 and below. Must have for VS 2005 and later
894 conf
.find_program('MT', path_list
=path
, var
='MT')
895 v
.MTFLAGS
= ['/nologo']
899 except Errors
.ConfigurationError
:
900 Logs
.warn('Resource compiler not found. Compiling resource file is disabled')
903 def visual_studio_add_flags(self
):
904 """visual studio flags found in the system environment"""
906 if self
.environ
.get('INCLUDE'):
907 v
.prepend_value('INCLUDES', [x
for x
in self
.environ
['INCLUDE'].split(';') if x
]) # notice the 'S'
908 if self
.environ
.get('LIB'):
909 v
.prepend_value('LIBPATH', [x
for x
in self
.environ
['LIB'].split(';') if x
])
912 def msvc_common_flags(conf
):
914 Setup the flags required for executing the msvc compiler
919 v
.append_value('CFLAGS', ['/nologo'])
920 v
.append_value('CXXFLAGS', ['/nologo'])
921 v
.append_value('LINKFLAGS', ['/nologo'])
922 v
.DEFINES_ST
= '/D%s'
925 v
.CC_TGT_F
= ['/c', '/Fo']
927 v
.CXX_TGT_F
= ['/c', '/Fo']
929 if (v
.MSVC_COMPILER
== 'msvc' and v
.MSVC_VERSION
>= 8) or (v
.MSVC_COMPILER
== 'wsdk' and v
.MSVC_VERSION
>= 6):
930 v
.CC_TGT_F
= ['/FC'] + v
.CC_TGT_F
931 v
.CXX_TGT_F
= ['/FC'] + v
.CXX_TGT_F
933 v
.CPPPATH_ST
= '/I%s' # template for adding include paths
935 v
.AR_TGT_F
= v
.CCLNK_TGT_F
= v
.CXXLNK_TGT_F
= '/OUT:'
938 v
.CFLAGS_CRT_MULTITHREADED
= v
.CXXFLAGS_CRT_MULTITHREADED
= ['/MT']
939 v
.CFLAGS_CRT_MULTITHREADED_DLL
= v
.CXXFLAGS_CRT_MULTITHREADED_DLL
= ['/MD']
941 v
.CFLAGS_CRT_MULTITHREADED_DBG
= v
.CXXFLAGS_CRT_MULTITHREADED_DBG
= ['/MTd']
942 v
.CFLAGS_CRT_MULTITHREADED_DLL_DBG
= v
.CXXFLAGS_CRT_MULTITHREADED_DLL_DBG
= ['/MDd']
945 v
.LIBPATH_ST
= '/LIBPATH:%s'
946 v
.STLIB_ST
= '%s.lib'
947 v
.STLIBPATH_ST
= '/LIBPATH:%s'
950 v
.append_value('LINKFLAGS', ['/MANIFEST'])
953 v
.CXXFLAGS_cxxshlib
= []
954 v
.LINKFLAGS_cshlib
= v
.LINKFLAGS_cxxshlib
= ['/DLL']
955 v
.cshlib_PATTERN
= v
.cxxshlib_PATTERN
= '%s.dll'
956 v
.implib_PATTERN
= '%s.lib'
957 v
.IMPLIB_ST
= '/IMPLIB:%s'
959 v
.LINKFLAGS_cstlib
= []
960 v
.cstlib_PATTERN
= v
.cxxstlib_PATTERN
= '%s.lib'
962 v
.cprogram_PATTERN
= v
.cxxprogram_PATTERN
= '%s.exe'
964 v
.def_PATTERN
= '/def:%s'
967 #######################################################################################################
968 ##### conf above, build below
970 @after_method('apply_link')
972 def apply_flags_msvc(self
):
974 Add additional flags implied by msvc, such as subsystems and pdb files::
977 bld.stlib(source='main.c', target='bar', subsystem='gruik')
979 if self
.env
.CC_NAME
!= 'msvc' or not getattr(self
, 'link_task', None):
982 is_static
= isinstance(self
.link_task
, ccroot
.stlink_task
)
984 subsystem
= getattr(self
, 'subsystem', '')
986 subsystem
= '/subsystem:%s' % subsystem
987 flags
= is_static
and 'ARFLAGS' or 'LINKFLAGS'
988 self
.env
.append_value(flags
, subsystem
)
991 for f
in self
.env
.LINKFLAGS
:
993 if d
[1:] in ('debug', 'debug:full', 'debug:fastlink'):
994 pdbnode
= self
.link_task
.outputs
[0].change_ext('.pdb')
995 self
.link_task
.outputs
.append(pdbnode
)
997 if getattr(self
, 'install_task', None):
998 self
.pdb_install_task
= self
.add_install_files(
999 install_to
=self
.install_task
.install_to
, install_from
=pdbnode
)
1002 @feature('cprogram', 'cshlib', 'cxxprogram', 'cxxshlib')
1003 @after_method('apply_link')
1004 def apply_manifest(self
):
1006 Special linker for MSVC with support for embedding manifests into DLL's
1007 and executables compiled by Visual Studio 2005 or probably later. Without
1008 the manifest file, the binaries are unusable.
1009 See: http://msdn2.microsoft.com/en-us/library/ms235542(VS.80).aspx
1011 if self
.env
.CC_NAME
== 'msvc' and self
.env
.MSVC_MANIFEST
and getattr(self
, 'link_task', None):
1012 out_node
= self
.link_task
.outputs
[0]
1013 man_node
= out_node
.parent
.find_or_declare(out_node
.name
+ '.manifest')
1014 self
.link_task
.outputs
.append(man_node
)
1015 self
.env
.DO_MANIFEST
= True
1017 def make_winapp(self
, family
):
1018 append
= self
.env
.append_unique
1019 append('DEFINES', 'WINAPI_FAMILY=%s' % family
)
1020 append('CXXFLAGS', ['/ZW', '/TP'])
1021 for lib_path
in self
.env
.LIBPATH
:
1022 append('CXXFLAGS','/AI%s'%lib_path
)
1024 @feature('winphoneapp')
1025 @after_method('process_use')
1026 @after_method('propagate_uselib_vars')
1027 def make_winphone_app(self
):
1029 Insert configuration flags for windows phone applications (adds /ZW, /TP...)
1031 make_winapp(self
, 'WINAPI_FAMILY_PHONE_APP')
1032 self
.env
.append_unique('LINKFLAGS', ['/NODEFAULTLIB:ole32.lib', 'PhoneAppModelHost.lib'])
1035 @after_method('process_use')
1036 @after_method('propagate_uselib_vars')
1037 def make_windows_app(self
):
1039 Insert configuration flags for windows applications (adds /ZW, /TP...)
1041 make_winapp(self
, 'WINAPI_FAMILY_DESKTOP_APP')