diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2016-04-18 11:46:28 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-04-19 16:51:26 (GMT) |
commit | cf679ea8dcd04c1217cd7c664117439fdd370f10 (patch) | |
tree | a052c2b3d19becc4e918f346631a340b09d2b297 /Source | |
parent | 3ea1d09082de6b5ed4fbb7f9be04a0172c01c0be (diff) | |
download | CMake-cf679ea8dcd04c1217cd7c664117439fdd370f10.zip CMake-cf679ea8dcd04c1217cd7c664117439fdd370f10.tar.gz CMake-cf679ea8dcd04c1217cd7c664117439fdd370f10.tar.bz2 |
Autogen: Split out moc file generation code to dedicated method
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmQtAutoGenerators.cxx | 157 | ||||
-rw-r--r-- | 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<std::string> cdefList; cmSystemTools::ExpandListArgument(this->MocCompileDefinitionsStr, cdefList); @@ -589,14 +591,11 @@ 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(); @@ -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<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"; - } - } - 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<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) { 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<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); @@ -100,6 +103,7 @@ private: std::string CurrentCompileSettingsStr; std::string OldCompileSettingsStr; + std::string OutMocCppFilenameRel; std::string OutMocCppFilename; std::list<std::string> MocIncludes; std::list<std::string> MocDefinitions; |