diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index e7e456a2e305b82b9007a0a7f5ecb92fbdfa85cb..902e87206f2e9ae5db6bbff2ce2d30953c2716ec 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -733,9 +733,8 @@ void cmQtAutoGenerators::MocFindDepends(
         const std::string match = filter.regExp.match(1);
         if (!match.empty()) {
           // Find the dependency file
-          const std::string incFile =
-            this->FindIncludedFile(absFilename, match);
-          if (!incFile.empty()) {
+          std::string incFile;
+          if (this->FindIncludedFile(incFile, absFilename, match)) {
             mocDepends[absFilename].insert(incFile);
             if (this->Verbose) {
               this->LogInfo("AutoMoc: Found dependency:\n  " +
@@ -1780,40 +1779,35 @@ std::string cmQtAutoGenerators::FindMocHeader(const std::string& basePath,
   return header;
 }
 
-std::string cmQtAutoGenerators::FindIncludedFile(
-  const std::string& sourceFile, const std::string& includeString) const
+bool cmQtAutoGenerators::FindIncludedFile(
+  std::string& absFile, const std::string& sourceFile,
+  const std::string& includeString) const
 {
+  bool success = false;
   // Search in vicinity of the source
   {
     std::string testPath = cmSystemTools::GetFilenamePath(sourceFile);
     testPath += '/';
     testPath += includeString;
     if (cmsys::SystemTools::FileExists(testPath.c_str())) {
-      return cmsys::SystemTools::GetRealPath(testPath);
+      absFile = cmsys::SystemTools::GetRealPath(testPath);
+      success = true;
     }
   }
-  // Search globally
-  return FindInIncludeDirectories(includeString);
-}
-
-/**
- * @brief Tries to find a file in the include directories
- * @return True on success
- */
-std::string cmQtAutoGenerators::FindInIncludeDirectories(
-  const std::string& includeString) const
-{
-  std::string res;
-  for (std::vector<std::string>::const_iterator iit =
-         this->MocIncludePaths.begin();
-       iit != this->MocIncludePaths.end(); ++iit) {
-    const std::string fullPath = ((*iit) + '/' + includeString);
-    if (cmsys::SystemTools::FileExists(fullPath.c_str())) {
-      res = cmsys::SystemTools::GetRealPath(fullPath);
-      break;
+  // Search in include directories
+  if (!success) {
+    for (std::vector<std::string>::const_iterator iit =
+           this->MocIncludePaths.begin();
+         iit != this->MocIncludePaths.end(); ++iit) {
+      const std::string fullPath = ((*iit) + '/' + includeString);
+      if (cmsys::SystemTools::FileExists(fullPath.c_str())) {
+        absFile = cmsys::SystemTools::GetRealPath(fullPath);
+        success = true;
+        break;
+      }
     }
   }
-  return res;
+  return success;
 }
 
 /**
diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h
index e4b7f607d8fd5ac3efb73891b319d7b1f15b54d8..b83edf7197dafc8237fe3f669d107c17e0ab4831 100644
--- a/Source/cmQtAutoGenerators.h
+++ b/Source/cmQtAutoGenerators.h
@@ -147,9 +147,8 @@ private:
   std::string FindMocHeader(const std::string& basePath,
                             const std::string& baseName,
                             const std::string& subDir) const;
-  std::string FindIncludedFile(const std::string& sourceFile,
-                               const std::string& includeString) const;
-  std::string FindInIncludeDirectories(const std::string& includeString) const;
+  bool FindIncludedFile(std::string& absFile, const std::string& sourceFile,
+                        const std::string& includeString) const;
 
   // - Target names
   std::string OriginTargetName;