From 42103081542cb7a26d4ee4300b9718b6fa43ccf8 Mon Sep 17 00:00:00 2001
From: Hauke Heibel <hauke.heibel@gmail.com>
Date: Fri, 29 Mar 2013 18:01:14 +0100
Subject: [PATCH] Fixes issue #13900.

---
 Source/cmQtAutomoc.cxx | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx
index c7060b0..68a05d4 100644
--- a/Source/cmQtAutomoc.cxx
+++ b/Source/cmQtAutomoc.cxx
@@ -13,6 +13,7 @@
 
 #include "cmGlobalGenerator.h"
 #include "cmLocalGenerator.h"
+#include "cmLocalVisualStudioGenerator.h"
 #include "cmMakefile.h"
 #include "cmSourceFile.h"
 #include "cmSystemTools.h"
@@ -182,14 +183,25 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target)
   std::string automocComment = "Automoc for target ";
   automocComment += targetName;
 
-  cmTarget* automocTarget = makefile->AddUtilityCommand(
-                              automocTargetName.c_str(), true,
-                              workingDirectory.c_str(), depends,
-                              commandLines, false, automocComment.c_str());
-  // inherit FOLDER property from target (#13688)
-  copyTargetProperty(automocTarget, target, "FOLDER");
+  // choose a special path for VS11 in order to overcome issue #13900
+  cmLocalVisualStudioGenerator* cmVisualStudioGenerator = dynamic_cast<cmLocalVisualStudioGenerator*>(localGen);
+  bool isVisualStudio11 = cmVisualStudioGenerator && (cmVisualStudioGenerator->GetVersion() == cmLocalVisualStudioGenerator::VS11);
 
-  target->AddUtility(automocTargetName.c_str());
+  if (isVisualStudio11)
+  {
+    makefile->AddCustomCommandToTarget(
+      targetName, depends, commandLines, cmTarget::CustomCommandType::PRE_BUILD,
+      automocComment.c_str(), workingDirectory.c_str(), false);
+  }
+  else
+  {
+    cmTarget* automocTarget = makefile->AddUtilityCommand(
+                                automocTargetName.c_str(), true,
+                                workingDirectory.c_str(), depends,
+                                commandLines, false, automocComment.c_str());
+    // inherit FOLDER property from target (#13688)
+    copyTargetProperty(automocTarget, target, "FOLDER");
+  }
 
   // configure a file to get all information to automoc at buildtime:
   std::string _moc_files;
-- 
1.8.1.msysgit.1

