From 7b6fbf0578f5d7c426a36c3afe77deaf864d49ab Mon Sep 17 00:00:00 2001
From: Mike Pagel <Mike.Pagel@bmw.de>
Date: Mon, 28 Sep 2015 15:33:10 +0200
Subject: [PATCH 1/2] Forced generated rule files to be old to prevent rebuilds
 of dependencies.

---
 Source/cmVisualStudio10TargetGenerator.cxx | 28 +++++++++++++++++++++++++++-
 Source/cmVisualStudio10TargetGenerator.h   |  2 ++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 4c380f7..38092e6 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -42,6 +42,7 @@
 #include "cmVS14MASMFlagTable.h"
 
 #include <cmsys/auto_ptr.hxx>
+#include <windows.h>
 
 cmIDEFlagTable const* cmVisualStudio10TargetGenerator::GetClFlagTable() const
 {
@@ -871,7 +872,8 @@ cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile const* source,
         fout << "# generated from CMake\n";
         fout.flush();
         fout.close();
-        }
+        ForceOld(sourcePath);
+      }
       else
         {
         std::string error = "Could not create file: [";
@@ -3429,3 +3431,27 @@ cmVisualStudio10TargetGenerator
   this->WriteString("<None Include=\"", 2);
   (*this->BuildFileStream) << cmVS10EscapeXML(keyFile) << "\" />\n";
 }
+
+// Forces given file to get a very old timestamp, preventing dependencies to be built automatically.
+bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const
+{
+  HANDLE h = CreateFileW(
+    cmSystemTools::ConvertToWindowsExtendedPath(source).c_str(),
+    FILE_WRITE_ATTRIBUTES,
+    FILE_SHARE_WRITE, 0, OPEN_EXISTING,
+    FILE_FLAG_BACKUP_SEMANTICS, 0);
+  if(!h)
+    {
+    return false;
+    }
+
+  const FILETIME FTIME_20010101 = { 3365781504, 29389701 };
+  if (!SetFileTime(h, &FTIME_20010101, &FTIME_20010101, &FTIME_20010101))
+    {
+    CloseHandle(h);
+    return false;
+    }
+
+  CloseHandle(h);
+  return true;
+}
\ No newline at end of file
diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h
index 451f8b2..7b425df 100644
--- a/Source/cmVisualStudio10TargetGenerator.h
+++ b/Source/cmVisualStudio10TargetGenerator.h
@@ -129,6 +129,8 @@ private:
   cmIDEFlagTable const* GetLinkFlagTable() const;
   cmIDEFlagTable const* GetMasmFlagTable() const;
 
+  bool ForceOld(const std::string& source) const;
+
 private:
   typedef cmVisualStudioGeneratorOptions Options;
   typedef std::map<std::string, Options*> OptionsMap;
-- 
1.9.5.msysgit.0


From a09d3a5e950baf793ad1a4210f3c1cd1ae1e49d9 Mon Sep 17 00:00:00 2001
From: Mike Pagel <Mike.Pagel@bmw.de>
Date: Mon, 28 Sep 2015 15:35:07 +0200
Subject: [PATCH 2/2] Fixed formatting.

---
 Source/cmVisualStudio10TargetGenerator.cxx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 38092e6..6145421 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -873,7 +873,7 @@ cmVisualStudio10TargetGenerator::WriteCustomRule(cmSourceFile const* source,
         fout.flush();
         fout.close();
         ForceOld(sourcePath);
-      }
+        }
       else
         {
         std::string error = "Could not create file: [";
-- 
1.9.5.msysgit.0

