Browse Source

use auto-detection for building with Windows SDK 7.1

This is similar to what is done for building with MSVC 2008-2013
Ashish Kulkarni 11 years ago
parent
commit
580b13998c
2 changed files with 28 additions and 24 deletions
  1. 1 9
      INSTALL.md
  2. 27 15
      scripts/build.py

+ 1 - 9
INSTALL.md

@@ -16,21 +16,13 @@ Building is currently supported only on the current 64-bit Debian stable release
 Prerequisites: Windows
 ----------------------
 
-* Install Visual Studio ([2013 Express](http://www.microsoft.com/en-US/download/details.aspx?id=40787) is recommended) or follow instructions for [Windows SDK 7.1](http://qt-project.org/wiki/Category:Tools::msvc)
+* Install Visual Studio 2008 or later ([2013 Express](http://www.microsoft.com/en-US/download/details.aspx?id=40787) is recommended) or follow instructions for [Windows SDK 7.1](http://qt-project.org/wiki/Category:Tools::msvc)
 * Do "Windows Update" to ensure that VC/SDK security patches are up-to-date
 * Install latest ActivePerl from http://www.activestate.com/activeperl/downloads
 * Install latest Python 2.7 from http://www.python.org/downloads/windows/
 * Install NSIS 2.46 from http://nsis.sourceforge.net/Download
 * Make sure that you can run "git". If not, add it to the PATH or reinstall
   with option "Run Git from the Windows Command Prompt".
-* **Skip this step if you are using Visual Studio**. If you are using Windows SDK 7.1, then start "Windows SDK 7.1 Command Prompt" for "Windows Server 2008 Release".
-  A 32-bit environment is available by running (all on one line)
-
-      %WINDIR%\System32\cmd.exe /E:ON /V:ON /T:0E /K "%ProgramFiles%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /2008 /Release /x86
-
-  or alternatively, a 64-bit environment can be started by running:
-
-      %WINDIR%\System32\cmd.exe /E:ON /V:ON /T:0E /K "%ProgramFiles%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /2008 /Release /x64
 
 Building
 --------

+ 27 - 15
scripts/build.py

@@ -308,31 +308,43 @@ def build_msvc(config, basedir, clean, debug):
 
     os.environ.update(eval(stdout.strip()))
 
-    build_msvc_winsdk71(config, basedir, clean, debug)
+    build_msvc_common(config, basedir, clean, debug)
 
 # --------------------------------------------------------------- MSVC via Windows SDK 7.1
 
 def check_msvc_winsdk71(config):
-    for key in ['Configuration', 'TARGET_PLATFORM', 'TARGET_CPU']:
-        if not key in os.environ:
-            error("Please run under appropriate 'Windows SDK 7.1 Command Prompt'.")
+    for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
+        if pfile in os.environ and exists(os.path.join(os.environ[pfile], 'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')):
+            return
+    error("Unable to detect the location of Windows SDK 7.1")
 
-    if os.environ['TARGET_PLATFORM'] not in ['XP', 'LH', 'SRV', 'LHS']:
-        error("Please configure for 'Windows Server 2008 Release' or earlier.")
+def build_msvc_winsdk71(config, basedir, clean, debug):
+    arch = config[config.rindex('-'):]
+    setenv = None
+    for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
+        if not pfile in os.environ:
+            continue
+        setenv = os.path.join(os.environ[pfile], 'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')
 
-    if os.environ['Configuration'] != 'Release':
-        error("Please configure for release mode.")
+    mode = debug and '/Debug' or '/Release'
+    if arch == 'win64':
+        args = '/2008 /x64 %s' % mode
+    else:
+        args = '/2008 /x86 %s' % mode
 
-    if os.environ['TARGET_CPU'] not in ['x86', 'x64']:
-        error("Please configure CPU for either x86 or x64.")
+    python = sys.executable
+    process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os; print repr(os.environ)"' % (
+        setenv, args, python), stdout=subprocess.PIPE, shell=True)
+    stdout, _ = process.communicate()
+    exitcode = process.wait()
+    if exitcode != 0:
+        error("unable to initialize the environment for Windows SDK 7.1")
 
-    if os.environ['TARGET_CPU'] == 'x86' and config == 'msvc2010-win64':
-        error("Error: SDK configured for x86 but trying to build 64-bit.")
+    os.environ.update(eval(stdout.strip()))
 
-    if os.environ['TARGET_CPU'] == 'x64' and config == 'msvc2010-win32':
-        error("Error: SDK configured for x64 but trying to build 32-bit.")
+    build_msvc_common(config, basedir, clean, debug)
 
-def build_msvc_winsdk71(config, basedir, clean, debug):
+def build_msvc_common(config, basedir, clean, debug):
     if debug:
         ssl = OPENSSL['build']
         cfg = QT_CONFIG['common']