summaryrefslogtreecommitdiffstats
path: root/Source/cmQtAutoGenerators.cxx
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2016-04-18 18:09:23 (GMT)
committerBrad King <brad.king@kitware.com>2016-04-22 12:49:21 (GMT)
commit8295d43713b621558ce8fc67033021e6eb2a6612 (patch)
tree6be23ac691d0cae3c59badb7e8dacacacf6408ff /Source/cmQtAutoGenerators.cxx
parentd350308af6704e70f94ef00d45c4b52ad779e566 (diff)
downloadCMake-8295d43713b621558ce8fc67033021e6eb2a6612.zip
CMake-8295d43713b621558ce8fc67033021e6eb2a6612.tar.gz
CMake-8295d43713b621558ce8fc67033021e6eb2a6612.tar.bz2
Autogen: Check added for name collisions of generated moc files
The test exits with an error if two or more source files would generate the same moc file.
Diffstat (limited to 'Source/cmQtAutoGenerators.cxx')
-rw-r--r--Source/cmQtAutoGenerators.cxx69
1 files changed, 69 insertions, 0 deletions
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index c07a0a6..08749dd 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -1067,6 +1067,26 @@ bool cmQtAutoGenerators::GenerateMocFiles(
const std::map<std::string, std::string>& includedMocs,
const std::map<std::string, std::string>& notIncludedMocs )
{
+ // look for name collisions
+ {
+ std::multimap<std::string, std::string> collisions;
+ // Test merged map of included and notIncluded
+ std::map<std::string, std::string> mergedMocs ( includedMocs );
+ mergedMocs.insert ( notIncludedMocs.begin(), notIncludedMocs.end() );
+ if( this->NameCollisionTest ( mergedMocs, collisions ) )
+ {
+ std::cerr <<
+ "AUTOGEN: error: "
+ "The same moc file will be generated "
+ "from different sources." << std::endl <<
+ "To avoid this error either" << std::endl <<
+ "- rename the source files or" << std::endl <<
+ "- do not include the (moc_NAME.cpp|NAME.moc) file" << std::endl;
+ this->NameCollisionLog ( collisions );
+ ::exit(EXIT_FAILURE);
+ }
+ }
+
// generate moc files that are included by source files.
for(std::map<std::string, std::string>::const_iterator
it = includedMocs.begin(); it != includedMocs.end(); ++it)
@@ -1442,6 +1462,55 @@ bool cmQtAutoGenerators::GenerateQrc (
return true;
}
+/**
+ * @brief Collects name collisions as output/input pairs
+ * @return True if there were collisions
+ */
+bool cmQtAutoGenerators::NameCollisionTest(
+ const std::map<std::string, std::string >& genFiles,
+ std::multimap<std::string, std::string>& collisions)
+{
+ typedef std::map<std::string, std::string>::const_iterator Iter;
+ typedef std::map<std::string, std::string>::value_type VType;
+ for(Iter ait = genFiles.begin(); ait != genFiles.end(); ++ait )
+ {
+ bool first_match ( true );
+ for (Iter bit = (++Iter(ait)); bit != genFiles.end(); ++bit)
+ {
+ if(ait->second == bit->second)
+ {
+ if (first_match)
+ {
+ if (collisions.find(ait->second) != collisions.end())
+ {
+ // We already know of this collision from before
+ break;
+ }
+ collisions.insert(VType(ait->second, ait->first));
+ first_match = false;
+ }
+ collisions.insert(VType(bit->second, bit->first));
+ }
+ }
+ }
+
+ return !collisions.empty();
+}
+
+void cmQtAutoGenerators::NameCollisionLog(
+ const std::multimap<std::string, std::string>& collisions)
+{
+ typedef std::multimap<std::string, std::string>::const_iterator Iter;
+
+ std::stringstream sbuf;
+ for(Iter it = collisions.begin(); it != collisions.end(); ++it )
+ {
+ sbuf << it->first << " : " << it->second << std::endl;
+ }
+ sbuf.flush();
+ std::cerr << sbuf.str();
+}
+
void cmQtAutoGenerators::LogCommand(const std::vector<std::string>& command)
{
std::stringstream sbuf;