Browse Source

VS: Add support for WinRT project properties (#12930)

VS_WINRT_EXTENSIONS: Boolean property that correspond to "Enable
Tailored Features" in Visual Studio 11 IDE.

VS_WINRT_REFERENCES: Semicolon-delimited list of *.winmd references to
add to the project, which creates a new <ItemGroup>.
Eugene Golushkov 13 years ago
parent
commit
9e01aefd24

+ 10 - 0
Source/cmTarget.cxx

@@ -1064,6 +1064,16 @@ void cmTarget::DefineProperties(cmake *cm)
      "Adds one or more semicolon-delimited .NET references to a "
      "generated Visual Studio project. For example, \"System;"
      "System.Windows.Forms\".");
+  cm->DefineProperty
+    ("VS_WINRT_EXTENSIONS", cmProperty::TARGET,
+     "Visual Studio project C++/CX language extensions for Windows Runtime",
+     "Can be set to enable C++/CX language extensions.");
+  cm->DefineProperty
+    ("VS_WINRT_REFERENCES", cmProperty::TARGET,
+     "Visual Studio project Windows Runtime Metadata references",
+     "Adds one or more semicolon-delimited WinRT references to a "
+     "generated Visual Studio project. For example, \"Windows;"
+     "Windows.UI.Core\".");
   cm->DefineProperty
     ("VS_GLOBAL_<variable>", cmProperty::TARGET,
      "Visual Studio project-specific global variable.",

+ 37 - 1
Source/cmVisualStudio10TargetGenerator.cxx

@@ -255,6 +255,7 @@ void cmVisualStudio10TargetGenerator::Generate()
   this->WriteObjSources();
   this->WriteCLSources();
   this->WriteDotNetReferences();
+  this->WriteWinRTReferences();
   this->WriteProjectReferences();
   this->WriteString(
     "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\""
@@ -299,6 +300,36 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
     }
 }
 
+void cmVisualStudio10TargetGenerator::WriteWinRTReferences()
+{
+  const char* vsWinRTReferences
+    = this->Target->GetProperty("VS_WINRT_REFERENCES");
+  if(vsWinRTReferences)
+    {
+    std::string references(vsWinRTReferences);
+    std::string::size_type position = 0;
+
+    this->WriteString("<ItemGroup>\n", 1);
+    while(references.length() > 0)
+      {
+      if((position = references.find(";")) == std::string::npos)
+        {
+        position = references.length() + 1;
+        }
+
+      this->WriteString("<Reference Include=\"", 2);
+      (*this->BuildFileStream) <<
+        cmVS10EscapeXML(references.substr(0, position)) << "\">\n";
+      this->WriteString("<IsWinMDFile>true</IsWinMDFile>\n", 3);
+      this->WriteString("</Reference>\n", 2);
+
+      references.erase(0, position + 1);
+      }
+
+    this->WriteString("</ItemGroup>\n", 1);
+    }
+}
+
 // ConfigurationType Application, Utility StaticLibrary DynamicLibrary
 
 void cmVisualStudio10TargetGenerator::WriteProjectConfigurations()
@@ -372,7 +403,8 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
     this->WriteString(mfcLine.c_str(), 2);
 
     if(this->Target->GetType() <= cmTarget::MODULE_LIBRARY &&
-       this->ClOptions[*i]->UsingUnicode())
+       this->ClOptions[*i]->UsingUnicode() ||
+       this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
       {
       this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
       }
@@ -387,6 +419,10 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
       pts += "</PlatformToolset>\n";
       this->WriteString(pts.c_str(), 2);
       }
+    if(this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
+      {
+      this->WriteString("<Immersive>true</Immersive>\n", 2);
+      }
     this->WriteString("</PropertyGroup>\n", 1);
     }
 }

+ 1 - 0
Source/cmVisualStudio10TargetGenerator.h

@@ -48,6 +48,7 @@ private:
   void WriteProjectConfigurationValues();
   void WriteCLSources();
   void WriteDotNetReferences();
+  void WriteWinRTReferences();
   void WriteObjSources();
   void WritePathAndIncrementalLinkOptions();
   void WriteItemDefinitionGroups();