Remove the need to check for .h/.cxx during buildtime

Instead it now relies on cmake time to put that information
correctly into AutomocInfo.cmake

Alex
This commit is contained in:
Alex Neundorf 2011-08-09 09:11:53 +02:00
parent d65689a3bd
commit de91feb367
2 changed files with 167 additions and 168 deletions

View File

@ -73,6 +73,7 @@ bool cmQtAutomoc::ReadAutomocInfoFile(cmMakefile* makefile,
this->QtMajorVersion = makefile->GetSafeDefinition("AM_QT_VERSION_MAJOR");
this->Sources = makefile->GetSafeDefinition("AM_SOURCES");
this->Headers = makefile->GetSafeDefinition("AM_HEADERS");
this->IncludeProjectDirsBefore = makefile->IsOn("AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE");
this->Srcdir = makefile->GetSafeDefinition("AM_CMAKE_CURRENT_SOURCE_DIR");
this->Builddir = makefile->GetSafeDefinition("AM_CMAKE_BINARY_DIR");
@ -282,184 +283,181 @@ bool cmQtAutomoc::RunAutomocQt4()
{
printf("Checking -%s-\n", absFilename.c_str());
}
std::string extension = absFilename.substr(absFilename.find_last_of('.'));
if (extension == ".cpp" || extension == ".cc" || extension == ".mm"
|| extension == ".cxx" || extension == ".C")
const std::string contentsString = this->ReadAll(absFilename);
if (contentsString.empty())
{
const std::string contentsString = this->ReadAll(absFilename);
if (contentsString.empty())
{
std::cerr << "automoc4: empty source file: " << absFilename << std::endl;
continue;
}
const std::string absPath = cmsys::SystemTools::GetFilenamePath(
cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/';
int matchOffset = 0;
if (!mocIncludeRegExp.find(contentsString.c_str()))
{
// no moc #include, look whether we need to create a moc from the .h nevertheless
//std::cout << "no moc #include in the .cpp file";
const std::string basename =
cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename);
for(std::list<std::string>::const_iterator ext =
headerExtensions.begin();
ext != headerExtensions.end();
++ext)
{
const std::string headername = absPath + basename + (*ext);
if (cmsys::SystemTools::FileExists(headername.c_str())
&& includedMocs.find(headername) == includedMocs.end()
&& notIncludedMocs.find(headername) == notIncludedMocs.end())
{
const std::string currentMoc = "moc_" + basename + ".cpp";
const std::string contents = this->ReadAll(headername);
if (qObjectRegExp.find(contents))
{
//std::cout << "header contains Q_OBJECT macro";
notIncludedMocs[headername] = currentMoc;
}
break;
}
}
for(std::list<std::string>::const_iterator ext =
headerExtensions.begin();
ext != headerExtensions.end();
++ext)
{
const std::string privateHeaderName = absPath+basename+"_p"+(*ext);
if (cmsys::SystemTools::FileExists(privateHeaderName.c_str())
&& includedMocs.find(privateHeaderName) == includedMocs.end()
&& notIncludedMocs.find(privateHeaderName) == notIncludedMocs.end())
{
const std::string currentMoc = "moc_" + basename + "_p.cpp";
const std::string contents = this->ReadAll(privateHeaderName);
if (qObjectRegExp.find(contents))
{
//std::cout << "header contains Q_OBJECT macro";
notIncludedMocs[privateHeaderName] = currentMoc;
}
break;
}
}
}
else
{
// for every moc include in the file
do
{
const std::string currentMoc = mocIncludeRegExp.match(1);
//std::cout << "found moc include: " << currentMoc << std::endl;
std::string basename = cmsys::SystemTools::
GetFilenameWithoutLastExtension(currentMoc);
const bool moc_style = this->StartsWith(basename, "moc_");
// If the moc include is of the moc_foo.cpp style we expect the Q_OBJECT class
// declaration in a header file.
// If the moc include is of the foo.moc style we need to look for a Q_OBJECT
// macro in the current source file, if it contains the macro we generate the
// moc file from the source file, else from the header.
//
// TODO: currently any .moc file name will be used if the source contains
// Q_OBJECT
if (moc_style || !qObjectRegExp.find(contentsString))
{
if (moc_style)
{
// basename should be the part of the moc filename used for finding the
// correct header, so we need to remove the moc_ part
basename = basename.substr(4);
}
bool headerFound = false;
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;
notIncludedMocs.erase(sourceFilePath);
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)
{
const std::string &filepath = absPath
+ cmsys::SystemTools::GetFilenamePath(currentMoc)
+ '/' + basename;
for(std::list<std::string>::const_iterator ext =
headerExtensions.begin();
ext != headerExtensions.end();
++ext)
{
const std::string &sourceFilePath = filepath + (*ext);
if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
{
headerFound = true;
includedMocs[sourceFilePath] = currentMoc;
notIncludedMocs.erase(sourceFilePath);
break;
}
}
if (!headerFound)
{
std::cerr << "automoc4: 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
{
std::cerr << "automoc4: The file \"" << absFilename <<
"\" includes the moc file \"" << currentMoc << "\", but \"" <<
absPath + basename + '{' + this->Join(headerExtensions, ',') + '}' <<
"\" does not exist." << std::endl;
::exit(EXIT_FAILURE);
}
}
}
else
{
includedMocs[absFilename] = currentMoc;
notIncludedMocs.erase(absFilename);
}
matchOffset += mocIncludeRegExp.end();
} while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
}
std::cerr << "automoc4: empty source file: " << absFilename << std::endl;
continue;
}
else if (extension == ".h" || extension == ".hpp"
|| extension == ".hxx" || extension == ".H")
const std::string absPath = cmsys::SystemTools::GetFilenamePath(
cmsys::SystemTools::GetRealPath(absFilename.c_str())) + '/';
int matchOffset = 0;
if (!mocIncludeRegExp.find(contentsString.c_str()))
{
if (includedMocs.find(absFilename) == includedMocs.end()
&& notIncludedMocs.find(absFilename) == notIncludedMocs.end())
// no moc #include, look whether we need to create a moc from the .h nevertheless
//std::cout << "no moc #include in the .cpp file";
const std::string basename =
cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename);
for(std::list<std::string>::const_iterator ext =
headerExtensions.begin();
ext != headerExtensions.end();
++ext)
{
// if this header is not getting processed yet and is explicitly mentioned for the
// automoc the moc is run unconditionally on the header and the resulting file is
// included in the _automoc.cpp file (unless there's a .cpp file later on that
// includes the moc from this header)
const std::string currentMoc = "moc_" + cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename) + ".cpp";
notIncludedMocs[absFilename] = currentMoc;
const std::string headername = absPath + basename + (*ext);
if (cmsys::SystemTools::FileExists(headername.c_str())
&& includedMocs.find(headername) == includedMocs.end()
&& notIncludedMocs.find(headername) == notIncludedMocs.end())
{
const std::string currentMoc = "moc_" + basename + ".cpp";
const std::string contents = this->ReadAll(headername);
if (qObjectRegExp.find(contents))
{
//std::cout << "header contains Q_OBJECT macro";
notIncludedMocs[headername] = currentMoc;
}
break;
}
}
for(std::list<std::string>::const_iterator ext =
headerExtensions.begin();
ext != headerExtensions.end();
++ext)
{
const std::string privateHeaderName = absPath+basename+"_p"+(*ext);
if (cmsys::SystemTools::FileExists(privateHeaderName.c_str())
&& includedMocs.find(privateHeaderName) == includedMocs.end()
&& notIncludedMocs.find(privateHeaderName) == notIncludedMocs.end())
{
const std::string currentMoc = "moc_" + basename + "_p.cpp";
const std::string contents = this->ReadAll(privateHeaderName);
if (qObjectRegExp.find(contents))
{
//std::cout << "header contains Q_OBJECT macro";
notIncludedMocs[privateHeaderName] = currentMoc;
}
break;
}
}
}
else
{
if (this->Verbose)
// for every moc include in the file
do
{
std::cout << "automoc4: ignoring file '" << absFilename << "' with unknown suffix" << std::endl;
}
const std::string currentMoc = mocIncludeRegExp.match(1);
//std::cout << "found moc include: " << currentMoc << std::endl;
std::string basename = cmsys::SystemTools::
GetFilenameWithoutLastExtension(currentMoc);
const bool moc_style = this->StartsWith(basename, "moc_");
// If the moc include is of the moc_foo.cpp style we expect the Q_OBJECT class
// declaration in a header file.
// If the moc include is of the foo.moc style we need to look for a Q_OBJECT
// macro in the current source file, if it contains the macro we generate the
// moc file from the source file, else from the header.
//
// TODO: currently any .moc file name will be used if the source contains
// Q_OBJECT
if (moc_style || !qObjectRegExp.find(contentsString))
{
if (moc_style)
{
// basename should be the part of the moc filename used for finding the
// correct header, so we need to remove the moc_ part
basename = basename.substr(4);
}
bool headerFound = false;
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;
notIncludedMocs.erase(sourceFilePath);
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)
{
const std::string &filepath = absPath
+ cmsys::SystemTools::GetFilenamePath(currentMoc)
+ '/' + basename;
for(std::list<std::string>::const_iterator ext =
headerExtensions.begin();
ext != headerExtensions.end();
++ext)
{
const std::string &sourceFilePath = filepath + (*ext);
if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
{
headerFound = true;
includedMocs[sourceFilePath] = currentMoc;
notIncludedMocs.erase(sourceFilePath);
break;
}
}
if (!headerFound)
{
std::cerr << "automoc4: 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
{
std::cerr << "automoc4: The file \"" << absFilename <<
"\" includes the moc file \"" << currentMoc << "\", but \"" <<
absPath + basename + '{' + this->Join(headerExtensions, ',') + '}' <<
"\" does not exist." << std::endl;
::exit(EXIT_FAILURE);
}
}
}
else
{
includedMocs[absFilename] = currentMoc;
notIncludedMocs.erase(absFilename);
}
matchOffset += mocIncludeRegExp.end();
} while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
}
}
std::vector<std::string> headerFiles;
cmSystemTools::ExpandListArgument(this->Headers, headerFiles);
for (std::vector<std::string>::const_iterator it = headerFiles.begin();
it != headerFiles.end();
++it)
{
const std::string &absFilename = *it;
if (this->Verbose)
{
printf("Checking -%s-\n", absFilename.c_str());
}
if (includedMocs.find(absFilename) == includedMocs.end()
&& notIncludedMocs.find(absFilename) == notIncludedMocs.end())
{
// if this header is not getting processed yet and is explicitly mentioned for the
// automoc the moc is run unconditionally on the header and the resulting file is
// included in the _automoc.cpp file (unless there's a .cpp file later on that
// includes the moc from this header)
const std::string currentMoc = "moc_" + cmsys::SystemTools::GetFilenameWithoutLastExtension(absFilename) + ".cpp";
notIncludedMocs[absFilename] = currentMoc;
}
}

View File

@ -32,6 +32,7 @@ private:
std::string QtMajorVersion;
std::string Sources;
std::string Headers;
bool IncludeProjectDirsBefore;
std::string Srcdir;
std::string Builddir;