Edd Dawson avatar Edd Dawson committed 0a9a569

Fixed generated NTDDI_VERSION macro and improved deduction of other Windows version numbers

Comments (0)

Files changed (2)

doozerlib/kitbox/mscl.py

 from os.path import basename, dirname, splitext, join
 
 class Compiler(doozerlib.kit.Compiler):
-    def __init__(self, name, is_cpp, env_prefixes, cl_version, winver, subdir):
+    def __init__(self, name, is_cpp, env_prefixes, cl_version, ntver, subdir):
         doozerlib.kit.Compiler.__init__(self, name)
 
         self.is_cpp = is_cpp
         self.env = ms.create_merged_environment(env_prefixes)
         self.cl_version = cl_version
-        self.winver = winver
+        self.ntver = ntver
         self.obj_subdir = subdir
         self._header_paths = filter(None, (self.env.get('INCLUDE') or '').split(';'))
 
 
 
 class CompilerFactory(object):
-    def __init__(self, is_cpp, env_prefixes, cl_version, winver):
+    def __init__(self, is_cpp, env_prefixes, cl_version, ntver):
         self.name = 'Microsoft Visual C++ compiler'
         self.env_prefixes = env_prefixes
         self.is_cpp = is_cpp
         self.cl_version = cl_version
-        self.winver = winver
+        self.ntver = ntver
 
     def create(self, threadpool, cache, subdir):
-        return Compiler(self.name, self.is_cpp, self.env_prefixes, self.cl_version, self.winver, subdir)
+        return Compiler(self.name, self.is_cpp, self.env_prefixes, self.cl_version, self.ntver, subdir)
 
 
 def deduce_compiler_version(env_prefixes):
     env_prefixes = ms.get_env_prefixes()
     vs_path = env_prefixes.get('PATH', '') + ';' + os.environ['PATH']
 
-    winver = win.target_version()
+    ntver = win.ntddi_version()
 
     compiler = proc.find('cl.exe', vs_path)
     if not compiler: 
 
     cl_version = deduce_compiler_version(env_prefixes)
 
-    ccfactory = CompilerFactory(False, env_prefixes, cl_version, winver)
-    cppfactory = CompilerFactory(True, env_prefixes, cl_version, winver)
+    ccfactory = CompilerFactory(False, env_prefixes, cl_version, ntver)
+    cppfactory = CompilerFactory(True, env_prefixes, cl_version, ntver)
 
     return (ccfactory, cppfactory)
 

doozerlib/kitbox/win/__init__.py

 
     return mj
 
+def ntddi_version():
+    return cfgvar(
+        'win.ntddi_version', 
+        default='0x05010000', # Windows XP, by default
+        description='the value of the NTDDI_VERSION macro, determining the minimum target OS'
+    )
+
 def target_version():
-    return cfgvar('win.version', default='0x501', description='the earliest version of Windows being targeted') # Windows XP/Server 2003, by default
+    ntver = ntddi_version
+    if isinstance(ntver, basestring):
+        if ntver.upper().startswith('0X'): ntver = int(ntver, 16)
+        else: ntver = int(ntver)
+
+    winver = 0x501
+    if   0x05000000 <= ntver < 0x05010000: winver = 0x500
+    elif 0x05010000 <= ntver < 0x05010200: winver = 0x501
+    elif 0x05010200 <= ntver < 0x05020000: winver = 0x502
+    elif 0x05020000 <= ntver < 0x05020100: winver = 0x501
+    elif 0x05020100 <= ntver < 0x06000000: winver = 0x502
+    elif 0x06000000 <= ntver < 0x06010000: winver = 0x600
+    elif ntver >= 0x06010000: winver = 0x601
+
+    winver = hex(winver)
+
+    return cfgvar(
+        'win.version', 
+        default=winver, 
+        description='the earliest version of Windows being targeted'
+    )
+
+def ie_version():
+    winver = target_version()
+    if isinstance(winver, basestring):
+        if winver.upper().startswith('0X'): winver = int(winver, 16)
+        else: winver = int(winver)
+
+    if   winver <= 0x400: iever = 0x500
+    elif winver <= 0x500: iever = 0x501
+    elif winver <= 0x501: iever = 0x600
+    elif winver <  0x600: iever = 0x602
+    else: iever = 0x800
+
+    return cfgvar(
+        'win.ie_version',
+        default=hex(iever),
+        description='the value of the _WIN32_IE macro, indicating the minimum version of IE that must be on a target machine'
+    ) 
 
 def add_win32_defines_to_flagsmap(flagsmap, target_is_windows_predicate):
-    versionmacros = ['WINVER', '_WIN32_WINNT', '_WIN32_WINDOWS', '_WIN32_IE', 'NTDDI_VERSION']
+    versionmacros = ['WINVER', '_WIN32_WINNT', '_WIN32_WINDOWS']
 
     class AppendWindowsDefines(object):
         def __call__(self, options):
             # According to Raymond Chen, NTDDI_VERSION should be sufficient but there are reports 
             # that it isn't always, so let's play it safe.
             # http://blogs.msdn.com/b/oldnewthing/archive/2007/04/11/2079137.aspx
+            ntddiver = ntddi_version()
+            if isinstance(ntddiver, int): ntddiver = hex(ntddiver)
+            options.defines.append('NTDDI_VERSION=%s' % ntddiver)
+
             winver = target_version()
             if isinstance(winver, int): winver = hex(winver)
             options.defines += ['%s=%s' % (d, winver) for d in versionmacros]
+
+            iever = ie_version()
+            if isinstance(iever, int): iever = hex(iever)
+            options.defines.append('_WIN32_IE=%s' % iever)
+
             return True
 
         def __str__(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.