From f9f31c31c893311f873f6171e02dab44402b96a9 Mon Sep 17 00:00:00 2001
From: Robert Goulet <robert.goulet@autodesk.com>
Date: Wed, 28 Jan 2015 17:03:52 -0500
Subject: [PATCH] Use VS_WINRT_COMPONENT explicitly set to false to disable
 Windows Store properties for executable targets.

---
 Source/cmCustomCommandGenerator.cxx        |  2 +-
 Source/cmGlobalGenerator.h                 |  2 ++
 Source/cmGlobalVisualStudio10Generator.cxx | 21 +++++++++++++++++++++
 Source/cmGlobalVisualStudio10Generator.h   |  9 ++++++---
 Source/cmTarget.cxx                        |  7 +++++++
 Source/cmTarget.h                          |  3 +++
 6 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx
index 0eac7a1..0160c26 100644
--- a/Source/cmCustomCommandGenerator.cxx
+++ b/Source/cmCustomCommandGenerator.cxx
@@ -43,7 +43,7 @@ std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const
   std::string const& argv0 = this->CC.GetCommandLines()[c][0];
   cmTarget* target = this->Makefile->FindTargetToUse(argv0);
   if(target && target->GetType() == cmTarget::EXECUTABLE &&
-     (target->IsImported() || !this->Makefile->IsOn("CMAKE_CROSSCOMPILING") || target->GetPropertyAsBool("VS_WINRT_DISABLE")))
+     (target->IsImported() || !this->Makefile->IsOn("CMAKE_CROSSCOMPILING") || target->IsHostExecutable()))
     {
     return target->GetLocation(this->Config);
     }
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 08f061a..d1f6895 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -353,6 +353,8 @@ public:
   cmFileLockPool& GetFileLockPool() { return FileLockPool; }
 #endif
 
+  virtual bool IsHostExecutable(const cmTarget* target) { return false; }
+
 protected:
   virtual void Generate();
 
diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx
index 531a714..50d7640 100644
--- a/Source/cmGlobalVisualStudio10Generator.cxx
+++ b/Source/cmGlobalVisualStudio10Generator.cxx
@@ -367,6 +367,22 @@ const char* cmGlobalVisualStudio10Generator::GetPlatformToolset() const
 }
 
 //----------------------------------------------------------------------------
+bool cmGlobalVisualStudio10Generator::TargetsWindowsStore(const cmTarget* target) const
+{
+  if (this->SystemIsWindowsStore)
+    {
+    // Allow disabling Windows Store properties on executable targets if VS_WINRT_COMPONENT is explicitly set to false
+    const char* isWinRT = target && target->GetType() == cmTarget::EXECUTABLE ? target->GetProperty("VS_WINRT_COMPONENT") : NULL;
+    if (isWinRT && cmSystemTools::IsOff(isWinRT))
+      {
+      return false;
+      }
+    return true;
+    }
+  return false;
+}
+
+//----------------------------------------------------------------------------
 std::string cmGlobalVisualStudio10Generator::GetUserMacrosDirectory()
 {
   std::string base;
@@ -652,3 +668,8 @@ std::string cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion()
     "Version", version, cmSystemTools::KeyWOW64_32);
   return version;
 }
+
+bool cmGlobalVisualStudio10Generator::IsHostExecutable(const cmTarget* target)
+{
+  return !TargetsWindowsStore(target);
+}
\ No newline at end of file
diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h
index 78c181a..3d471e0 100644
--- a/Source/cmGlobalVisualStudio10Generator.h
+++ b/Source/cmGlobalVisualStudio10Generator.h
@@ -80,9 +80,10 @@ public:
   bool TargetsWindowsPhone() const
     { return this->SystemIsWindowsPhone; }
 
-  /** Return true if building for WindowsStore */
-  bool TargetsWindowsStore(cmTarget* target) const
-    { return target ? this->SystemIsWindowsStore && !target->GetPropertyAsBool("VS_WINRT_DISABLE") : this->SystemIsWindowsStore; }
+  /** Return true if building for WindowsStore. If target provided, also check
+    * if WindowsStore properties are explicitly disabled by VS_WINRT_COMPONENT.
+    */
+  bool TargetsWindowsStore(const cmTarget* target) const;
 
   /**
    * Where does this version of Visual Studio look for macros for the
@@ -112,6 +113,8 @@ public:
 
   static std::string GetInstalledNsightTegraVersion();
 
+  virtual bool IsHostExecutable(const cmTarget* target);
+
 protected:
   virtual void Generate();
   virtual bool InitializeSystem(cmMakefile* mf);
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 98cb75c..c872998 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -572,6 +572,13 @@ bool cmTarget::IsExecutableWithExports() const
 }
 
 //----------------------------------------------------------------------------
+bool cmTarget::IsHostExecutable() const
+{
+  return (this->GetType() == cmTarget::EXECUTABLE &&
+          this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->IsHostExecutable(this));
+}
+
+//----------------------------------------------------------------------------
 bool cmTarget::IsLinkable() const
 {
   return (this->GetType() == cmTarget::STATIC_LIBRARY ||
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index ddd9859..ef36dc7 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -510,6 +510,9 @@ public:
       enabled.  */
   bool IsExecutableWithExports() const;
 
+  /** Return whether this target is an executable on host.  */
+  bool IsHostExecutable() const;
+
   /** Return whether this target may be used to link another target.  */
   bool IsLinkable() const;
 
-- 
1.9.4.msysgit.0

From 7ad002d75963c32195a8e0f1d7c4512776a65da5 Mon Sep 17 00:00:00 2001
From: Robert Goulet <robert.goulet@autodesk.com>
Date: Tue, 27 Jan 2015 14:47:05 -0500
Subject: [PATCH] Add target property to allow disabling Windows Store support
 for specific targets.

---
 Source/cmCustomCommandGenerator.cxx        |  2 +-
 Source/cmGlobalVisualStudio10Generator.h   |  4 ++--
 Source/cmVisualStudio10TargetGenerator.cxx | 18 +++++++++---------
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx
index 162d7a1..0eac7a1 100644
--- a/Source/cmCustomCommandGenerator.cxx
+++ b/Source/cmCustomCommandGenerator.cxx
@@ -43,7 +43,7 @@ std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const
   std::string const& argv0 = this->CC.GetCommandLines()[c][0];
   cmTarget* target = this->Makefile->FindTargetToUse(argv0);
   if(target && target->GetType() == cmTarget::EXECUTABLE &&
-     (target->IsImported() || !this->Makefile->IsOn("CMAKE_CROSSCOMPILING")))
+     (target->IsImported() || !this->Makefile->IsOn("CMAKE_CROSSCOMPILING") || target->GetPropertyAsBool("VS_WINRT_DISABLE")))
     {
     return target->GetLocation(this->Config);
     }
diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h
index 3b0a5cf..78c181a 100644
--- a/Source/cmGlobalVisualStudio10Generator.h
+++ b/Source/cmGlobalVisualStudio10Generator.h
@@ -81,8 +81,8 @@ public:
     { return this->SystemIsWindowsPhone; }
 
   /** Return true if building for WindowsStore */
-  bool TargetsWindowsStore() const
-    { return this->SystemIsWindowsStore; }
+  bool TargetsWindowsStore(cmTarget* target) const
+    { return target ? this->SystemIsWindowsStore && !target->GetPropertyAsBool("VS_WINRT_DISABLE") : this->SystemIsWindowsStore; }
 
   /**
    * Where does this version of Visual Studio look for macros for the
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index d2f6ffd..974e4ce 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -708,7 +708,7 @@ void cmVisualStudio10TargetGenerator
       this->ClOptions[config]->UsingUnicode()) ||
      this->Target->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
      this->GlobalGenerator->TargetsWindowsPhone() ||
-     this->GlobalGenerator->TargetsWindowsStore() ||
+     this->GlobalGenerator->TargetsWindowsStore(Target) ||
      this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
     {
     this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
@@ -1276,7 +1276,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
   std::string deployContent;
   std::string deployLocation;
   if(this->GlobalGenerator->TargetsWindowsPhone() ||
-     this->GlobalGenerator->TargetsWindowsStore())
+     this->GlobalGenerator->TargetsWindowsStore(Target))
     {
     const char* content = sf->GetProperty("VS_DEPLOYMENT_CONTENT");
     if(content && *content)
@@ -1907,7 +1907,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
         clOptions.AddDefine("_WINRT_DLL");
         }
       }
-    else if (this->GlobalGenerator->TargetsWindowsStore() ||
+    else if (this->GlobalGenerator->TargetsWindowsStore(Target) ||
              this->GlobalGenerator->TargetsWindowsPhone())
       {
       if (!clOptions.IsWinRt())
@@ -2125,7 +2125,7 @@ cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
   // and WindowsStore tools look at GenerateWindowsMetadata in the
   // Link tool options even for static libraries.
   if(this->GlobalGenerator->TargetsWindowsPhone() ||
-     this->GlobalGenerator->TargetsWindowsStore())
+     this->GlobalGenerator->TargetsWindowsStore(Target))
     {
     this->WriteString("<Link>\n", 2);
     this->WriteString("<GenerateWindowsMetadata>false"
@@ -2401,7 +2401,7 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
       linkOptions.AddFlag("GenerateWindowsMetadata", "true");
       }
     else if (this->GlobalGenerator->TargetsWindowsPhone() ||
-             this->GlobalGenerator->TargetsWindowsStore())
+             this->GlobalGenerator->TargetsWindowsStore(Target))
       {
       // WindowsPhone and WindowsStore components are in an app container
       // and produce WindowsMetadata.  If we are not producing a WINRT
@@ -2677,7 +2677,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences()
 
 void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
 {
-  if((this->GlobalGenerator->TargetsWindowsStore() ||
+  if((this->GlobalGenerator->TargetsWindowsStore(Target) ||
       this->GlobalGenerator->TargetsWindowsPhone())
       && (cmTarget::EXECUTABLE == this->Target->GetType()))
     {
@@ -2751,7 +2751,7 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
 {
   bool isAppContainer = false;
   bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
-  bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
+  bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore(Target);
   std::string const& v = this->GlobalGenerator->GetSystemVersion();
   if(isWindowsPhone || isWindowsStore)
     {
@@ -2847,7 +2847,7 @@ void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
             }
           }
         }
-      else if (this->GlobalGenerator->TargetsWindowsStore())
+      else if (this->GlobalGenerator->TargetsWindowsStore(Target))
         {
         if (manifestSources.empty())
           {
@@ -2879,7 +2879,7 @@ void cmVisualStudio10TargetGenerator::WriteMissingFiles()
       this->WriteMissingFilesWP81();
       }
     }
-  else if (this->GlobalGenerator->TargetsWindowsStore())
+  else if (this->GlobalGenerator->TargetsWindowsStore(Target))
    {
    if (v == "8.0")
      {
-- 
1.9.4.msysgit.0

