From 7a73c404dd63aef0e68da9ef70ac706a6339c476 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 18 Apr 2016 11:22:00 +0200 Subject: Autogen: Use SystemTools string functions instead of rolling out own --- Source/cmQtAutoGenerators.cxx | 22 ++-------------------- Source/cmQtAutoGenerators.h | 2 -- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index ebe08b0..ee40e7a 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -464,7 +464,7 @@ void cmQtAutoGenerators::Init() std::list::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 +477,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); @@ -1365,21 +1365,3 @@ std::string cmQtAutoGenerators::Join(const std::vector& lst, 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..d5a23ab 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -70,8 +70,6 @@ private: void Init(); std::string Join(const std::vector& lst, char separator); - bool EndsWith(const std::string& str, const std::string& with); - bool StartsWith(const std::string& str, const std::string& with); static void MergeUicOptions(std::vector &opts, const std::vector &fileOpts, bool isQt5); -- cgit v0.12 From 95064a6d35c93557c9bb87bc8eeff8555d7295a2 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 18 Apr 2016 11:39:06 +0200 Subject: Autogen: Rename header extension Join method to JoinExts While at it, simplify the signature and avoid a trailing separator. --- Source/cmQtAutoGenerators.cxx | 14 +++++++++----- Source/cmQtAutoGenerators.h | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index ee40e7a..19f6a38 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -762,7 +762,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 +937,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; @@ -1347,8 +1347,7 @@ bool cmQtAutoGenerators::GenerateQrc() return true; } -std::string cmQtAutoGenerators::Join(const std::vector& lst, - char separator) +std::string cmQtAutoGenerators::JoinExts(const std::vector& lst) { if (lst.empty()) { @@ -1356,11 +1355,16 @@ std::string cmQtAutoGenerators::Join(const std::vector& lst, } std::string result; + std::string separator = ","; for (std::vector::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; diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index d5a23ab..f9dd41c 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -69,7 +69,7 @@ private: void Init(); - std::string Join(const std::vector& lst, char separator); + std::string JoinExts(const std::vector& lst); static void MergeUicOptions(std::vector &opts, const std::vector &fileOpts, bool isQt5); -- cgit v0.12 From 8ced8bb95aee78ece751259f9cce23786fe4a1b2 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 18 Apr 2016 12:02:28 +0200 Subject: Autogen: New logCommand method. It prints commands using std::cout. --- Source/cmQtAutoGenerators.cxx | 45 +++++++++++++++++++++++-------------------- Source/cmQtAutoGenerators.h | 1 + 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 19f6a38..65892fe 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -1159,13 +1159,7 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile, if (this->Verbose) { - for(std::vector::const_iterator cmdIt = command.begin(); - cmdIt != command.end(); - ++cmdIt) - { - std::cout << *cmdIt << " "; - } - std::cout << std::endl; + this->LogCommand(command); } std::string output; @@ -1231,13 +1225,7 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName, if (this->Verbose) { - for(std::vector::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; @@ -1322,13 +1310,7 @@ bool cmQtAutoGenerators::GenerateQrc() if (this->Verbose) { - for(std::vector::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; @@ -1347,6 +1329,27 @@ bool cmQtAutoGenerators::GenerateQrc() return true; } +void cmQtAutoGenerators::LogCommand(const std::vector& command) +{ + std::stringstream sbuf; + for(std::vector::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& lst) { if (lst.empty()) diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index f9dd41c..408ca14 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -69,6 +69,7 @@ private: void Init(); + void LogCommand(const std::vector& command); std::string JoinExts(const std::vector& lst); static void MergeUicOptions(std::vector &opts, -- cgit v0.12 From 3ea1d09082de6b5ed4fbb7f9be04a0172c01c0be Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 18 Apr 2016 12:34:10 +0200 Subject: Autogen: Rename method GenerateQrc{ => Files} --- Source/cmQtAutoGenerators.cxx | 4 ++-- Source/cmQtAutoGenerators.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 65892fe..576de7a 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -612,7 +612,7 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) if(!this->RccExecutable.empty()) { - this->GenerateQrc(); + this->GenerateQrcFiles(); } std::stringstream outStream; @@ -1264,7 +1264,7 @@ bool cmQtAutoGenerators::InputFilesNewerThanQrc(const std::string& qrcFile, return false; } -bool cmQtAutoGenerators::GenerateQrc() +bool cmQtAutoGenerators::GenerateQrcFiles() { for(std::vector::const_iterator si = this->RccSources.begin(); si != this->RccSources.end(); ++si) diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 408ca14..5b33d16 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -42,7 +42,7 @@ private: bool GenerateMoc(const std::string& sourceFile, const std::string& mocFileName); bool GenerateUi(const std::string& realName, const std::string& uiFileName); - bool GenerateQrc(); + bool GenerateQrcFiles(); void ParseCppFile(const std::string& absFilename, const std::vector& headerExtensions, std::map& includedMocs, -- cgit v0.12 From cf679ea8dcd04c1217cd7c664117439fdd370f10 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 18 Apr 2016 13:46:28 +0200 Subject: Autogen: Split out moc file generation code to dedicated method --- Source/cmQtAutoGenerators.cxx | 157 +++++++++++++++++++++++++++--------------- Source/cmQtAutoGenerators.h | 4 ++ 2 files changed, 107 insertions(+), 54 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 576de7a..7f7dbad 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 cdefList; cmSystemTools::ExpandListArgument(this->MocCompileDefinitionsStr, cdefList); @@ -589,14 +591,11 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) std::map notIncludedMocs; this->ParseHeaders(headerFiles, includedMocs, notIncludedMocs, includedUis); - // run moc on all the moc's that are #included in source files - for(std::map::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 >::const_iterator it = includedUis.begin(); it != includedUis.end(); @@ -615,38 +614,11 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) this->GenerateQrcFiles(); } - 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::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"; - } - } - if (this->RunMocFailed) { std::cerr << "moc failed..." << std::endl; return false; } - if (this->RunUicFailed) { std::cerr << "uic failed..." << std::endl; @@ -657,25 +629,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; } @@ -1119,6 +1072,102 @@ void cmQtAutoGenerators::ParseHeaders(const std::set& absHeaders, } } + +bool cmQtAutoGenerators::GenerateMocFiles( + const std::map& includedMocs, + const std::map& notIncludedMocs ) +{ + // generate moc files that are included by source files. + for(std::map::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::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::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) { diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 5b33d16..51959be 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -39,6 +39,9 @@ private: std::string MakeCompileSettingsString(cmMakefile* makefile); bool RunAutogen(cmMakefile* makefile); + bool GenerateMocFiles( + const std::map& includedMocs, + const std::map& notIncludedMocs); bool GenerateMoc(const std::string& sourceFile, const std::string& mocFileName); bool GenerateUi(const std::string& realName, const std::string& uiFileName); @@ -100,6 +103,7 @@ private: std::string CurrentCompileSettingsStr; std::string OldCompileSettingsStr; + std::string OutMocCppFilenameRel; std::string OutMocCppFilename; std::list MocIncludes; std::list MocDefinitions; -- cgit v0.12 From 47e60bc5a09f5b3a71ce015025cd93af4270afb5 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 18 Apr 2016 14:07:12 +0200 Subject: Autogen: Split out UI file generation code to dedicated method --- Source/cmQtAutoGenerators.cxx | 38 ++++++++++++++++++++++++++------------ Source/cmQtAutoGenerators.h | 2 ++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 7f7dbad..91bacce 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -595,20 +595,10 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) { this->GenerateMocFiles ( includedMocs, notIncludedMocs ); } - - for(std::map >::const_iterator - it = includedUis.begin(); - it != includedUis.end(); - ++it) + if(!this->UicExecutable.empty()) { - for (std::vector::const_iterator nit = it->second.begin(); - nit != it->second.end(); - ++nit) - { - this->GenerateUi(it->first, *nit); - } + this->GenerateUiFiles ( includedUis ); } - if(!this->RccExecutable.empty()) { this->GenerateQrcFiles(); @@ -1227,6 +1217,30 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile, return false; } + +bool cmQtAutoGenerators::GenerateUiFiles( + const std::map >& includedUis ) +{ + for(std::map >::const_iterator + it = includedUis.begin(); it != includedUis.end(); ++it) + { + for (std::vector::const_iterator nit = it->second.begin(); + nit != it->second.end(); ++nit) + { + if (!this->GenerateUi(it->first, *nit) ) + { + if (this->RunUicFailed) + { + return false; + } + } + } + } + + return true; +} + + bool cmQtAutoGenerators::GenerateUi(const std::string& realName, const std::string& uiFileName) { diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index 51959be..cb2be4a 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -44,6 +44,8 @@ private: const std::map& notIncludedMocs); bool GenerateMoc(const std::string& sourceFile, const std::string& mocFileName); + bool GenerateUiFiles( + const std::map >& includedUis ); bool GenerateUi(const std::string& realName, const std::string& uiFileName); bool GenerateQrcFiles(); void ParseCppFile(const std::string& absFilename, -- cgit v0.12 From bc4c7751ab4ae28770f5bcf3595e632c40026be2 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 18 Apr 2016 16:51:24 +0200 Subject: Autogen: Ui processing: Generate single map with final input / output names The single map allows name collision testing (in a later commit) --- Source/cmQtAutoGenerators.cxx | 56 ++++++++++++++++++++++++++++++------------- Source/cmQtAutoGenerators.h | 4 +++- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 91bacce..b75868e 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -1221,13 +1221,38 @@ bool cmQtAutoGenerators::GenerateMoc(const std::string& sourceFile, bool cmQtAutoGenerators::GenerateUiFiles( const std::map >& includedUis ) { + // single map with input / output names + std::map > uiGenMap; for(std::map >::const_iterator it = includedUis.begin(); it != includedUis.end(); ++it) { - for (std::vector::const_iterator nit = it->second.begin(); - nit != it->second.end(); ++nit) + // 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::map& sourceMap = uiGenMap[it->first]; + for (std::vector::const_iterator sit = it->second.begin(); + sit != it->second.end(); + ++sit) { - if (!this->GenerateUi(it->first, *nit) ) + 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 >:: + const_iterator it = uiGenMap.begin(); it != uiGenMap.end(); ++it) + { + for(std::map::const_iterator + sit = it->second.begin(); + sit != it->second.end(); + ++sit) + { + if (!this->GenerateUi(it->first, sit->first, sit->second) ) { if (this->RunUicFailed) { @@ -1242,27 +1267,24 @@ bool cmQtAutoGenerators::GenerateUiFiles( 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); @@ -1272,7 +1294,7 @@ bool cmQtAutoGenerators::GenerateUi(const std::string& realName, std::vector opts = this->UicTargetOptions; std::map::const_iterator optionIt - = this->UicOptions.find(ui_input_file); + = this->UicOptions.find(uiInputFile); if (optionIt != this->UicOptions.end()) { std::vector fileOpts; @@ -1283,8 +1305,8 @@ 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) { @@ -1296,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; diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index cb2be4a..d532c21 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -46,7 +46,9 @@ private: const std::string& mocFileName); bool GenerateUiFiles( const std::map >& includedUis ); - bool GenerateUi(const std::string& realName, const std::string& uiFileName); + bool GenerateUi(const std::string& realName, + const std::string& uiInputFile, + const std::string& uiOutputFile ); bool GenerateQrcFiles(); void ParseCppFile(const std::string& absFilename, const std::vector& headerExtensions, -- cgit v0.12 From 840b830bc6a76afe207bc08ca164eaabb731acaf Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Mon, 18 Apr 2016 17:52:00 +0200 Subject: Autogen: Qrc processing: Generate single map with final input / output names --- Source/cmQtAutoGenerators.cxx | 120 ++++++++++++++++++++++++++---------------- Source/cmQtAutoGenerators.h | 2 + 2 files changed, 76 insertions(+), 46 deletions(-) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index b75868e..c07a0a6 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -1351,64 +1351,92 @@ bool cmQtAutoGenerators::InputFilesNewerThanQrc(const std::string& qrcFile, bool cmQtAutoGenerators::GenerateQrcFiles() { + // generate single map with input / output names + std::map qrcGenMap; for(std::vector::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 command; - command.push_back(this->RccExecutable); + } - std::string basename = cmsys::SystemTools:: - GetFilenameWithoutLastExtension(*si); + // generate qrc files + for(std::map::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 command; + command.push_back(this->RccExecutable); - if (this->GenerateAll || generateQrc) + std::map::const_iterator optionIt + = this->RccOptions.find(qrcInputFile); + if (optionIt != this->RccOptions.end()) { - std::map::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) - { - 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 " << 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; diff --git a/Source/cmQtAutoGenerators.h b/Source/cmQtAutoGenerators.h index d532c21..68ab480 100644 --- a/Source/cmQtAutoGenerators.h +++ b/Source/cmQtAutoGenerators.h @@ -50,6 +50,8 @@ private: 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& headerExtensions, std::map& includedMocs, -- cgit v0.12