automoc: rework the checking for the matching header, to give better warnings

Alex
This commit is contained in:
Alex Neundorf 2011-11-10 20:56:46 +01:00
parent d08bc32bc2
commit 7242822897

View File

@ -545,64 +545,57 @@ void cmQtAutomoc::ParseCppFile(const std::string& absFilename,
// finding the correct header, so we need to remove the moc_ part // finding the correct header, so we need to remove the moc_ part
basename = basename.substr(4); basename = basename.substr(4);
bool headerFound = false; std::string mocSubDir;
if (currentMoc.find_first_of('/') != std::string::npos)
{
mocSubDir = absPath
+ cmsys::SystemTools::GetFilenamePath(currentMoc) + '/';
}
std::string headerToMoc;
for(std::list<std::string>::const_iterator ext = for(std::list<std::string>::const_iterator ext =
headerExtensions.begin(); headerExtensions.begin();
ext != headerExtensions.end(); ext != headerExtensions.end();
++ext) ++ext)
{ {
const std::string &sourceFilePath = absPath + basename + (*ext); std::string sourceFilePath = absPath + basename + (*ext);
if (cmsys::SystemTools::FileExists(sourceFilePath.c_str())) if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
{ {
headerFound = true; headerToMoc = sourceFilePath;
includedMocs[sourceFilePath] = currentMoc;
break; break;
} }
} if (!mocSubDir.empty())
if (!headerFound)
{
// the moc file is in a subdir => look for the header in the
// same subdir
if (currentMoc.find_first_of('/') != std::string::npos)
{ {
const std::string &filepath = absPath sourceFilePath = mocSubDir + basename + (*ext);
+ cmsys::SystemTools::GetFilenamePath(currentMoc) if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
+ '/' + basename; {
headerToMoc = sourceFilePath;
break;
}
}
}
for(std::list<std::string>::const_iterator ext = if (!headerToMoc.empty())
headerExtensions.begin(); {
ext != headerExtensions.end(); includedMocs[headerToMoc] = currentMoc;
++ext) }
{ else
const std::string &sourceFilePath = filepath + (*ext); {
if (cmsys::SystemTools::FileExists(sourceFilePath.c_str())) std::cerr << "AUTOMOC: The file \"" << absFilename
{ << "\" includes the moc file \"" << currentMoc
headerFound = true; << "\", but could not find header \"" << basename
includedMocs[sourceFilePath] = currentMoc; << '{' << this->Join(headerExtensions, ',') << "}\" ";
break; if (mocSubDir.empty())
} {
} std::cerr << "in " << absPath << std::endl;
if (!headerFound)
{
std::cerr << "AUTOMOC: The file \"" << absFilename
<< "\" includes the moc file \"" << currentMoc
<< "\", but neither \"" << absPath << basename
<< '{' << this->Join(headerExtensions, ',')
<< "}\" nor \"" << filepath << '{'
<< this->Join(headerExtensions, ',') << '}'
<< "\" exist." << std::endl;
::exit(EXIT_FAILURE);
}
} }
else else
{ {
std::cerr << "AUTOMOC: The file \"" << absFilename std::cerr << "neither in " << absPath
<< "\" includes the moc file \"" << currentMoc << " nor in " << mocSubDir << std::endl;
<< "\", but \"" << absPath << basename << '{'
<< this->Join(headerExtensions, ',') << '}'
<< "\" does not exist." << std::endl;
::exit(EXIT_FAILURE);
} }
::exit(EXIT_FAILURE);
} }
} }
else else