Browse Source

Autogen: Add AUTOMOC_DEPEND_FILTERS support

Sebastian Holtermann 8 years ago
parent
commit
70ebf35cda

+ 1 - 0
Modules/AutogenInfo.cmake.in

@@ -20,6 +20,7 @@ set(AM_MOC_COMPILE_DEFINITIONS @_moc_compile_defs@)
 set(AM_MOC_INCLUDES @_moc_incs@)
 set(AM_MOC_OPTIONS @_moc_options@)
 set(AM_MOC_RELAXED_MODE @_moc_relaxed_mode@)
+set(AM_MOC_DEPEND_FILTERS @_moc_depend_filters@)
 # UIC settings
 set(AM_UIC_SKIP @_uic_skip@)
 set(AM_UIC_TARGET_OPTIONS @_uic_target_options@)

+ 2 - 0
Source/cmQtAutoGeneratorInitializer.cxx

@@ -218,6 +218,8 @@ static void MocSetupAutoTarget(
   AddDefinitionEscaped(makefile, "_moc_relaxed_mode",
                        makefile->IsOn("CMAKE_AUTOMOC_RELAXED_MODE") ? "TRUE"
                                                                     : "FALSE");
+  AddDefinitionEscaped(makefile, "_moc_depend_filters",
+                       GetSafeProperty(target, "AUTOMOC_DEPEND_FILTERS"));
 
   // Moc includes and compile definitions
   {

+ 50 - 10
Source/cmQtAutoGenerators.cxx

@@ -260,6 +260,32 @@ bool cmQtAutoGenerators::Run(const std::string& targetDirectory,
   return success;
 }
 
+bool cmQtAutoGenerators::MocDependFilterPush(const std::string& key,
+                                             const std::string& regExp)
+{
+  bool success = false;
+  if (!key.empty()) {
+    if (!regExp.empty()) {
+      MocDependFilter filter;
+      filter.key = key;
+      if (filter.regExp.compile(regExp)) {
+        this->MocDependFilters.push_back(filter);
+        success = true;
+      } else {
+        this->LogError("AutoMoc: Error in AUTOMOC_DEPEND_FILTERS: Compiling "
+                       "regular expression failed.\nKey: \"" +
+                       key + "\"\nReg. exp.: \"" + regExp + "\"");
+      }
+    } else {
+      this->LogError("AutoMoc: Error in AUTOMOC_DEPEND_FILTERS: Regular "
+                     "expression is empty");
+    }
+  } else {
+    this->LogError("AutoMoc: Error in AUTOMOC_DEPEND_FILTERS: Key is empty");
+  }
+  return success;
+}
+
 bool cmQtAutoGenerators::ReadAutogenInfoFile(
   cmMakefile* makefile, const std::string& targetDirectory,
   const std::string& config)
@@ -320,6 +346,30 @@ bool cmQtAutoGenerators::ReadAutogenInfoFile(
     this->MocIncludePaths);
   cmSystemTools::ExpandListArgument(
     makefile->GetSafeDefinition("AM_MOC_OPTIONS"), this->MocOptions);
+  {
+    std::vector<std::string> mocDependFilters;
+    cmSystemTools::ExpandListArgument(
+      makefile->GetSafeDefinition("AM_MOC_DEPEND_FILTERS"), mocDependFilters);
+    // Insert Q_PLUGIN_METADATA dependency filter
+    if (this->QtMajorVersion != "4") {
+      this->MocDependFilterPush("Q_PLUGIN_METADATA",
+                                "[\n][ \t]*Q_PLUGIN_METADATA[ \t]*\\("
+                                "[^\\)]*FILE[ \t]*\"([^\"]+)\"");
+    }
+    // Insert user defined dependency filters
+    if ((mocDependFilters.size() % 2) == 0) {
+      for (std::vector<std::string>::const_iterator dit =
+             mocDependFilters.begin();
+           dit != mocDependFilters.end(); dit += 2) {
+        if (!this->MocDependFilterPush(*dit, *(dit + 1))) {
+          return false;
+        }
+      }
+    } else {
+      this->LogError("AutoMoc: Error: AUTOMOC_DEPEND_FILTERS list size is not "
+                     "a multiple of 2");
+    }
+  }
 
   // - Uic
   cmSystemTools::ExpandListArgument(makefile->GetSafeDefinition("AM_UIC_SKIP"),
@@ -559,16 +609,6 @@ void cmQtAutoGenerators::Init(cmMakefile* makefile)
       this->MocIncludes.push_back(*it);
     }
   }
-
-  // Insert MocDependFilter for Q_PLUGIN_METADATA
-  if (QtMajorVersion != "4") {
-    MocDependFilter filter;
-    filter.key = "Q_PLUGIN_METADATA";
-    filter.regExp.compile("[\n][ \t]*"
-                          "Q_PLUGIN_METADATA[ \t]*\\("
-                          "[^\\)]*FILE[ \t]*\"([^\"]+)\"");
-    this->MocDependFilters.push_back(filter);
-  }
 }
 
 bool cmQtAutoGenerators::RunAutogen()

+ 1 - 0
Source/cmQtAutoGenerators.h

@@ -33,6 +33,7 @@ private:
   typedef std::pair<std::string, cmsys::RegularExpression> MacroFilter;
 
   // - Configuration
+  bool MocDependFilterPush(const std::string& key, const std::string& regExp);
   bool ReadAutogenInfoFile(cmMakefile* makefile,
                            const std::string& targetDirectory,
                            const std::string& config);

+ 1 - 0
Source/cmTarget.cxx

@@ -245,6 +245,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
     this->SetPropertyDefault("AUTOMOC", CM_NULLPTR);
     this->SetPropertyDefault("AUTOUIC", CM_NULLPTR);
     this->SetPropertyDefault("AUTORCC", CM_NULLPTR);
+    this->SetPropertyDefault("AUTOMOC_DEPEND_FILTERS", CM_NULLPTR);
     this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", CM_NULLPTR);
     this->SetPropertyDefault("AUTOUIC_OPTIONS", CM_NULLPTR);
     this->SetPropertyDefault("AUTORCC_OPTIONS", CM_NULLPTR);