[Patch] Adding support of the PlatformToolset property to Gyp. (MSBuild AKA VS 2010/VC++ 2010 Express only)

261 views
Skip to first unread message

Alex Pakhunov

unread,
Feb 13, 2012, 3:26:36 PM2/13/12
to chromi...@chromium.org
Hi,

It looks like Gyp currently does not support the PlatformToolset property when generating MSBuild projects (VS 2010 or VC++ 2010 Express setup). This property is the standard way of specifying what version of SDK should be used to compile a project. The lack of support, probably, explains why the Build Instruction page describes needlessly hackish way of making sure that SDK 7.1 is used:

Manually registering the Platform SDK
VS2010
1. In Explorer, change the security C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\PlatformToolsets\v100\Microsoft.Cpp.Win32.v100.props to allow you to write to it (will require administrative priviledges).
2. Edit the file and replace v7.0A with v7.1
3. Restart Visual Studio 2010.

There are a couple ways of how the PlatformToolset property can be specified:
  1. When building using MSBuild.exe it can be passed from the command line: "msbuild.exe ... /p:PlatformToolset=Windows7.1SDK". Unfortunately this does not work when building using devenv.exe or from Visual Studio UI.
  2. It can be specified in the project itself before "$(VCTargetsPath)\Microsoft.Cpp.props" is included.
<PropertyGroup Label="Locals">
<PlatformToolset>Windows7.1SDK</PlatformToolset>
</PropertyGroup>

The second option requires patching Gyp hence the attached patch. The patch allows to specify the PlatformToolset property by either setting GYP_MSVS_TOOLSET=<toolset name> in the environment or by passing msvs_toolset=<toolset name> via generator attributes (... -G msvs_toolset=Windows7.1SDK). The -G flag is considered first. If msvs_toolset is not specified the PlatformToolset property is not emitted letting MSBuild to use the default toolset. This change affects only MSBuild projects (i.e. vcxproj).


In the case this patch is taken in, SDK-related instructions at the Build Instruction page can be simplified to: "set GYP_MSVS_TOOLSET=Windows7.1SDK".


There is also another related minor issue on the page. The described way of adding DirectX and WDK includes and library paths overwrites default SDK include and library paths. It is a minor issue because at the moment the paths for v100 and Windows7.1SDK are "compatible". However to set the paths properly the user-defined properties files should be edited in the following way:

The files are located here:
  • %LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props
  • %LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.x64.user.props
They are created when edited via Visual Studio UI or they can be created manually. The contents of the files should look like this:

Microsoft.Cpp.Win32.user.props:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <IncludePath>$(DXSDK_DIR)\include;$(IncludePath);$(WDK_DIR)\inc\atl71;$(WDK_DIR)\inc\mfc42</IncludePath>
    <LibraryPath>$(DXSDK_DIR)\lib\x86;$(LibraryPath);$(WDK_DIR)\lib\ATL\i386</LibraryPath>
  </PropertyGroup>
</Project>
 
Microsoft.Cpp.x64.user.props:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <IncludePath>$(DXSDK_DIR)\include;$(IncludePath);$(WDK_DIR)\inc\atl71;$(WDK_DIR)\inc\mfc42</IncludePath>
    <LibraryPath>$(DXSDK_DIR)\lib\x64;$(LibraryPath);$(WDK_DIR)\lib\ATL\amd64</LibraryPath>
  </PropertyGroup>
</Project>

Obviously WDK includes and libraries are needed only for Express versions of Visual Studio. Note that the paths are recursive - they include paths set up by chosen SDK configuration.

Alex.
0001-Added-support-of-the-PlatformToolset-property-to-Gyp.patch

Nico Weber

unread,
Feb 13, 2012, 3:40:12 PM2/13/12
to alex...@google.com, chromi...@chromium.org
Hi Alex,

this looks like a good idea to me. You can upload your patch to
rietveld and send it out for review, or send an email to gyp-developer
if you want to discuss more first. chromium-dev isn't really the right
place for this :-)

Nico

> --
> Chromium Developers mailing list: chromi...@chromium.org
> View archives, change email options, or unsubscribe:
> http://groups.google.com/a/chromium.org/group/chromium-dev

Reply all
Reply to author
Forward
0 new messages