Kaynağa Gözat

QtAutogen: Generate moc compilation in _automoc.dir/moc_compilation.cpp

Sebastian Holtermann 9 yıl önce
ebeveyn
işleme
6f53b1ab64

+ 1 - 1
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
-  ``<targetname>_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`

+ 3 - 7
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);

+ 16 - 12
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_<filename>.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_<filename>.cpp file is created and included in
+  // the moc_compilation.cpp file.
 
   // key = moc source filepath, value = moc output filepath
   std::map<std::string, std::string> 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<std::string, std::string>::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;