From ef0fd4f0ced850edd049bb05b527c3bd234f441f Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Tue, 10 Jun 2014 11:33:19 -0400
Subject: VS: Teach vcxproj generation about the Tegra-Android platform

Complete the basic implementation of the VS Tegra-Android generators
by replacing parts of vcxproj files that are specific to MS tools
with settings defined for the NVIDIA Nsight Tegra tools.

Current limitations include:

* We have no "flag table" so flags will be passed in the additional
  options fields instead of mapped to the vcxproj elements defined
  by Nsight Tegra msbuild platform definition files.

* We have no interface to set the AndroidArch, AndroidStlType, or
  AndroidTargetAPI fields so defaults will be used.

* The Nsight Tegra msbuild platform definition files do not provide
  a working "Utility" target type so for add_custom_target we need
  to use a "StaticLibrary" target type and leave out ClCompile rules.

* There is also no target type for plain command-line executables
  so for add_executable we need to use a "DynamicLibrary" target.
  Full application bundles will likely require new CMake target
  properties (like WIN32_EXECUTABLE for Windows GUI executables).
---
 Source/cmVisualStudio10TargetGenerator.cxx | 53 ++++++++++++++++++++++++++++--
 Source/cmVisualStudio10TargetGenerator.h   |  2 ++
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index a13cbd2..15d0980 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -180,7 +180,8 @@ cmVisualStudio10TargetGenerator(cmTarget* target,
   this->GlobalGenerator->CreateGUID(this->Name.c_str());
   this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());
   this->Platform = gg->GetPlatformName();
-  this->MSTools = true;
+  this->NsightTegra = gg->IsNsightTegra();
+  this->MSTools = !this->NsightTegra;
   this->TargetCompileAsWinRT = false;
   this->BuildFileStream = 0;
   this->IsMissingFiles = false;
@@ -312,6 +313,15 @@ void cmVisualStudio10TargetGenerator::Generate()
           "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
   this->WriteString(project_defaults.c_str(),0);
 
+  if(this->NsightTegra)
+    {
+    this->WriteString("<PropertyGroup Label=\"NsightTegraProject\">\n", 1);
+    this->WriteString("<NsightTegraProjectRevisionNumber>"
+                      "6"
+                      "</NsightTegraProjectRevisionNumber>\n", 2);
+    this->WriteString("</PropertyGroup>\n", 1);
+    }
+
   this->WriteProjectConfigurations();
   this->WriteString("<PropertyGroup Label=\"Globals\">\n", 1);
   this->WriteString("<ProjectGUID>", 2);
@@ -605,11 +615,27 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
         configType += "StaticLibrary";
         break;
       case cmTarget::EXECUTABLE:
-        configType += "Application";
+        if(this->NsightTegra)
+          {
+          // Android executables are .so too.
+          configType += "DynamicLibrary";
+          }
+        else
+          {
+          configType += "Application";
+          }
         break;
       case cmTarget::UTILITY:
       case cmTarget::GLOBAL_TARGET:
-        configType += "Utility";
+        if(this->NsightTegra)
+          {
+          // Tegra-Android platform does not understand "Utility".
+          configType += "StaticLibrary";
+          }
+        else
+          {
+          configType += "Utility";
+          }
         break;
       case cmTarget::UNKNOWN_LIBRARY:
       case cmTarget::INTERFACE_LIBRARY:
@@ -622,6 +648,10 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
       {
       this->WriteMSToolConfigurationValues(*i);
       }
+    else if(this->NsightTegra)
+      {
+      this->WriteNsightTegraConfigurationValues(*i);
+      }
 
     this->WriteString("</PropertyGroup>\n", 1);
     }
@@ -683,6 +713,19 @@ void cmVisualStudio10TargetGenerator
     }
 }
 
+//----------------------------------------------------------------------------
+void cmVisualStudio10TargetGenerator
+::WriteNsightTegraConfigurationValues(std::string const&)
+{
+  cmGlobalVisualStudio10Generator* gg =
+    static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
+  const char* toolset = gg->GetPlatformToolset();
+  std::string ntv = "<NdkToolchainVersion>";
+  ntv += toolset? toolset : "Default";
+  ntv += "</NdkToolchainVersion>\n";
+  this->WriteString(ntv.c_str(), 2);
+}
+
 void cmVisualStudio10TargetGenerator::WriteCustomCommands()
 {
   this->SourcesVisited.clear();
@@ -2188,6 +2231,10 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
       linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
       }
     }
+  else if(this->NsightTegra)
+    {
+    linkOptions.AddFlag("SoName", targetNameSO.c_str());
+    }
 
   linkOptions.Parse(flags.c_str());
 
diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h
index d6db18a..8887d14 100644
--- a/Source/cmVisualStudio10TargetGenerator.h
+++ b/Source/cmVisualStudio10TargetGenerator.h
@@ -59,6 +59,7 @@ private:
   void WriteMSToolConfigurationValues(std::string const& config);
   void WriteHeaderSource(cmSourceFile const* sf);
   void WriteExtraSource(cmSourceFile const* sf);
+  void WriteNsightTegraConfigurationValues(std::string const& config);
   void WriteSource(std::string const& tool, cmSourceFile const* sf,
                    const char* end = 0);
   void WriteSources(std::string const& tool,
@@ -139,6 +140,7 @@ private:
   std::string GUID;
   std::string Name;
   bool MSTools;
+  bool NsightTegra;
   bool TargetCompileAsWinRT;
   cmGlobalVisualStudio10Generator* GlobalGenerator;
   cmGeneratedFileStream* BuildFileStream;
-- 
cgit v0.12