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;
for(std::list<std::string>::const_iterator ext =
headerExtensions.begin();
ext != headerExtensions.end();
++ext)
{
const std::string &sourceFilePath = absPath + basename + (*ext);
if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
{
headerFound = true;
includedMocs[sourceFilePath] = currentMoc;
break;
}
}
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) if (currentMoc.find_first_of('/') != std::string::npos)
{ {
const std::string &filepath = absPath mocSubDir = absPath
+ cmsys::SystemTools::GetFilenamePath(currentMoc) + cmsys::SystemTools::GetFilenamePath(currentMoc) + '/';
+ '/' + basename; }
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 = filepath + (*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;
}
if (!mocSubDir.empty())
{
sourceFilePath = mocSubDir + basename + (*ext);
if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
{
headerToMoc = sourceFilePath;
break; break;
} }
} }
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);
} }
if (!headerToMoc.empty())
{
includedMocs[headerToMoc] = currentMoc;
} }
else else
{ {
std::cerr << "AUTOMOC: The file \"" << absFilename std::cerr << "AUTOMOC: The file \"" << absFilename
<< "\" includes the moc file \"" << currentMoc << "\" includes the moc file \"" << currentMoc
<< "\", but \"" << absPath << basename << '{' << "\", but could not find header \"" << basename
<< this->Join(headerExtensions, ',') << '}' << '{' << this->Join(headerExtensions, ',') << "}\" ";
<< "\" does not exist." << std::endl; if (mocSubDir.empty())
::exit(EXIT_FAILURE); {
std::cerr << "in " << absPath << std::endl;
} }
else
{
std::cerr << "neither in " << absPath
<< " nor in " << mocSubDir << std::endl;
}
::exit(EXIT_FAILURE);
} }
} }
else else