dtarditi created this revision.
dtarditi added a reviewer: hans.
Herald added subscribers: delcypher, mgorny.

Add support for integrating clang as a platform toolset for Visual Studio 2017.

In prior versions of Visual Studio, MSBuild was installed separately in its own 
known directory location and the platform toolset information was placed within 
that direcotry.  In VS2017, MSBuild is installed in the VS 2017 directory and 
the platform toolset information is placed in a different directory within the 
VS 2017 directory.  Use the vswhere program 
(https://github.com/Microsoft/vswhere) to locate the installation of VS 2017.   
vswhere is guaranteed to be placed in a known location on a machine, and can 
then be used to locate VS 2017 installs.   With that information we can install 
the .props and .targets files for MSBuild.   These are slightly modified 
versions of the (misnamed) VS 2014 files.

Visual Studio allows side-by-side installations, including installations of 
different products (Community, Professional, and Enterprise) with the same 
version and the same product with the same version.   For now, just use the 
latest version of VS 2017 in the install and uninstall scripts, so we get 
predictable behavior.   We leave it as future work for someone else to deal 
with side-by-side installs.

Testing:  this change is being backported from 
https://github.com/Microsoft/checkedc-llvm.    Other people have tried out the 
change there and it has worked for them.  I locally built a clean version of 
the Windows LLVM installer with the backported change and tried it out.  It 
worked fine.


Repository:
  rC Clang

https://reviews.llvm.org/D48886

Files:
  tools/msbuild/CMakeLists.txt
  tools/msbuild/install.bat
  tools/msbuild/toolset-vs2017.targets
  tools/msbuild/toolset-vs2017_xp.targets
  tools/msbuild/uninstall.bat
  utils/lit/lit/TestingConfig.py

Index: utils/lit/lit/TestingConfig.py
===================================================================
--- utils/lit/lit/TestingConfig.py
+++ utils/lit/lit/TestingConfig.py
@@ -37,6 +37,7 @@
             environment.update({
                     'INCLUDE' : os.environ.get('INCLUDE',''),
                     'PATHEXT' : os.environ.get('PATHEXT',''),
+                    'PROGRAMDATA' : os.environ.get('PROGRAMDATA',''),
                     'PYTHONUNBUFFERED' : '1',
                     'TEMP' : os.environ.get('TEMP',''),
                     'TMP' : os.environ.get('TMP',''),
Index: tools/msbuild/uninstall.bat
===================================================================
--- tools/msbuild/uninstall.bat
+++ tools/msbuild/uninstall.bat
@@ -66,6 +66,26 @@
 IF EXIST %D%\LLVM-vs2014_xp del %D%\LLVM-vs2014_xp\toolset.targets
 IF EXIST %D%\LLVM-vs2014_xp rmdir %D%\LLVM-vs2014_xp
 
+REM MSBuild is now under the Visual Studio installation.  VSWhere is a new executable placed in a known
+REM location that can be used to find the VS installation, starting with VS 2017 SP1
+IF EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
+  FOR /f "usebackq delims=" %%i IN (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -version 15 -property installationPath`) DO (
+    SET D="%%i\Common7\IDE\VC\VCTargets\Platforms\%PLATFORM%\PlatformToolsets"
+  )
+)
+
+REM On 32-bit Windows OSes before Windows 10, vswhere will be installed under %ProgramFiles%
+IF EXIST "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" (
+  FOR /f "usebackq delims=" %%i IN (`"%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -version 15 -property installationPath`) DO (
+    SET D="%%i\Common7\IDE\VC\VCTargets\Platforms\%PLATFORM%\PlatformToolsets"
+  )
+)
+IF EXIST %D%\LLVM-vs2017 del %D%\LLVM-vs2017\toolset.props
+IF EXIST %D%\LLVM-vs2017 del %D%\LLVM-vs2017\toolset.targets
+IF EXIST %D%\LLVM-vs2017 rmdir %D%\LLVM-vs2017
+IF EXIST %D%\LLVM-vs2017_xp del %D%\LLVM-vs2017_xp\toolset.props
+IF EXIST %D%\LLVM-vs2017_xp del %D%\LLVM-vs2017_xp\toolset.targets
+IF EXIST %D%\LLVM-vs2017_xp rmdir %D%\LLVM-vs2017_xp
 
 GOTO LOOPHEAD
 
Index: tools/msbuild/toolset-vs2017_xp.targets
===================================================================
--- tools/msbuild/toolset-vs2017_xp.targets
+++ tools/msbuild/toolset-vs2017_xp.targets
@@ -0,0 +1,21 @@
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003";>
+  <!-- Force TargetFrameworkVersion to v4.0 to support XP-->
+  <PropertyGroup>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <BeforeClCompileTargets>NoSupportCodeAnalysisXP;$(BeforeClCompileTargets)</BeforeClCompileTargets>
+  </PropertyGroup>
+
+  <Import Project="$(VCTargetsPath)\Microsoft.CppCommon.targets" />
+
+  <Target Name="NoSupportCodeAnalysisXP" Condition="'$(ErrorNoSupportCodeAnalysisXP)' != 'false'">
+    <VCMessage Condition="'$(DesignTimeBuild)' != 'true' and '@(ClCompile->AnyHaveMetadataValue('EnablePREfast', 'true'))'=='true'" Code="MSB8026" Type="Error"/>
+  </Target>
+
+  <PropertyGroup>
+    <PrepareForBuildDependsOn>CheckWindowsSDK71A;$(PrepareForBuildDependsOn)</PrepareForBuildDependsOn>
+  </PropertyGroup>
+
+  <Target Name="CheckWindowsSDK71A">
+    <VCMessage Code="MSB8003" Type="Warning" Arguments="WindowsSdkDir_71A" Condition="'$(WindowsSdkDir_71A)'=='' and '$(UseEnv)' != 'true'" />
+  </Target>
+</Project>
Index: tools/msbuild/toolset-vs2017.targets
===================================================================
--- tools/msbuild/toolset-vs2017.targets
+++ tools/msbuild/toolset-vs2017.targets
@@ -0,0 +1,3 @@
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003";>
+  <Import Project="$(VCTargetsPath)\Microsoft.CppCommon.targets" />
+</Project>
Index: tools/msbuild/install.bat
===================================================================
--- tools/msbuild/install.bat
+++ tools/msbuild/install.bat
@@ -40,6 +40,21 @@
 
 :TRY_V150
 
+REM MSBuild is now under the Visual Studio installation.  VSWhere is a new executable placed in a known
+REM location that can be used to find the VS installation, starting with VS 2017 SP1
+IF EXIST "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
+  FOR /f "usebackq delims=" %%i IN (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -prerelease -latest -version 15 -property installationPath`) DO (
+    SET D="%%i\Common7\IDE\VC\VCTargets\Platforms\%PLATFORM%\PlatformToolsets"
+  )
+)
+REM On 32-bit Windows OSes before Windows 10, vswhere will be installed under %ProgramFiles%
+IF EXIST "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" (
+  FOR /f "usebackq delims=" %%i IN (`"%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -prerelease -latest -version 15 -property installationPath`) DO (
+    SET D="%%i\Common7\IDE\VC\VCTargets\Platforms\%PLATFORM%\PlatformToolsets"
+  )
+)
+if EXIST %D% GOTO FOUND_V150
+
 GOTO PLATFORMLOOPHEAD
 
 :PLATFORMLOOPEND
@@ -110,6 +125,21 @@
 set SUCCESS=1
 GOTO TRY_V150
 
+:FOUND_V150
+REM Routine for installing v150 toolchain.
+IF NOT EXIST %D%\LLVM-vs2017 mkdir %D%\LLVM-vs2017
+IF NOT %ERRORLEVEL% == 0 GOTO FAILED
+copy %PLATFORM%\toolset-vs2017.props %D%\LLVM-vs2017\toolset.props
+IF NOT %ERRORLEVEL% == 0 GOTO FAILED
+copy %PLATFORM%\toolset-vs2017.targets %D%\LLVM-vs2017\toolset.targets
+IF NOT %ERRORLEVEL% == 0 GOTO FAILED
+IF NOT EXIST %D%\LLVM-vs2017_xp mkdir %D%\LLVM-vs2017_xp
+IF NOT %ERRORLEVEL% == 0 GOTO FAILED
+copy %PLATFORM%\toolset-vs2017_xp.props %D%\LLVM-vs2017_xp\toolset.props
+IF NOT %ERRORLEVEL% == 0 GOTO FAILED
+copy %PLATFORM%\toolset-vs2017_xp.targets %D%\LLVM-vs2017_xp\toolset.targets
+IF NOT %ERRORLEVEL% == 0 GOTO FAILED
+set SUCCESS=1
 
 :DONE
 echo Done!
Index: tools/msbuild/CMakeLists.txt
===================================================================
--- tools/msbuild/CMakeLists.txt
+++ tools/msbuild/CMakeLists.txt
@@ -12,6 +12,8 @@
     set(prop_file_v120_xp "toolset-vs2013_xp.props")
     set(prop_file_v140 "toolset-vs2014.props")
     set(prop_file_v140_xp "toolset-vs2014_xp.props")
+    set(prop_file_v141 "toolset-vs2017.props")
+    set(prop_file_v141_xp "toolset-vs2017_xp.props")
 
     if (platform STREQUAL "Win32")
       set(mflag "m32")
@@ -36,6 +38,11 @@
     configure_file(${prop_file_in} ${platform}/${prop_file_v140})
     set(VS_VERSION "v140_xp")
     configure_file(${prop_file_in} ${platform}/${prop_file_v140_xp})
+    set(VS_VERSION "v141")
+    set(MSC_VERSION "1911")
+    configure_file(${prop_file_in} ${platform}/${prop_file_v141})
+    set(VS_VERSION "v141_xp")
+    configure_file(${prop_file_in} ${platform}/${prop_file_v141_xp})
     set(VS_VERSION)
     set(MSC_VERSION)
     set(mflag)
@@ -47,14 +54,18 @@
     install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${platform}/${prop_file_v120_xp}" DESTINATION tools/msbuild/${platform})
     install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${platform}/${prop_file_v140}" DESTINATION tools/msbuild/${platform})
     install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${platform}/${prop_file_v140_xp}" DESTINATION tools/msbuild/${platform})
+    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${platform}/${prop_file_v141}" DESTINATION tools/msbuild/${platform})
+    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${platform}/${prop_file_v141_xp}" DESTINATION tools/msbuild/${platform})
 
     install(FILES "Microsoft.Cpp.Win32.LLVM-vs2010.targets" DESTINATION "tools/msbuild/${platform}" RENAME "Microsoft.Cpp.${platform}.LLVM-vs2010.targets")
     install(FILES "Microsoft.Cpp.Win32.LLVM-vs2012.targets" DESTINATION "tools/msbuild/${platform}" RENAME "Microsoft.Cpp.${platform}.LLVM-vs2012.targets")
     install(FILES "Microsoft.Cpp.Win32.LLVM-vs2012_xp.targets" DESTINATION "tools/msbuild/${platform}" RENAME "Microsoft.Cpp.${platform}.LLVM-vs2012_xp.targets")
     install(FILES "toolset-vs2013.targets" DESTINATION "tools/msbuild/${platform}")
     install(FILES "toolset-vs2013_xp.targets" DESTINATION "tools/msbuild/${platform}")
     install(FILES "toolset-vs2014.targets" DESTINATION "tools/msbuild/${platform}")
     install(FILES "toolset-vs2014_xp.targets" DESTINATION "tools/msbuild/${platform}")
+    install(FILES "toolset-vs2017.targets" DESTINATION "tools/msbuild/${platform}")
+    install(FILES "toolset-vs2017_xp.targets" DESTINATION "tools/msbuild/${platform}")
   endforeach()
 
   set(LIB_PATH_VERSION)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to