summaryrefslogtreecommitdiffstats
path: root/Source/cmQtAutomoc.cxx
diff options
context:
space:
mode:
authorAlex Neundorf <neundorf@kde.org>2011-11-10 20:30:06 (GMT)
committerAlex Neundorf <neundorf@kde.org>2011-11-10 21:12:03 (GMT)
commit81c43b4fb6e46430e730e2cb268c283e47995b78 (patch)
tree0aa19f87852ed785ccb62a39bd456371d98240e9 /Source/cmQtAutomoc.cxx
parent72428228970b8b7da54a3c98a36eca6810c46bb5 (diff)
downloadCMake-81c43b4fb6e46430e730e2cb268c283e47995b78.zip
CMake-81c43b4fb6e46430e730e2cb268c283e47995b78.tar.gz
CMake-81c43b4fb6e46430e730e2cb268c283e47995b78.tar.bz2
automoc: handle the case when the developer includes the wrong mocfile
There are multiple/many places in KDE where the developer includes moc_foo.cpp, and expects moc to run on foo.cpp, instead of foo.h. He should use foo.moc, but right now this is handled by automoc4, so we must stay compatible. So support this too, but warn about it. Alex
Diffstat (limited to 'Source/cmQtAutomoc.cxx')
-rw-r--r--Source/cmQtAutomoc.cxx33
1 files changed, 33 insertions, 0 deletions
diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx
index 3dc515e..b715df6 100644
--- a/Source/cmQtAutomoc.cxx
+++ b/Source/cmQtAutomoc.cxx
@@ -520,6 +520,11 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
const std::string scannedFileBasename = cmsys::SystemTools::
GetFilenameWithoutLastExtension(absFilename);
+ bool dotMocIncluded = false;
+ bool mocUnderscoreIncluded = false;
+ std::string ownMocUnderscoreFile;
+ std::string ownMocHeaderFile;
+
std::string::size_type matchOffset = 0;
if (mocIncludeRegExp.find(contentsString.c_str()))
{
@@ -578,6 +583,12 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
if (!headerToMoc.empty())
{
includedMocs[headerToMoc] = currentMoc;
+ if (basename == scannedFileBasename)
+ {
+ mocUnderscoreIncluded = true;
+ ownMocUnderscoreFile = currentMoc;
+ ownMocHeaderFile = headerToMoc;
+ }
}
else
{
@@ -611,11 +622,33 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
::exit(EXIT_FAILURE);
}
includedMocs[absFilename] = currentMoc;
+ dotMocIncluded = true;
}
matchOffset += mocIncludeRegExp.end();
} while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
}
+ // In this case, check whether the scanned file itself contains a Q_OBJECT.
+ // If this is the case, the moc_foo.cpp should probably be generated from
+ // foo.cpp instead of foo.h, because otherwise it won't build.
+ // But warn, since this is not how it is supposed to be used.
+ if ((dotMocIncluded == false) && (mocUnderscoreIncluded == true))
+ {
+ cmsys::RegularExpression qObjectRegExp("[\n][ \t]*Q_OBJECT[^a-zA-Z0-9_]");
+ if (qObjectRegExp.find(contentsString))
+ {
+ std::cerr << "AUTOMOC: The file \"" << absFilename
+ << "\" contains a Q_OBJECT macro, but does not include "
+ << "\"" << scannedFileBasename << ".moc\", but instead includes "
+ << "\"" << ownMocUnderscoreFile << "\". Running moc on "
+ << "\"" << absFilename << "\" ! Better include \""
+ << scannedFileBasename << ".moc\" to get a robust build."
+ << std::endl;
+ includedMocs[absFilename] = ownMocUnderscoreFile;
+ includedMocs.erase(ownMocHeaderFile);
+ }
+ }
+
// search for header files and private header files we may need to moc:
const std::string basename =
cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename);