Re: [cmake-developers] Automoc same source name fix (proposal)

2016-04-12 Thread Sebastian Holtermann

Am 12.04.2016 um 11:57 schrieb Sebastian Holtermann:

Oops, moc_item.cpp it is.


For the attached test case you end up with


foo_automoc.cpp -- As before but includes sources below
foo_automoc.dir/data/moc_item.cpp
foo_automoc.dir/view/moc_item.cpp
foo_automoc.dir/moc_item.cpp


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers


[cmake-developers] Automoc same source name fix (proposal)

2016-04-12 Thread Sebastian Holtermann

Hi,

I've stumbled over bug
https://cmake.org/Bug/view.php?id=12873
a few times now since I like to use same named data/view classes.

I've prepared a fix that generates all moc_xxx.cpp files
in the foo_automoc.dir subdirectory.
For the attached test case you end up with

foo_automoc.cpp -- As before but includes sources below
foo_automoc.dir/data/moc_item.cpp
foo_automoc.dir/view/moc_item.cpp
foo_automoc.dir/item.cpp

This solves the same output moc problem.

What remains though is that including "moc_foo.cpp"
does not work because of missing INCLUDE_DIRECTORIES.

Kind regards,
Sebastian Holtermann

>From cf51dcf0af4744fbb40e3bb5ad253d2514325148 Mon Sep 17 00:00:00 2001
From: Sebastian Holtermann 
Date: Tue, 12 Apr 2016 10:47:49 +0200
Subject: [PATCH] Automoc: Create moc files below foo_automoc.dir with respect
 to the source header project relative path

---
 Source/cmQtAutoGenerators.cxx | 90 ---
 Source/cmQtAutoGenerators.h   |  3 ++
 2 files changed, 80 insertions(+), 13 deletions(-)

diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index ebe08b0..69b1e3d 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -414,6 +414,9 @@ void cmQtAutoGenerators::Init()
   this->OutMocCppFilename += this->TargetName;
   this->OutMocCppFilename += ".cpp";
 
+  this->OutMocDirname += this->TargetName;
+  this->OutMocDirname += ".dir";
+
   std::vector cdefList;
   cmSystemTools::ExpandListArgument(this->MocCompileDefinitionsStr, cdefList);
   for(std::vector::const_iterator it = cdefList.begin();
@@ -637,7 +640,7 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile)
 {
 automocCppChanged = true;
 }
-  outStream << "#include \"" << it->second << "\"\n";
+  outStream << "#include \"" << MocPathBuildRel ( it->second ) << "\"\n";
   }
 }
 
@@ -749,7 +752,7 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename,
 
 if (!headerToMoc.empty())
   {
-  includedMocs[headerToMoc] = currentMoc;
+  includedMocs[headerToMoc] = MocPathIncluderRel ( absFilename, currentMoc );
   if (basename == scannedFileBasename)
 {
 mocUnderscoreIncluded = true;
@@ -826,7 +829,7 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename,
   dotMocIncluded = true;
   ownDotMocFile = currentMoc;
   }
-includedMocs[fileToMoc] = currentMoc;
+includedMocs[fileToMoc] = MocPathIncluderRel ( absFilename, currentMoc );
 }
   matchOffset += mocIncludeRegExp.end();
   } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
@@ -851,7 +854,7 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename,
 << scannedFileBasename << ".moc\" for compatibility with "
"strict mode (see CMAKE_AUTOMOC_RELAXED_MODE).\n"
 << std::endl;
-  includedMocs[absFilename] = ownMocUnderscoreFile;
+  includedMocs[absFilename] = MocPathIncluderRel ( absFilename, ownMocUnderscoreFile );
   includedMocs.erase(ownMocHeaderFile);
   }
 else
@@ -930,7 +933,7 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename,
 
 if (!headerToMoc.empty())
   {
-  includedMocs[headerToMoc] = currentMoc;
+  includedMocs[headerToMoc] = MocPathIncluderRel ( absFilename, currentMoc );
   }
 else
   {
@@ -964,7 +967,7 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename,
   ::exit(EXIT_FAILURE);
   }
 dotMocIncluded = true;
-includedMocs[absFilename] = currentMoc;
+includedMocs[absFilename] = MocPathIncluderRel ( absFilename, currentMoc );
 }
   matchOffset += mocIncludeRegExp.end();
   } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
@@ -1104,15 +1107,14 @@ void cmQtAutoGenerators::ParseHeaders(const std::set& absHeaders,
 std::cout << "AUTOGEN: Checking " << headerName << std::endl;
 }
 
-  const std::string basename = cmsys::SystemTools::
-   GetFilenameWithoutLastExtension(headerName);
-
-  const std::string currentMoc = "moc_" + basename + ".cpp";
   std::string macroName;
   if (requiresMocing(contents, macroName))
 {
 //std::cout << "header contains Q_OBJECT macro";
-notIncludedMocs[headerName] = currentMoc;
+const std::string basename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(headerName);
+const std::string currentMoc = "moc_" + basename + ".cpp";
+notIncludedMocs[headerName] = MocPathIncluderRel ( headerName, currentMoc );
 }
   }
 this->ParseForUic(headerName, contents, includedUis);
@@ -1122,7 +1124,11 @@ void