From 6f53b1ab642ca1e5977121ec60779f248cf8ee88 Mon Sep 17 00:00:00 2001 From: Sebastian Holtermann Date: Wed, 30 Nov 2016 22:51:00 +0100 Subject: QtAutogen: Generate moc compilation in _automoc.dir/moc_compilation.cpp --- Help/prop_tgt/AUTOMOC.rst | 2 +- Source/cmQtAutoGeneratorInitializer.cxx | 10 +++------- Source/cmQtAutoGenerators.cxx | 28 ++++++++++++++++------------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Help/prop_tgt/AUTOMOC.rst b/Help/prop_tgt/AUTOMOC.rst index 8143ba9..eea57e3 100644 --- a/Help/prop_tgt/AUTOMOC.rst +++ b/Help/prop_tgt/AUTOMOC.rst @@ -30,7 +30,7 @@ source files at build time and invoke moc accordingly. alternative extensions, such as ``hpp``, ``hxx`` etc when searching for headers. The resulting moc files, which are not included as shown above in any of the source files are included in a generated - ``_automoc.cpp`` file, which is compiled as part of the + ``moc_compilation.cpp`` file, which is compiled as part of the target. This property is initialized by the value of the :variable:`CMAKE_AUTOMOC` diff --git a/Source/cmQtAutoGeneratorInitializer.cxx b/Source/cmQtAutoGeneratorInitializer.cxx index de70d34..a443934 100644 --- a/Source/cmQtAutoGeneratorInitializer.cxx +++ b/Source/cmQtAutoGeneratorInitializer.cxx @@ -650,14 +650,10 @@ static void RccSetupAutoTarget(cmGeneratorTarget const* target) void cmQtAutoGeneratorInitializer::InitializeAutogenSources( cmGeneratorTarget* target) { - cmMakefile* makefile = target->Target->GetMakefile(); - if (target->GetPropertyAsBool("AUTOMOC")) { - std::string automocTargetName = GetAutogenTargetName(target); - std::string mocCppFile = makefile->GetCurrentBinaryDirectory(); - mocCppFile += "/"; - mocCppFile += automocTargetName; - mocCppFile += ".cpp"; + cmMakefile* makefile = target->Target->GetMakefile(); + std::string mocCppFile = GetAutogenTargetBuildDir(target); + mocCppFile += "moc_compilation.cpp"; makefile->GetOrCreateSource(mocCppFile, true); makefile->AppendProperty("ADDITIONAL_MAKE_CLEAN_FILES", mocCppFile.c_str(), false); diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index f90f0d5..e5d7b57 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -392,8 +392,8 @@ void cmQtAutoGenerators::Init() this->TargetBuildSubDir = this->TargetName; this->TargetBuildSubDir += ".dir/"; - this->OutMocCppFilenameRel = this->TargetName; - this->OutMocCppFilenameRel += ".cpp"; + this->OutMocCppFilenameRel = this->TargetBuildSubDir; + this->OutMocCppFilenameRel += "moc_compilation.cpp"; this->OutMocCppFilenameAbs = this->Builddir + this->OutMocCppFilenameRel; @@ -480,10 +480,10 @@ bool cmQtAutoGenerators::RunAutogen(cmMakefile* makefile) // the program goes through all .cpp files to see which moc files are // included. It is not really interesting how the moc file is named, but // what file the moc is created from. Once a moc is included the same moc - // may not be included in the _automoc.cpp file anymore. OTOH if there's a - // header containing Q_OBJECT where no corresponding moc file is included - // anywhere a moc_.cpp file is created and included in - // the _automoc.cpp file. + // may not be included in the moc_compilation.cpp file anymore. OTOH if + // there's a header containing Q_OBJECT where no corresponding moc file + // is included anywhere a moc_.cpp file is created and included in + // the moc_compilation.cpp file. // key = moc source filepath, value = moc output filepath std::map includedMocs; @@ -1041,30 +1041,34 @@ bool cmQtAutoGenerators::GenerateMocFiles( } } - // compose _automoc.cpp content + // Compose moc_compilation.cpp content std::string automocSource; { std::ostringstream outStream; outStream << "/* This file is autogenerated, do not edit*/\n"; if (notIncludedMocs.empty()) { + // Dummy content outStream << "enum some_compilers { need_more_than_nothing };\n"; } else { + // Includes content for (std::map::const_iterator it = notIncludedMocs.begin(); it != notIncludedMocs.end(); ++it) { - outStream << "#include \"" << it->second << "\"\n"; + outStream << "#include \"" + << it->second.substr(this->TargetBuildSubDir.size()) + << "\"\n"; } } outStream.flush(); automocSource = outStream.str(); } - // check if we even need to update _automoc.cpp + // Check if we even need to update moc_compilation.cpp if (!automocCppChanged) { - // compare contents of the _automoc.cpp file + // compare contents of the moc_compilation.cpp file const std::string oldContents = ReadAll(this->OutMocCppFilenameAbs); if (oldContents == automocSource) { - // nothing changed: don't touch the _automoc.cpp file + // nothing changed: don't touch the moc_compilation.cpp file if (this->Verbose) { std::ostringstream err; err << "AUTOGEN: " << this->OutMocCppFilenameRel << " still up to date" @@ -1075,7 +1079,7 @@ bool cmQtAutoGenerators::GenerateMocFiles( } } - // actually write _automoc.cpp + // Actually write moc_compilation.cpp { std::string msg = "Generating MOC compilation "; msg += this->OutMocCppFilenameRel; -- cgit v0.12