diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index 576de7a31..7f7dbadb6 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 5b33d1631..51959be5f 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;