__doc__ = """Module for Visual C/C++ detection and configuration.
"""
+import SCons.compat
import os
import platform
debug = common.debug
+import sdk
+
+get_installed_sdks = sdk.get_installed_sdks
+
+
class VisualCException(Exception):
pass
host_platform = env.get('HOST_ARCH')
if not host_platform:
host_platform = platform.machine()
+ # TODO(2.5): the native Python platform.machine() function returns
+ # '' on all Python versions before 2.6, after which it also uses
+ # PROCESSOR_ARCHITECTURE.
+ if not host_platform:
+ host_platform = os.environ.get('PROCESSOR_ARCHITECTURE', '')
target_platform = env.get('TARGET_ARCH')
if not target_platform:
target_platform = host_platform
try:
host = _ARCH_TO_CANONICAL[host_platform]
except KeyError, e:
- raise ValueError("Unrecognized host architecture %s" % host_platform)
+ msg = "Unrecognized host architecture %s"
+ raise ValueError(msg % repr(host_platform))
try:
target = _ARCH_TO_CANONICAL[target_platform]
raise MissingConfiguration("registry dir %s not found on the filesystem" % comps)
return None
-def find_batch_file(msvc_version):
+def find_batch_file(env,msvc_version):
+ """
+ Find the location of the batch script which should set up the compiler
+ for any TARGET_ARCH whose compilers were installed by Visual Studio/VCExpress
+ """
pdir = find_vc_pdir(msvc_version)
if pdir is None:
raise NoVersionFound("No version of Visual Studio found")
else: # >= 8
batfilename = os.path.join(pdir, "vcvarsall.bat")
- if os.path.exists(batfilename):
- return batfilename
- else:
+ if not os.path.exists(batfilename):
debug("Not found: %s" % batfilename)
- return None
+ batfilename = None
+
+ installed_sdks=get_installed_sdks()
+ (host_arch,target_arch)=get_host_target(env)
+ for _sdk in installed_sdks:
+ #print "Trying :%s"%_sdk.vc_setup_scripts
+ sdk_bat_file=_sdk.get_sdk_vc_script(host_arch,target_arch)
+ sdk_bat_file_path=os.path.join(pdir,sdk_bat_file)
+ #print "PATH: %s"%sdk_bat_file_path
+ if os.path.exists(sdk_bat_file_path):
+ return (batfilename,sdk_bat_file_path)
+ else:
+ return (batfilename,None)
__INSTALLED_VCS_RUN = None
env['MSVS'] = {}
try:
- script = find_batch_file(version)
+ (vc_script,sdk_script) = find_batch_file(env,version)
except VisualCException, e:
msg = str(e)
debug('Caught exception while looking for batch file (%s)' % msg)
host_platform, target_platform = get_host_target(env)
host_target = (host_platform, target_platform)
if not is_host_target_supported(host_target, version):
- raise UnsupportedVersion(
- "host, target = %s not supported for MSVC version %s" %
- (host_target, version))
+ warn_msg = "host, target = %s not supported for MSVC version %s" % \
+ (host_target, version)
+ SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, warn_msg)
arg = _HOST_TARGET_ARCH_TO_BAT_ARCH[host_target]
- debug('use_script 2 %s, args:%s\n' % (repr(script), arg))
- try:
- d = script_env(script, args=arg)
- except BatchFileExecutionError, e:
- msg = "MSVC error while executing %s with args %s (error was %s)" % \
- (script, arg, str(e))
- raise SCons.Errors.UserError(msg)
+ debug('use_script 2 %s, args:%s\n' % (repr(vc_script), arg))
+ if vc_script:
+ try:
+ d = script_env(vc_script, args=arg)
+ except BatchFileExecutionError, e:
+ debug('use_script 3: failed running VC script %s: %s: Error:%s'%(repr(vc_script),arg,e))
+ vc_script=None
+ if not vc_script and sdk_script:
+ debug('use_script 4: trying sdk script: %s %s'%(sdk_script,arg))
+ try:
+ d = script_env(sdk_script,args=[])
+ except BatchFileExecutionError,e:
+ debug('use_script 5: failed running SDK script %s: Error:%s'%(repr(sdk_script),e))
+ return None
+ else:
+ debug('use_script 6: Neither VC script nor SDK script found')
+ return None
+
else:
debug('MSVC_USE_SCRIPT set to False')
warn_msg = "MSVC_USE_SCRIPT set to False, assuming environment " \