Support VS2017 for Building UWP 85/23985/1
authorC.J. Collier <cjcollier@linuxfoundation.org>
Tue, 23 Jan 2018 23:13:41 +0000 (15:13 -0800)
committerC.J. Collier <cjcollier@linuxfoundation.org>
Tue, 23 Jan 2018 23:13:41 +0000 (15:13 -0800)
Add support for building iotivity UWP with Visual Studio 2017
This is a manual rebase of Ibrahim Esmat's 23629 to master

Change-Id: I2025aca430deb61e0e3de379cc2c4f48452cff5b
Signed-off-by: C.J. Collier <cjcollier@linuxfoundation.org>
build_common/SConscript
build_common/windows/SConscript
resource/IPCA/samples/ElevatorClientUWP/ElevatorClientUWP.vcxproj

index f937815..d96331d 100644 (file)
@@ -236,14 +236,13 @@ if target_os == 'windows':
     # Builds differ based on Visual Studio version
     #   For VS2013, MSVC_VERSION is '12.0'.
     #   For VS2015, MSVC_VERSION is '14.0'.
-    #   For VS2017, MSVC_VERSION is '15.0'.
+    #   For VS2017, MSVC_VERSION is '14.1'.
     # Default value is None, which means SCons will pick
     help_vars.Add(
         EnumVariable('MSVC_VERSION',
                      'MSVC compiler version - Windows',
                      default=None,
-                     allowed_values=('12.0', '14.0')))
-                     #TODO allowed_values=('12.0', '14.0', '15.0')))
+                     allowed_values=('12.0', '14.0', '14.1')))
     help_vars.Add(
         EnumVariable('MSVC_UWP_APP',
                      'Build a Universal Windows Platform (UWP) Application',
index fbd8b8d..a6613b8 100644 (file)
@@ -5,9 +5,22 @@ Import('env')
 import os
 import winreg
 import platform
+import sys
+from SCons.Tool.MSCommon.vc import find_vc_pdir
 
 build_dir = env.get('BUILD_DIR')
 
+_SUPPORTED_UWP_MSVC_VERS = [
+    '14.1', # VS2017
+    '14.0'  # VS2015
+]
+# Note: Not a complete list, just the ones that IoTivity supports
+_VCVER_TO_VSVER = {
+    '14.1' : '15.0', # VS2017
+    '14.0' : '14.0', # VS2015
+    '12.0' : '12.0'  # VS2013
+}
+
 def OpenRegKey(env, key, sub_key, reg_view_64bit=False):
     # Default access
     reg_access_mask = winreg.KEY_READ
@@ -52,17 +65,32 @@ def ReadRegistryStringValue(env, key, sub_key, value_name, reg_view_64bit=False)
     return value
 
 def SetupMSBuildEnv(env):
-    # Add MSBuild path to path
-    msbuild_reg_path = 'SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\' + env.get('MSVC_VERSION')
-    # MSBuild executable arch needs to be the same as the python/SCons environment Arch.
-    # Open the Registry key with the same registry view as the environment (handled by the
-    # winreg.OpenKey function)
-    msbuild_path = env.ReadRegistryStringValue(winreg.HKEY_LOCAL_MACHINE,
-                                               msbuild_reg_path,
-                                               'MSBuildToolsPath')
+    msbuild_path = None
+    msvc_version = env.get('MSVC_VERSION')
+    if msvc_version == '14.1':
+        # VS2017
+        vs_ver = _VCVER_TO_VSVER[msvc_version]
+        vc_dir = find_vc_pdir(msvc_version)
+        msbuild_path = os.path.join(vc_dir, '..', 'MSBuild', vs_ver, 'Bin')
+        # Find python's arch
+        (bits, linkage) = platform.architecture()
+        if '64' in bits:
+            # Running in 64bit python. That means we can run the 64bit msbuild.exe
+            msbuild_path = os.path.join(msbuild_path, 'amd64')
+    else:
+        # VS2015 and below
+        msbuild_reg_path = 'SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\' + msvc_version
+        # MSBuild executable arch needs to be the same as the python/SCons environment Arch.
+        # Open the Registry key with the same registry view as the environment (handled by the
+        # winreg.OpenKey function)
+        msbuild_path = env.ReadRegistryStringValue(winreg.HKEY_LOCAL_MACHINE,
+                                                   msbuild_reg_path,
+                                                   'MSBuildToolsPath')
+
     if not msbuild_path:
         Exit('Error: Could not Find the MSBuild Registry Key/Value')
 
+    # Add MSBuild path to path
     env.AppendUnique(PATH = [msbuild_path])
     # Need to update the 'ENV' dictionary PATH as that's what is used when executing
     # commands
@@ -89,17 +117,22 @@ def GetMSBuildArgs(env):
 def MSBuildGenerator(source, target, env, for_signature):
     env.SetupMSBuildEnv()
     (configuration, platform, outdir) = env.GetMSBuildArgs()
+    vs_ver = _VCVER_TO_VSVER[env.get('MSVC_VERSION')]
 
     msbuild_cmd = 'msbuild.exe %s /p:Configuration=%s /p:Platform=%s /p:OutDir="%s"' \
                   % (source[0], configuration, platform, outdir)
+    msbuild_cmd += ' /p:VisualStudioVersion=%s /fileLogger /fileloggerparameters:LogFile="%s"' \
+                   % (vs_ver, os.path.join(outdir, source[0].name + '.log'))
     return msbuild_cmd
 
 def MSBuildClean(env, target, solutionfile):
     env.SetupMSBuildEnv()
     (configuration, platform, outdir) = env.GetMSBuildArgs()
+    vs_ver = _VCVER_TO_VSVER[env.get('MSVC_VERSION')]
 
-    msbuild_cmd = 'msbuild.exe %s /p:Configuration=%s /p:Platform=%s /p:OutDir="%s" /t:Clean' \
+    msbuild_cmd = 'msbuild.exe %s /p:Configuration=%s /p:Platform=%s /p:OutDir="%s"' \
                   % (solutionfile, configuration, platform, outdir)
+    msbuild_cmd += ' /p:VisualStudioVersion=%s /t:Clean' % (vs_ver)
     env.Execute(msbuild_cmd)
 
 if env.get('MSVC_UWP_APP') == '1':
@@ -121,11 +154,8 @@ if env.get('MSVC_UWP_APP') == '1':
 # Set common flags
 if env['CC'] == 'cl':
     if env.get('MSVC_UWP_APP') == '1':
-        # Currently only supports VS2015 (14.0)
-        # TODO add VS2017 (15.0)
-        supported_uwp_msvc_versions = ['14.0']
         # If MSVC_VERSION is not supported for UWP, exit on error
-        if env.get('MSVC_VERSION') not in supported_uwp_msvc_versions:
+        if env.get('MSVC_VERSION') not in _SUPPORTED_UWP_MSVC_VERS:
             msg = '\nError: Trying to Build UWP binaries with unsupported Visual Studio version\n'
             Exit(msg)
 
index a4a3b43..9d5ba49 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>\r
-<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
   <PropertyGroup Label="Globals">\r
     <ProjectGuid>{d30ae502-76ee-4061-87a3-c7142283d03e}</ProjectGuid>\r
     <RootNamespace>ElevatorClientUWP</RootNamespace>\r
@@ -7,7 +7,11 @@
     <MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>\r
     <AppContainerApplication>true</AppContainerApplication>\r
     <ApplicationType>Windows Store</ApplicationType>\r
-    <WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>\r
+    <!-- Use the SDK that is installed on the Jenkins builds -->\r
+    <!-- For Visual Studio 2015, use SDK 10.0.14393 -->\r
+    <WindowsTargetPlatformVersion Condition="'$(VisualStudioVersion)'=='14.0'">10.0.14393.0</WindowsTargetPlatformVersion>\r
+    <!-- For Visual Studio 2017, use SDK 10.0.15063 -->\r
+    <WindowsTargetPlatformVersion Condition="'$(VisualStudioVersion)'=='15.0'">10.0.15063.0</WindowsTargetPlatformVersion>\r
     <WindowsTargetPlatformMinVersion>10.0.10586.0</WindowsTargetPlatformMinVersion>\r
     <ApplicationTypeRevision>10.0</ApplicationTypeRevision>\r
     <PackageCertificateThumbprint>1D05309EEC0622608A78ABCCA0E20C7528C4C79E</PackageCertificateThumbprint>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>true</UseDebugLibraries>\r
-    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>true</UseDebugLibraries>\r
-    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>true</UseDebugLibraries>\r
-    <PlatformToolset>v140</PlatformToolset>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>false</UseDebugLibraries>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
-    <PlatformToolset>v140</PlatformToolset>\r
     <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>false</UseDebugLibraries>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
-    <PlatformToolset>v140</PlatformToolset>\r
     <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>\r
   </PropertyGroup>\r
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
     <ConfigurationType>Application</ConfigurationType>\r
     <UseDebugLibraries>false</UseDebugLibraries>\r
     <WholeProgramOptimization>true</WholeProgramOptimization>\r
-    <PlatformToolset>v140</PlatformToolset>\r
     <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>\r
   </PropertyGroup>\r
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r