I need this change to create Windows 8.1/Windows Phone 8.1 projects that compile modules that can be consumed by Windows Store Applications (WinRT).

This change is required as a prerequisite to adding proper Windows Store (8.1 only) support to Google's ANGLE codebase.

Patch from coopp@microsoft.com.

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/521693002

git-svn-id: http://gyp.googlecode.com/svn/trunk@1981 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/generator/msvs.py b/pylib/gyp/generator/msvs.py
index 80e3104..517ce3c 100644
--- a/pylib/gyp/generator/msvs.py
+++ b/pylib/gyp/generator/msvs.py
@@ -83,6 +83,9 @@
     'msvs_external_builder_build_cmd',
     'msvs_external_builder_clean_cmd',
     'msvs_external_builder_clcompile_cmd',
+    'msvs_enable_winrt',
+    'msvs_requires_importlibrary',
+    'msvs_enable_winphone',
 ]
 
 
@@ -2595,15 +2598,26 @@
 
 def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):
   namespace = os.path.splitext(gyp_file_name)[0]
-  return [
+  properties = [
       ['PropertyGroup', {'Label': 'Globals'},
-       ['ProjectGuid', guid],
-       ['Keyword', 'Win32Proj'],
-       ['RootNamespace', namespace],
-       ['IgnoreWarnCompileDuplicatedFilename', 'true'],
+        ['ProjectGuid', guid],
+        ['Keyword', 'Win32Proj'],
+        ['RootNamespace', namespace],
+        ['IgnoreWarnCompileDuplicatedFilename', 'true'],
       ]
-  ]
+    ]
 
+  if spec.get('msvs_enable_winrt'):
+    properties[0].append(['DefaultLanguage', 'en-US'])
+    properties[0].append(['AppContainerApplication', 'true'])
+    properties[0].append(['ApplicationTypeRevision', '8.1'])
+
+    if spec.get('msvs_enable_winphone'):
+      properties[0].append(['ApplicationType', 'Windows Phone'])
+    else:
+      properties[0].append(['ApplicationType', 'Windows Store'])
+
+  return properties
 
 def _GetMSBuildConfigurationDetails(spec, build_file):
   properties = {}
@@ -2614,8 +2628,9 @@
     _AddConditionalProperty(properties, condition, 'ConfigurationType',
                             msbuild_attributes['ConfigurationType'])
     if character_set:
-      _AddConditionalProperty(properties, condition, 'CharacterSet',
-                              character_set)
+      if 'msvs_enable_winrt' not in spec :
+        _AddConditionalProperty(properties, condition, 'CharacterSet',
+                                character_set)
   return _GetMSBuildPropertyGroup(spec, 'Configuration', properties)
 
 
@@ -2974,6 +2989,13 @@
                 'PrecompiledHeaderFile', precompiled_header)
     _ToolAppend(msbuild_settings, 'ClCompile',
                 'ForcedIncludeFiles', [precompiled_header])
+  else:
+    _ToolAppend(msbuild_settings, 'ClCompile', 'PrecompiledHeader', 'NotUsing')
+  # Turn off WinRT compilation
+  _ToolAppend(msbuild_settings, 'ClCompile', 'CompileAsWinRT', 'false')
+  # Turn on import libraries if appropriate
+  if spec.get('msvs_requires_importlibrary'):
+   _ToolAppend(msbuild_settings, '', 'IgnoreImportLibrary', 'false')
   # Loadable modules don't generate import libraries;
   # tell dependent projects to not expect one.
   if spec['type'] == 'loadable_module':
@@ -3214,7 +3236,10 @@
   content += _GetMSBuildGlobalProperties(spec, project.guid, project_file_name)
   content += import_default_section
   content += _GetMSBuildConfigurationDetails(spec, project.build_file)
-  content += _GetMSBuildLocalProperties(project.msbuild_toolset)
+  if spec.get('msvs_enable_winphone'):
+   content += _GetMSBuildLocalProperties('v120_wp81')
+  else:
+   content += _GetMSBuildLocalProperties(project.msbuild_toolset)
   content += import_cpp_props_section
   content += _GetMSBuildExtensions(props_files_of_rules)
   content += _GetMSBuildPropertySheets(configurations)
diff --git a/test/win/enable-winrt/dllmain.cc b/test/win/enable-winrt/dllmain.cc
new file mode 100644
index 0000000..dedd83c
--- /dev/null
+++ b/test/win/enable-winrt/dllmain.cc
@@ -0,0 +1,30 @@
+// Copyright (c) 2013 Google Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <windows.h>
+#include <wrl.h>
+#include <wrl/wrappers/corewrappers.h>
+#include <windows.graphics.display.h>
+
+using namespace Microsoft::WRL;
+using namespace Microsoft::WRL::Wrappers;
+using namespace ABI::Windows::Foundation;
+using namespace ABI::Windows::Graphics::Display;
+
+bool TryToUseSomeWinRT() {
+  ComPtr<IDisplayPropertiesStatics> dp;
+  HStringReference s(RuntimeClass_Windows_Graphics_Display_DisplayProperties);
+  HRESULT hr = GetActivationFactory(s.Get(), dp.GetAddressOf());
+  if (SUCCEEDED(hr)) {
+    float dpi = 96.0f;
+    if (SUCCEEDED(dp->get_LogicalDpi(&dpi))) {
+      return true;
+    }
+  }
+  return false;
+}
+
+BOOL WINAPI DllMain(HINSTANCE hinstance, DWORD reason, LPVOID reserved) {
+  return TRUE;
+}
diff --git a/test/win/enable-winrt/enable-winrt.gyp b/test/win/enable-winrt/enable-winrt.gyp
new file mode 100644
index 0000000..466fff9
--- /dev/null
+++ b/test/win/enable-winrt/enable-winrt.gyp
@@ -0,0 +1,42 @@
+# Copyright (c) 2013 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'targets': [
+    {
+      'target_name': 'enable_winrt_dll',
+      'type': 'shared_library',
+      'msvs_enable_winrt': 1,
+      'sources': [
+        'dllmain.cc',
+      ],
+    },
+    {
+      'target_name': 'enable_winrt_missing_dll',
+      'type': 'shared_library',
+      'sources': [
+        'dllmain.cc',
+      ],
+    },
+    {
+      'target_name': 'enable_winrt_winphone_dll',
+      'type': 'shared_library',
+      'msvs_enable_winrt': 1,
+      'msvs_enable_winphone': 1,
+      'sources': [
+        'dllmain.cc',
+      ],
+      'msvs_settings':
+      {
+         'VCLinkerTool':
+         {
+            'AdditionalDependencies':
+            [
+                '%(AdditionalDependencies)',
+            ],
+         },
+      },
+    },
+  ]
+}
diff --git a/test/win/gyptest-link-enable-winrt.py b/test/win/gyptest-link-enable-winrt.py
new file mode 100644
index 0000000..2dc4860
--- /dev/null
+++ b/test/win/gyptest-link-enable-winrt.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2013 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+Make sure msvs_enable_winrt works correctly.
+"""
+
+import TestGyp
+
+import struct
+import sys
+
+
+CHDIR = 'enable-winrt'
+
+if sys.platform == 'win32':
+  test = TestGyp.TestGyp(formats=['msvs'])
+
+  test.run_gyp('enable-winrt.gyp', chdir=CHDIR)
+
+  test.build('enable-winrt.gyp', 'enable_winrt_dll', chdir=CHDIR)
+
+  test.build('enable-winrt.gyp', 'enable_winrt_missing_dll', chdir=CHDIR,
+             status=1)
+
+  test.build('enable-winrt.gyp', 'enable_winrt_winphone_dll', chdir=CHDIR)
+
+  test.pass_test()
diff --git a/test/win/gyptest-link-target-machine.py b/test/win/gyptest-link-target-machine.py
index 5a15f3f..477937d 100644
--- a/test/win/gyptest-link-target-machine.py
+++ b/test/win/gyptest-link-target-machine.py
@@ -18,11 +18,12 @@
   CHDIR = 'linker-flags'
   test.run_gyp('target-machine.gyp', chdir=CHDIR)
   # The .cc file is compiled as x86 (the default), so the link/libs that are
-  # x64 need to fail.
+  # x64 or ARM need to fail.
   test.build('target-machine.gyp', 'test_target_link_x86', chdir=CHDIR)
   test.build(
       'target-machine.gyp', 'test_target_link_x64', chdir=CHDIR, status=1)
   test.build('target-machine.gyp', 'test_target_lib_x86', chdir=CHDIR)
   test.build('target-machine.gyp', 'test_target_lib_x64', chdir=CHDIR, status=1)
+  test.build('target-machine.gyp', 'test_target_lib_arm', chdir=CHDIR, status=1)
 
   test.pass_test()
diff --git a/test/win/linker-flags/target-machine.gyp b/test/win/linker-flags/target-machine.gyp
index 3027192..7371999 100644
--- a/test/win/linker-flags/target-machine.gyp
+++ b/test/win/linker-flags/target-machine.gyp
@@ -44,5 +44,15 @@
       },
       'sources': ['hello.cc'],
     },
+    {
+      'target_name': 'test_target_lib_arm',
+      'type': 'static_library',
+      'msvs_settings': {
+        'VCLibrarianTool': {
+          'TargetMachine': '3',
+        },
+      },
+      'sources': ['hello.cc'],
+    },
   ]
 }