summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-04-20 13:52:34 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2016-04-20 13:52:34 (GMT)
commitf22365279078d522e7b5347ecb7b87377f50f0c5 (patch)
treeead910be33b2f1e23f946127ba616bf9e8bd0ba1 /Source
parent0a05b2bd41e63d3695e79efb20d0c19314abcb9c (diff)
parent840b830bc6a76afe207bc08ca164eaabb731acaf (diff)
downloadCMake-f22365279078d522e7b5347ecb7b87377f50f0c5.zip
CMake-f22365279078d522e7b5347ecb7b87377f50f0c5.tar.gz
CMake-f22365279078d522e7b5347ecb7b87377f50f0c5.tar.bz2
Merge topic 'autogen-cleanups'
840b830b Autogen: Qrc processing: Generate single map with final input / output names bc4c7751 Autogen: Ui processing: Generate single map with final input / output names 47e60bc5 Autogen: Split out UI file generation code to dedicated method cf679ea8 Autogen: Split out moc file generation code to dedicated method 3ea1d090 Autogen: Rename method GenerateQrc{ => Files} 8ced8bb9 Autogen: New logCommand method. It prints commands using std::cout. 95064a6d Autogen: Rename header extension Join method to JoinExts 7a73c404 Autogen: Use SystemTools string functions instead of rolling out own
Diffstat (limited to 'Source')
-rw-r--r--Source/cmQtAutoGenerators.cxx446
-rw-r--r--Source/cmQtAutoGenerators.h19
2 files changed, 288 insertions, 177 deletions
diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx
index ebe08b0..c07a0a6 100644
--- a/Source/cmQtAutoGenerators.cxx
+++ b/Source/cmQtAutoGenerators.cxx
@@ -410,9 +410,11 @@ cmQtAutoGenerators::WriteOldMocDefinitionsFile(
void cmQtAutoGenerators::Init()
{
+ this->OutMocCppFilenameRel = this->TargetName;
+ this->OutMocCppFilenameRel += ".cpp";
+
this->OutMocCppFilename = this->Builddir;
- this->OutMocCppFilename += this->TargetName;
- this->OutMocCppFilename += ".cpp";
+ this->OutMocCppFilename += this->OutMocCppFilenameRel;
std::vector<std::string> cdefList;
cmSystemTools::ExpandListArgument(this->MocCompileDefinitionsStr, cdefList);
@@ -464,7 +466,7 @@ void cmQtAutoGenerators::Init()
std::list<std::string>::iterator it = this->MocIncludes.begin();
while (it != this->MocIncludes.end())
{
- if (this->StartsWith(*it, binDir))
+ if (cmsys::SystemTools::StringStartsWith(*it, binDir.c_str()))
{
sortedMocIncludes.push_back(*it);
it = this->MocIncludes.erase(it);
@@ -477,7 +479,7 @@ void cmQtAutoGenerators::Init()
it = this->MocIncludes.begin();
while (it != this->MocIncludes.end())
{
- if (this->StartsWith(*it, srcDir))
+ if (cmsys::SystemTools::StringStartsWith(*it, srcDir.c_str()))
{
sortedMocIncludes.push_back(*it);
it = this->MocIncludes.erase(it);
@@ -589,56 +591,17 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile)
std::map<std::string, std::string> notIncludedMocs;
this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs, includedUis);
- // run moc on all the moc's that are #included in source files
- for(std::map<std::string, std::string>::const_iterator
- it = includedMocs.begin();
- it != includedMocs.end();
- ++it)
+ if(!this->MocExecutable.empty())
{
- this->GenerateMoc(it->first, it->second);
+ this->GenerateMocFiles ( includedMocs, notIncludedMocs );
}
- for(std::map<std::string, std::vector<std::string> >::const_iterator
- it = includedUis.begin();
- it != includedUis.end();
- ++it)
+ if(!this->UicExecutable.empty())
{
- for (std::vector<std::string>::const_iterator nit = it->second.begin();
- nit != it->second.end();
- ++nit)
- {
- this->GenerateUi(it->first, *nit);
- }
+ this->GenerateUiFiles ( includedUis );
}
-
if(!this->RccExecutable.empty())
{
- this->GenerateQrc();
- }
-
- std::stringstream outStream;
- outStream << "/* This file is autogenerated, do not edit*/\n";
-
- bool automocCppChanged = false;
- if (notIncludedMocs.empty())
- {
- outStream << "enum some_compilers { need_more_than_nothing };\n";
- }
- else
- {
- // run moc on the remaining headers and include them in
- // the _automoc.cpp file
- for(std::map<std::string, std::string>::const_iterator
- it = notIncludedMocs.begin();
- it != notIncludedMocs.end();
- ++it)
- {
- bool mocSuccess = this->GenerateMoc(it->first, it->second);
- if (mocSuccess)
- {
- automocCppChanged = true;
- }
- outStream << "#include \"" << it->second << "\"\n";
- }
+ this->GenerateQrcFiles();
}
if (this->RunMocFailed)
@@ -646,7 +609,6 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile)
std::cerr << "moc failed..." << std::endl;
return false;
}
-
if (this->RunUicFailed)
{
std::cerr << "uic failed..." << std::endl;
@@ -657,25 +619,6 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile)
std::cerr << "rcc failed..." << std::endl;
return false;
}
- outStream.flush();
- std::string automocSource = outStream.str();
- if (!automocCppChanged)
- {
- // compare contents of the _automoc.cpp file
- const std::string oldContents = ReadAll(this->OutMocCppFilename);
- if (oldContents == automocSource)
- {
- // nothing changed: don't touch the _automoc.cpp file
- return true;
- }
- }
-
- // source file that includes all remaining moc files (_automoc.cpp file)
- cmsys::ofstream outfile;
- outfile.open(this->OutMocCppFilename.c_str(),
- std::ios::trunc);
- outfile << automocSource;
- outfile.close();
return true;
}
@@ -762,7 +705,7 @@ void cmQtAutoGenerators::ParseCppFile(const std::string& absFilename,
std::cerr << "AUTOGEN: error: " << absFilename << ": The file "
<< "includes the moc file \"" << currentMoc << "\", "
<< "but could not find header \"" << basename
- << '{' << this->Join(headerExtensions, ',') << "}\" ";
+ << '{' << this->JoinExts(headerExtensions) << "}\" ";
if (mocSubDir.empty())
{
std::cerr << "in " << absPath << "\n" << std::endl;
@@ -937,7 +880,7 @@ void cmQtAutoGenerators::StrictParseCppFile(const std::string& absFilename,
std::cerr << "AUTOGEN: error: " << absFilename << " The file "
<< "includes the moc file \"" << currentMoc << "\", "
<< "but could not find header \"" << basename
- << '{' << this->Join(headerExtensions, ',') << "}\" ";
+ << '{' << this->JoinExts(headerExtensions) << "}\" ";
if (mocSubDir.empty())
{
std::cerr << "in " << absPath << "\n" << std::endl;
@@ -1119,6 +1062,102 @@ void cmQtAutoGenerators::ParseHeaders(const std::set<std::string>& absHeaders,
}
}
+
+bool cmQtAutoGenerators::GenerateMocFiles(
+ const std::map<std::string, std::string>& includedMocs,
+ const std::map<std::string, std::string>& notIncludedMocs )
+{
+ // generate moc files that are included by source files.
+ for(std::map<std::string, std::string>::const_iterator
+ it = includedMocs.begin(); it != includedMocs.end(); ++it)
+ {
+ if (!this->GenerateMoc(it->first, it->second))
+ {
+ if (this->RunMocFailed)
+ {
+ return false;
+ }
+ }
+ }
+
+ // generate moc files that are _not_ included by source files.
+ bool automocCppChanged = false;
+ for(std::map<std::string, std::string>::const_iterator
+ it = notIncludedMocs.begin(); it != notIncludedMocs.end(); ++it)
+ {
+ if (this->GenerateMoc(it->first, it->second))
+ {
+ automocCppChanged = true;
+ }
+ else
+ {
+ if (this->RunMocFailed)
+ {
+ return false;
+ }
+ }
+ }
+
+ // compose _automoc.cpp content
+ std::string automocSource;
+ {
+ std::stringstream outStream;
+ outStream << "/* This file is autogenerated, do not edit*/\n";
+ if( notIncludedMocs.empty() )
+ {
+ outStream << "enum some_compilers { need_more_than_nothing };\n";
+ }
+ else
+ {
+ for(std::map<std::string, std::string>::const_iterator
+ it = notIncludedMocs.begin();
+ it != notIncludedMocs.end();
+ ++it)
+ {
+ outStream << "#include \"" << it->second << "\"\n";
+ }
+ }
+ outStream.flush();
+ automocSource = outStream.str();
+ }
+
+ // check if we even need to update _automoc.cpp
+ if (!automocCppChanged)
+ {
+ // compare contents of the _automoc.cpp file
+ const std::string oldContents = ReadAll(this->OutMocCppFilename);
+ if (oldContents == automocSource)
+ {
+ // nothing changed: don't touch the _automoc.cpp file
+ if (this->Verbose)
+ {
+ std::cout << "AUTOGEN: " << this->OutMocCppFilenameRel
+ << " still up to date" << std::endl;
+ }
+ return true;
+ }
+ }
+
+ // actually write _automoc.cpp
+ {
+ std::string msg = "Generating ";
+ msg += this->OutMocCppFilenameRel;
+ cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue
+ |cmsysTerminal_Color_ForegroundBold,
+ msg.c_str(), true, this->ColorOutput);
+ }
+ {
+ cmsys::ofstream outfile;
+ outfile.open(this->OutMocCppFilename.c_str(),
+ std::ios::trunc);
+ outfile << automocSource;
+ outfile.close();
+ }
+
+ return true;
+}
+
+
bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile,
const std::string& mocFileName)
{
@@ -1159,13 +1198,7 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile,
if (this->Verbose)
{
- for(std::vector<std::string>::const_iterator cmdIt = command.begin();
- cmdIt != command.end();
- ++cmdIt)
- {
- std::cout << *cmdIt << " ";
- }
- std::cout << std::endl;
+ this->LogCommand(command);
}
std::string output;
@@ -1184,28 +1217,74 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile,
return false;
}
+
+bool cmQtAutoGenerators::GenerateUiFiles(
+ const std::map<std::string, std::vector<std::string> >& includedUis )
+{
+ // single map with input / output names
+ std::map<std::string, std::map<std::string, std::string> > uiGenMap;
+ for(std::map<std::string, std::vector<std::string> >::const_iterator
+ it = includedUis.begin(); it != includedUis.end(); ++it)
+ {
+ // source file path
+ std::string sourcePath = cmsys::SystemTools::GetFilenamePath(it->first);
+ sourcePath += '/';
+ // insert new map for source file an use new reference
+ uiGenMap[it->first] = std::map<std::string, std::string>();
+ std::map<std::string, std::string>& sourceMap = uiGenMap[it->first];
+ for (std::vector<std::string>::const_iterator sit = it->second.begin();
+ sit != it->second.end();
+ ++sit)
+ {
+ const std::string & uiFileName = *sit;
+ const std::string uiInputFile = sourcePath + uiFileName + ".ui";
+ const std::string uiOutputFile = "ui_" + uiFileName + ".h";
+ sourceMap[uiInputFile] = uiOutputFile;
+ }
+ }
+
+ // generate ui files
+ for(std::map<std::string, std::map<std::string, std::string> >::
+ const_iterator it = uiGenMap.begin(); it != uiGenMap.end(); ++it)
+ {
+ for(std::map<std::string, std::string>::const_iterator
+ sit = it->second.begin();
+ sit != it->second.end();
+ ++sit)
+ {
+ if (!this->GenerateUi(it->first, sit->first, sit->second) )
+ {
+ if (this->RunUicFailed)
+ {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+}
+
+
bool cmQtAutoGenerators::GenerateUi(const std::string& realName,
- const std::string& uiFileName)
+ const std::string& uiInputFile,
+ const std::string& uiOutputFile)
{
if (!cmsys::SystemTools::FileExists(this->Builddir.c_str(), false))
{
cmsys::SystemTools::MakeDirectory(this->Builddir.c_str());
}
- const std::string path = cmsys::SystemTools::GetFilenamePath(
- realName) + '/';
-
- std::string ui_output_file = "ui_" + uiFileName + ".h";
- std::string ui_input_file = path + uiFileName + ".ui";
+ const ::std::string uiBuildFile = this->Builddir + uiOutputFile;
int sourceNewerThanUi = 0;
- bool success = cmsys::SystemTools::FileTimeCompare(ui_input_file,
- this->Builddir + ui_output_file,
+ bool success = cmsys::SystemTools::FileTimeCompare(uiInputFile,
+ uiBuildFile,
&sourceNewerThanUi);
if (this->GenerateAll || !success || sourceNewerThanUi >= 0)
{
std::string msg = "Generating ";
- msg += ui_output_file;
+ msg += uiOutputFile;
cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue
|cmsysTerminal_Color_ForegroundBold,
msg.c_str(), true, this->ColorOutput);
@@ -1215,7 +1294,7 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName,
std::vector<std::string> opts = this->UicTargetOptions;
std::map<std::string, std::string>::const_iterator optionIt
- = this->UicOptions.find(ui_input_file);
+ = this->UicOptions.find(uiInputFile);
if (optionIt != this->UicOptions.end())
{
std::vector<std::string> fileOpts;
@@ -1226,18 +1305,12 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName,
command.insert(command.end(), opts.begin(), opts.end());
command.push_back("-o");
- command.push_back(this->Builddir + ui_output_file);
- command.push_back(ui_input_file);
+ command.push_back(uiBuildFile);
+ command.push_back(uiInputFile);
if (this->Verbose)
{
- for(std::vector<std::string>::const_iterator cmdIt = command.begin();
- cmdIt != command.end();
- ++cmdIt)
- {
- std::cout << *cmdIt << " ";
- }
- std::cout << std::endl;
+ this->LogCommand(command);
}
std::string output;
int retVal = 0;
@@ -1245,11 +1318,11 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName,
&retVal);
if (!result || retVal)
{
- std::cerr << "AUTOUIC: error: process for " << ui_output_file <<
+ std::cerr << "AUTOUIC: error: process for " << uiOutputFile <<
" needed by\n \"" << realName << "\"\nfailed:\n" << output
<< std::endl;
this->RunUicFailed = true;
- cmSystemTools::RemoveFile(ui_output_file);
+ cmSystemTools::RemoveFile(uiOutputFile);
return false;
}
return true;
@@ -1276,79 +1349,121 @@ bool cmQtAutoGenerators::InputFilesNewerThanQrc(const std::string& qrcFile,
return false;
}
-bool cmQtAutoGenerators::GenerateQrc()
+bool cmQtAutoGenerators::GenerateQrcFiles()
{
+ // generate single map with input / output names
+ std::map<std::string, std::string> qrcGenMap;
for(std::vector<std::string>::const_iterator si = this->RccSources.begin();
si != this->RccSources.end(); ++si)
{
- std::string ext = cmsys::SystemTools::GetFilenameLastExtension(*si);
-
- if (ext != ".qrc")
+ const std::string ext = cmsys::SystemTools::GetFilenameLastExtension(*si);
+ if (ext == ".qrc")
{
- continue;
+ std::string basename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(*si);
+ std::string qrcOutputFile = "CMakeFiles/" + this->OriginTargetName
+ + ".dir/qrc_" + basename + ".cpp";
+ qrcGenMap[*si] = qrcOutputFile;
}
- std::vector<std::string> command;
- command.push_back(this->RccExecutable);
+ }
- std::string basename = cmsys::SystemTools::
- GetFilenameWithoutLastExtension(*si);
+ // generate qrc files
+ for(std::map<std::string, std::string>::const_iterator
+ si = qrcGenMap.begin(); si != qrcGenMap.end(); ++si)
+ {
+ if (!this->GenerateQrc( si->first, si->second))
+ {
+ if (this->RunRccFailed)
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+}
- std::string rcc_output_file = this->Builddir
- + "CMakeFiles/" + this->OriginTargetName
- + ".dir/qrc_" + basename + ".cpp";
+bool cmQtAutoGenerators::GenerateQrc (
+ const std::string& qrcInputFile,
+ const std::string& qrcOutputFile )
+{
+ const std::string basename = cmsys::SystemTools::
+ GetFilenameWithoutLastExtension(qrcInputFile);
+ const ::std::string qrcBuildFile = this->Builddir + qrcOutputFile;
+
+ int sourceNewerThanQrc = 0;
+ bool generateQrc = !cmsys::SystemTools::FileTimeCompare(qrcInputFile,
+ qrcBuildFile,
+ &sourceNewerThanQrc);
+ generateQrc = generateQrc || (sourceNewerThanQrc >= 0);
+ generateQrc = generateQrc || this->InputFilesNewerThanQrc(qrcInputFile,
+ qrcBuildFile);
+
+ if (this->GenerateAll || generateQrc)
+ {
+ std::string msg = "Generating ";
+ msg += qrcOutputFile;
+ cmSystemTools::MakefileColorEcho(cmsysTerminal_Color_ForegroundBlue
+ |cmsysTerminal_Color_ForegroundBold,
+ msg.c_str(), true, this->ColorOutput);
- int sourceNewerThanQrc = 0;
- bool generateQrc = !cmsys::SystemTools::FileTimeCompare(*si,
- rcc_output_file,
- &sourceNewerThanQrc);
- generateQrc = generateQrc || (sourceNewerThanQrc >= 0);
- generateQrc = generateQrc || this->InputFilesNewerThanQrc(*si,
- rcc_output_file);
+ std::vector<std::string> command;
+ command.push_back(this->RccExecutable);
- if (this->GenerateAll || generateQrc)
+ std::map<std::string, std::string>::const_iterator optionIt
+ = this->RccOptions.find(qrcInputFile);
+ if (optionIt != this->RccOptions.end())
{
- std::map<std::string, std::string>::const_iterator optionIt
- = this->RccOptions.find(*si);
- if (optionIt != this->RccOptions.end())
- {
- cmSystemTools::ExpandListArgument(optionIt->second, command);
- }
+ cmSystemTools::ExpandListArgument(optionIt->second, command);
+ }
- command.push_back("-name");
- command.push_back(basename);
- command.push_back("-o");
- command.push_back(rcc_output_file);
- command.push_back(*si);
+ command.push_back("-name");
+ command.push_back(basename);
+ command.push_back("-o");
+ command.push_back(qrcBuildFile);
+ command.push_back(qrcInputFile);
- if (this->Verbose)
- {
- for(std::vector<std::string>::const_iterator cmdIt = command.begin();
- cmdIt != command.end();
- ++cmdIt)
- {
- std::cout << *cmdIt << " ";
- }
- std::cout << std::endl;
- }
- std::string output;
- int retVal = 0;
- bool result = cmSystemTools::RunSingleCommand(command, &output, &output,
- &retVal);
- if (!result || retVal)
- {
- std::cerr << "AUTORCC: error: process for " << rcc_output_file <<
- " failed:\n" << output << std::endl;
- this->RunRccFailed = true;
- cmSystemTools::RemoveFile(rcc_output_file);
- return false;
- }
+ if (this->Verbose)
+ {
+ this->LogCommand(command);
+ }
+ std::string output;
+ int retVal = 0;
+ bool result = cmSystemTools::RunSingleCommand(command, &output, &output,
+ &retVal);
+ if (!result || retVal)
+ {
+ std::cerr << "AUTORCC: error: process for " << qrcOutputFile <<
+ " failed:\n" << output << std::endl;
+ this->RunRccFailed = true;
+ cmSystemTools::RemoveFile(qrcBuildFile);
+ return false;
}
}
return true;
}
-std::string cmQtAutoGenerators::Join(const std::vector<std::string>& lst,
- char separator)
+void cmQtAutoGenerators::LogCommand(const std::vector<std::string>& command)
+{
+ std::stringstream sbuf;
+ for(std::vector<std::string>::const_iterator cmdIt = command.begin();
+ cmdIt != command.end();
+ ++cmdIt)
+ {
+ if ( cmdIt != command.begin() )
+ {
+ sbuf << " ";
+ }
+ sbuf << *cmdIt;
+ }
+ sbuf.flush();
+ if ( !sbuf.str().empty() )
+ {
+ std::cout << sbuf.str();
+ std::cout << std::endl;
+ }
+}
+
+std::string cmQtAutoGenerators::JoinExts(const std::vector<std::string>& lst)
{
if (lst.empty())
{
@@ -1356,30 +1471,17 @@ std::string cmQtAutoGenerators::Join(const std::vector<std::string>& lst,
}
std::string result;
+ std::string separator = ",";
for (std::vector<std::string>::const_iterator it = lst.begin();
it != lst.end();
++it)
{
- result += "." + (*it) + separator;
+ if(it != lst.begin())
+ {
+ result += separator;
+ }
+ result += '.' + (*it);
}
result.erase(result.end() - 1);
return result;
}
-
-
-bool cmQtAutoGenerators::StartsWith(const std::string& str,
- const std::string& with)
-{
- return (str.substr(0, with.length()) == with);
-}
-
-
-bool cmQtAutoGenerators::EndsWith(const std::string& str,
- const std::string& with)
-{
- if (with.length() > (str.length()))
- {
- return false;
- }
- return (str.substr(str.length() - with.length(), with.length()) == with);
-}
diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h
index ab7b6ed..68ab480 100644
--- a/Source/cmQtAutoGenerators.h
+++ b/Source/cmQtAutoGenerators.h
@@ -39,10 +39,19 @@ private:
std::string MakeCompileSettingsString(cmMakefile* makefile);
bool RunAutogen(cmMakefile* makefile);
+ bool GenerateMocFiles(
+ const std::map<std::string, std::string>& includedMocs,
+ const std::map<std::string, std::string>& notIncludedMocs);
bool GenerateMoc(const std::string& sourceFile,
const std::string& mocFileName);
- bool GenerateUi(const std::string& realName, const std::string& uiFileName);
- bool GenerateQrc();
+ bool GenerateUiFiles(
+ const std::map<std::string, std::vector<std::string> >& includedUis );
+ bool GenerateUi(const std::string& realName,
+ const std::string& uiInputFile,
+ const std::string& uiOutputFile );
+ bool GenerateQrcFiles();
+ bool GenerateQrc(const std::string& qrcInputFile,
+ const std::string& qrcOutputFile);
void ParseCppFile(const std::string& absFilename,
const std::vector<std::string>& headerExtensions,
std::map<std::string, std::string>& includedMocs,
@@ -69,9 +78,8 @@ private:
void Init();
- std::string Join(const std::vector<std::string>& lst, char separator);
- bool EndsWith(const std::string& str, const std::string& with);
- bool StartsWith(const std::string& str, const std::string& with);
+ void LogCommand(const std::vector<std::string>& command);
+ std::string JoinExts(const std::vector<std::string>& lst);
static void MergeUicOptions(std::vector<std::string> &opts,
const std::vector<std::string> &fileOpts, bool isQt5);
@@ -101,6 +109,7 @@ private:
std::string CurrentCompileSettingsStr;
std::string OldCompileSettingsStr;
+ std::string OutMocCppFilenameRel;
std::string OutMocCppFilename;
std::list<std::string> MocIncludes;
std::list<std::string> MocDefinitions;