summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Neundorf <neundorf@kde.org>2011-08-09 07:11:53 (GMT)
committerAlex Neundorf <neundorf@kde.org>2011-08-14 13:53:50 (GMT)
commitde91feb367c127294a56b492799c4bf042954fd8 (patch)
treea5b9feda041be77caa3d2f9d68b0f53ecf11d7f5
parentd65689a3bd059b2f70e11644e43df4251c71987e (diff)
downloadCMake-de91feb367c127294a56b492799c4bf042954fd8.zip
CMake-de91feb367c127294a56b492799c4bf042954fd8.tar.gz
CMake-de91feb367c127294a56b492799c4bf042954fd8.tar.bz2
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
-rw-r--r--Source/cmQtAutomoc.cxx286
-rw-r--r--Source/cmQtAutomoc.h1
2 files changed, 143 insertions, 144 deletions
diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx
index 7fac2f2..5494b2a 100644
--- a/Source/cmQtAutomoc.cxx
+++ b/Source/cmQtAutomoc.cxx
@@ -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())) + '/';
+ 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()))
+ 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)
{
- // 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 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))
{
- 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;
+ //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)
+ }
+ 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 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))
{
- 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;
+ //std::cout << "header contains Q_OBJECT macro";
+ notIncludedMocs[privateHeaderName] = currentMoc;
}
+ break;
}
}
- else
+ }
+ else
+ {
+ // for every moc include in the file
+ do
{
- // 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))
{
- 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)
{
- 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);
- }
+ // 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)
+ 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()))
{
- const std::string &sourceFilePath = absPath + basename + (*ext);
- if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
- {
- headerFound = true;
- includedMocs[sourceFilePath] = currentMoc;
- notIncludedMocs.erase(sourceFilePath);
- break;
- }
+ headerFound = true;
+ includedMocs[sourceFilePath] = currentMoc;
+ notIncludedMocs.erase(sourceFilePath);
+ break;
}
- if (!headerFound)
+ }
+ 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)
{
- // 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 &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)
+ const std::string &sourceFilePath = filepath + (*ext);
+ if (cmsys::SystemTools::FileExists(sourceFilePath.c_str()))
{
- 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);
+ headerFound = true;
+ includedMocs[sourceFilePath] = currentMoc;
+ notIncludedMocs.erase(sourceFilePath);
+ break;
}
}
- else
+ if (!headerFound)
{
std::cerr << "automoc4: The file \"" << absFilename <<
- "\" includes the moc file \"" << currentMoc << "\", but \"" <<
- absPath + basename + '{' + this->Join(headerExtensions, ',') + '}' <<
- "\" does not exist." << std::endl;
+ "\" 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));
- }
+ }
+ else
+ {
+ includedMocs[absFilename] = currentMoc;
+ notIncludedMocs.erase(absFilename);
+ }
+ matchOffset += mocIncludeRegExp.end();
+ } while(mocIncludeRegExp.find(contentsString.c_str() + matchOffset));
}
- else if (extension == ".h" || extension == ".hpp"
- || extension == ".hxx" || extension == ".H")
+ }
+
+ 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)
{
- 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;
- }
+ printf("Checking -%s-\n", absFilename.c_str());
}
- else
+ if (includedMocs.find(absFilename) == includedMocs.end()
+ && notIncludedMocs.find(absFilename) == notIncludedMocs.end())
{
- if (this->Verbose)
- {
- std::cout << "automoc4: ignoring file '" << absFilename << "' with unknown suffix" << std::endl;
- }
+ // 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;
}
}
diff --git a/Source/cmQtAutomoc.h b/Source/cmQtAutomoc.h
index 0dafd4a..891b47a 100644
--- a/Source/cmQtAutomoc.h
+++ b/Source/cmQtAutomoc.h
@@ -32,6 +32,7 @@ private:
std::string QtMajorVersion;
std::string Sources;
+ std::string Headers;
bool IncludeProjectDirsBefore;
std::string Srcdir;
std::string Builddir;