-def get_default_visualstudio_version(env):
- """Returns the version set in the env, or the latest version
- installed, if it can find it, or '6.0' if all else fails. Also
- updated the environment with what it found."""
-
- version = '6.0'
- versions = [version]
-
- if not env.has_key('MSVS') or not SCons.Util.is_Dict(env['MSVS']):
- env['MSVS'] = {}
-
- if env['MSVS'].has_key('VERSIONS'):
- versions = env['MSVS']['VERSIONS']
- elif SCons.Util.can_read_reg:
- v = get_visualstudio_versions()
- if v:
- versions = v
- if env.has_key('MSVS_VERSION'):
- version = env['MSVS_VERSION']
- else:
- version = versions[0] #use highest version by default
-
- env['MSVS_VERSION'] = version
- env['MSVS']['VERSIONS'] = versions
- env['MSVS']['VERSION'] = version
- else:
- version = env['MSVS']['VERSION']
-
- return version
-
-def get_visualstudio_versions():
- """
- Get list of visualstudio versions from the Windows registry.
- Returns a list of strings containing version numbers. An empty list
- is returned if we were unable to accees the register (for example,
- we couldn't import the registry-access module) or the appropriate
- registry keys weren't found.
- """
-
- if not SCons.Util.can_read_reg:
- return []
-
- HLM = SCons.Util.HKEY_LOCAL_MACHINE
- KEYS = {
- r'Software\Microsoft\VisualStudio' : '',
- r'Software\Microsoft\VCExpress' : 'Exp',
- }
- L = []
- for K, suite_suffix in KEYS.items():
- try:
- k = SCons.Util.RegOpenKeyEx(HLM, K)
- i = 0
- while 1:
- try:
- p = SCons.Util.RegEnumKey(k,i)
- except SCons.Util.RegError:
- break
- i = i + 1
- if not p[0] in '123456789' or p in L:
- continue
- # Only add this version number if there is a valid
- # registry structure (includes the "Setup" key),
- # and at least some of the correct directories
- # exist. Sometimes VS uninstall leaves around
- # some registry/filesystem turds that we don't
- # want to trip over. Also, some valid registry
- # entries are MSDN entries, not MSVS ('7.1',
- # notably), and we want to skip those too.
- try:
- SCons.Util.RegOpenKeyEx(HLM, K + '\\' + p + '\\Setup')
- except SCons.Util.RegError:
- continue
-
- id = []
- idk = SCons.Util.RegOpenKeyEx(HLM, K + '\\' + p)
- # This is not always here -- it only exists if the
- # user installed into a non-standard location (at
- # least in VS6 it works that way -- VS7 seems to
- # always write it)
- try:
- id = SCons.Util.RegQueryValueEx(idk, 'InstallDir')
- except SCons.Util.RegError:
- pass
-
- # If the InstallDir key doesn't exist,
- # then we check the default locations.
- # Note: The IDE's executable is not devenv.exe for VS8 Express.
- if not id or not id[0]:
- files_dir = SCons.Platform.win32.get_program_files_dir()
- version_num, suite = msvs_parse_version(p)
- if version_num < 7.0:
- vs = r'Microsoft Visual Studio\Common\MSDev98'
- elif version_num < 8.0:
- vs = r'Microsoft Visual Studio .NET\Common7\IDE'
- else:
- vs = r'Microsoft Visual Studio 8\Common7\IDE'
- id = [ os.path.join(files_dir, vs) ]
- if os.path.exists(id[0]):
- L.append(p + suite_suffix)
- except SCons.Util.RegError:
- pass
-
- if not L:
- return []
-
- # This is a hack to get around the fact that certain Visual Studio
- # patches place a "6.1" version in the registry, which does not have
- # any of the keys we need to find include paths, install directories,
- # etc. Therefore we ignore it if it is there, since it throws all
- # other logic off.
- try:
- L.remove("6.1")
- except ValueError:
- pass
-
- L.sort()
- L.reverse()
-
- return L
-
-def get_default_visualstudio8_suite(env):
- """
- Returns the Visual Studio 2005 suite identifier set in the env, or the
- highest suite installed.
- """
- if not env.has_key('MSVS') or not SCons.Util.is_Dict(env['MSVS']):
- env['MSVS'] = {}
-
- if env.has_key('MSVS_SUITE'):
- suite = env['MSVS_SUITE'].upper()
- suites = [suite]
- else:
- suite = 'EXPRESS'
- suites = [suite]
- if SCons.Util.can_read_reg:
- suites = get_visualstudio8_suites()
- if suites:
- suite = suites[0] #use best suite by default
-
- env['MSVS_SUITE'] = suite
- env['MSVS']['SUITES'] = suites
- env['MSVS']['SUITE'] = suite
-
- return suite
-
-def get_visualstudio8_suites():
- """
- Returns a sorted list of all installed Visual Studio 2005 suites found
- in the registry. The highest version should be the first entry in the list.
- """
-
- suites = []
-
- # Detect Standard, Professional and Team edition
- try:
- idk = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,
- r'Software\Microsoft\VisualStudio\8.0')
- id = SCons.Util.RegQueryValueEx(idk, 'InstallDir')
- editions = { 'PRO': r'Setup\VS\Pro' } # ToDo: add standard and team editions
- edition_name = 'STD'
- for name, key_suffix in editions.items():
- try:
- idk = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,
- r'Software\Microsoft\VisualStudio\8.0' + '\\' + key_suffix )
- edition_name = name
- except SCons.Util.RegError:
- pass
- suites.append(edition_name)
- except SCons.Util.RegError:
- pass
-
- # Detect Expression edition
- try:
- idk = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,
- r'Software\Microsoft\VCExpress\8.0')
- id = SCons.Util.RegQueryValueEx(idk, 'InstallDir')
- suites.append('EXPRESS')
- except SCons.Util.RegError:
- pass
-
- return suites
-
-def is_msvs_installed():
- """
- Check the registry for an installed visual studio.
- """
- try:
- v = SCons.Tool.msvs.get_visualstudio_versions()
- return v
- except (SCons.Util.RegError, SCons.Errors.InternalError):
- return 0
-
-def get_msvs_install_dirs(version = None):
- """
- Get installed locations for various msvc-related products, like the .NET SDK
- and the Platform SDK.
- """
-
- if not SCons.Util.can_read_reg:
- return {}
-
- if not version:
- versions = get_visualstudio_versions()
- if versions:
- version = versions[0] #use highest version by default
- else:
- return {}
-
- version_num, suite = msvs_parse_version(version)
-
- K = 'Software\\Microsoft\\VisualStudio\\' + str(version_num)
- if (version_num >= 8.0):
- try:
- SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE, K )
- except SCons.Util.RegError:
- K = 'Software\\Microsoft\\VCExpress\\' + str(version_num)
-
- # vc++ install dir
- rv = {}
- if (version_num < 7.0):
- key = K + r'\Setup\Microsoft Visual C++\ProductDir'
- else:
- key = K + r'\Setup\VC\ProductDir'
- try:
- (rv['VCINSTALLDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE, key)
- except SCons.Util.RegError:
- pass
-
- # visual studio install dir
- if (version_num < 7.0):
- try:
- (rv['VSINSTALLDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
- K + r'\Setup\Microsoft Visual Studio\ProductDir')
- except SCons.Util.RegError:
- pass
-
- if not rv.has_key('VSINSTALLDIR') or not rv['VSINSTALLDIR']:
- if rv.has_key('VCINSTALLDIR') and rv['VCINSTALLDIR']:
- rv['VSINSTALLDIR'] = os.path.dirname(rv['VCINSTALLDIR'])
- else:
- rv['VSINSTALLDIR'] = os.path.join(SCons.Platform.win32.get_program_files_dir(),'Microsoft Visual Studio')
- else:
- try:
- (rv['VSINSTALLDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
- K + r'\Setup\VS\ProductDir')
- except SCons.Util.RegError:
- pass
-
- # .NET framework install dir
- try:
- (rv['FRAMEWORKDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
- r'Software\Microsoft\.NETFramework\InstallRoot')
- except SCons.Util.RegError:
- pass
-
- if rv.has_key('FRAMEWORKDIR'):
- # try and enumerate the installed versions of the .NET framework.
- contents = os.listdir(rv['FRAMEWORKDIR'])
- l = re.compile('v[0-9]+.*')
- versions = []
- for entry in contents:
- if l.match(entry):
- versions.append(entry)
-
- def versrt(a,b):
- # since version numbers aren't really floats...
- aa = a[1:]
- bb = b[1:]
- aal = aa.split('.')
- bbl = bb.split('.')
- c = int(bbl[0]) - int(aal[0])
- if c == 0:
- c = int(bbl[1]) - int(aal[1])
- if c == 0:
- c = int(bbl[2]) - int(aal[2])
- return c
-
- versions.sort(versrt)
-
- rv['FRAMEWORKVERSIONS'] = versions
- # assume that the highest version is the latest version installed
- rv['FRAMEWORKVERSION'] = versions[0]
-
- # .NET framework SDK install dir
- try:
- if rv.has_key('FRAMEWORKVERSION') and rv['FRAMEWORKVERSION'][:4] == 'v1.1':
- key = r'Software\Microsoft\.NETFramework\sdkInstallRootv1.1'
- else:
- key = r'Software\Microsoft\.NETFramework\sdkInstallRoot'
-
- (rv['FRAMEWORKSDKDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,key)
-
- except SCons.Util.RegError:
- pass
-
- # MS Platform SDK dir
- try:
- (rv['PLATFORMSDKDIR'], t) = SCons.Util.RegGetValue(SCons.Util.HKEY_LOCAL_MACHINE,
- r'Software\Microsoft\MicrosoftSDK\Directories\Install Dir')
- except SCons.Util.RegError:
- pass
-
- if rv.has_key('PLATFORMSDKDIR'):
- # if we have a platform SDK, try and get some info on it.
- vers = {}
- try:
- loc = r'Software\Microsoft\MicrosoftSDK\InstalledSDKs'
- k = SCons.Util.RegOpenKeyEx(SCons.Util.HKEY_LOCAL_MACHINE,loc)
- i = 0
- while 1:
- try:
- key = SCons.Util.RegEnumKey(k,i)
- sdk = SCons.Util.RegOpenKeyEx(k,key)
- j = 0
- name = ''
- date = ''
- version = ''
- while 1:
- try:
- (vk,vv,t) = SCons.Util.RegEnumValue(sdk,j)
- if vk.lower() == 'keyword':
- name = vv
- if vk.lower() == 'propagation_date':
- date = vv
- if vk.lower() == 'version':
- version = vv
- j = j + 1
- except SCons.Util.RegError:
- break
- if name:
- vers[name] = (date, version)
- i = i + 1
- except SCons.Util.RegError:
- break
- rv['PLATFORMSDK_MODULES'] = vers
- except SCons.Util.RegError:
- pass
-
- return rv
-