From 7d5b6a582aee61880ce6b3f70ceb4cb1d63d1dc1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20St=C3=BCrmer?= <michael.stuermer@schaeffler.com>
Date: Fri, 23 Sep 2016 12:15:40 +0200
Subject: [PATCH] preparational patches for CSharp support

---
 Source/cmGlobalVisualStudio71Generator.cxx |  6 +++++-
 Source/cmGlobalVisualStudioGenerator.cxx   | 24 ++++++++++++++++++++++++
 Source/cmGlobalVisualStudioGenerator.h     |  3 +++
 Source/cmVisualStudioGeneratorOptions.cxx  |  5 +++++
 Source/cmVisualStudioGeneratorOptions.h    |  1 +
 5 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx
index ea008ad..2448b4e 100644
--- a/Source/cmGlobalVisualStudio71Generator.cxx
+++ b/Source/cmGlobalVisualStudio71Generator.cxx
@@ -168,7 +168,11 @@ void cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
     ext = ".vfproj";
     project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
   }
-  const char* targetExt = t->GetProperty("GENERATOR_FILE_NAME_EXT");
+  if (this->TargetIsCSharpOnly(t)) {
+    ext = ".csproj";
+    project = "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"";
+  }
+  const char* targetExt = t->Target->GetProperty("GENERATOR_FILE_NAME_EXT");
   if (targetExt) {
     ext = targetExt;
   }
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx
index 7bdd74d..1b858d5 100644
--- a/Source/cmGlobalVisualStudioGenerator.cxx
+++ b/Source/cmGlobalVisualStudioGenerator.cxx
@@ -743,6 +743,30 @@ bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly(
   return false;
 }
 
+bool cmGlobalVisualStudioGenerator::TargetIsCSharpOnly(
+  cmGeneratorTarget const* gt)
+{
+  if (gt->GetType() > cmState::OBJECT_LIBRARY) {
+    return false;
+  }
+  // check to see if this is a C# build
+  std::set<std::string> languages;
+  {
+    // Issue diagnostic if the source files depend on the config.
+    std::vector<cmSourceFile*> sources;
+    if (!gt->GetConfigCommonSourceFiles(sources)) {
+      return false;
+    }
+  }
+  gt->GetLanguages(languages, "");
+  if (languages.size() == 1) {
+    if (*languages.begin() == "CSharp") {
+      return true;
+    }
+  }
+  return false;
+}
+
 bool cmGlobalVisualStudioGenerator::TargetCompare::operator()(
   cmGeneratorTarget const* l, cmGeneratorTarget const* r) const
 {
diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h
index 3312ed6..3b304ae 100644
--- a/Source/cmGlobalVisualStudioGenerator.h
+++ b/Source/cmGlobalVisualStudioGenerator.h
@@ -78,6 +78,9 @@ public:
   // return true if target is fortran only
   bool TargetIsFortranOnly(const cmGeneratorTarget* gt);
 
+  // return true if target is C# only
+  static bool TargetIsCSharpOnly(cmGeneratorTarget const* gt);
+
   /** Get the top-level registry key for this VS version.  */
   std::string GetRegistryBase();
 
diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx
index 9badda6..4be183d 100644
--- a/Source/cmVisualStudioGeneratorOptions.cxx
+++ b/Source/cmVisualStudioGeneratorOptions.cxx
@@ -137,6 +137,11 @@ bool cmVisualStudioGeneratorOptions::IsWinRt() const
   return this->FlagMap.find("CompileAsWinRT") != this->FlagMap.end();
 }
 
+bool cmVisualStudioGeneratorOptions::IsManaged() const
+{
+  return this->FlagMap.find("CompileAsManaged") != this->FlagMap.end();
+}
+
 bool cmVisualStudioGeneratorOptions::UsingUnicode() const
 {
   // Look for the a _UNICODE definition.
diff --git a/Source/cmVisualStudioGeneratorOptions.h b/Source/cmVisualStudioGeneratorOptions.h
index 219b009..9e82a9a 100644
--- a/Source/cmVisualStudioGeneratorOptions.h
+++ b/Source/cmVisualStudioGeneratorOptions.h
@@ -58,6 +58,7 @@ public:
 
   bool IsDebug() const;
   bool IsWinRt() const;
+  bool IsManaged() const;
   // Write options to output.
   void OutputPreprocessorDefinitions(std::ostream& fout, const char* prefix,
                                      const char* suffix,
-- 
2.8.0.windows.1

