Browse Source

cmQtAutogen: Allow specifying depends for autogen targets.

Test this by generating files with a custom target, which moc
requires to be present when it is run.
Stephen Kelly 12 năm trước cách đây
mục cha
commit
1320e0768e

+ 1 - 0
Help/manual/cmake-properties.7.rst

@@ -80,6 +80,7 @@ Properties on Targets
    /prop_tgt/ARCHIVE_OUTPUT_DIRECTORY
    /prop_tgt/ARCHIVE_OUTPUT_NAME_CONFIG
    /prop_tgt/ARCHIVE_OUTPUT_NAME
+   /prop_tgt/AUTOGEN_TARGET_DEPENDS
    /prop_tgt/AUTOMOC_MOC_OPTIONS
    /prop_tgt/AUTOMOC
    /prop_tgt/AUTOUIC

+ 14 - 0
Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst

@@ -0,0 +1,14 @@
+AUTOGEN_TARGET_DEPENDS
+----------------------
+
+Target dependencies of the corresponding ``_automoc`` target.
+
+Targets which have their :prop_tgt:`AUTOMOC` target set to true have a
+corresponding ``_automoc`` target which is used to autogenerate generate moc
+files.  As this ``_automoc`` target is created at generate-time, it is not
+possible to define dependencies of it, such as to create inputs for the moc
+executable.
+
+The ``AUTOGEN_TARGET_DEPENDS`` target can be set instead to a list of dependencies
+for the ``_automoc`` target. The buildsystem will be generated to depend on its
+contents.

+ 5 - 0
Source/cmQtAutoGenerators.cxx

@@ -204,6 +204,11 @@ bool cmQtAutoGenerators::InitializeAutogenTarget(cmTarget* target)
                                     "", makefile->GetCurrentOutputDirectory());
 
   std::vector<std::string> depends;
+  if (const char *autogenDepends =
+                                target->GetProperty("AUTOGEN_TARGET_DEPENDS"))
+    {
+    cmSystemTools::ExpandListArgument(autogenDepends, depends);
+    }
   std::vector<std::string> toolNames;
   if (target->GetPropertyAsBool("AUTOMOC"))
     {

+ 8 - 1
Tests/QtAutogen/CMakeLists.txt

@@ -43,10 +43,17 @@ add_library(codeeditorLib STATIC codeeditor.cpp)
 
 add_library(privateSlot OBJECT private_slot.cpp)
 
+add_custom_target(generate_moc_input
+  COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/myinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}"
+  COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_CURRENT_BINARY_DIR}/myinterface.h.in" "${CMAKE_CURRENT_BINARY_DIR}/myinterface.h"
+)
+# set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/myinterface.h" PROPERTIES GENERATED TRUE)
+
 add_executable(QtAutogen main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp
                xyz.cpp yaf.cpp gadget.cpp $<TARGET_OBJECTS:privateSlot>
-               test.qrc resourcetester.cpp
+               test.qrc resourcetester.cpp generated.cpp
 )
+set_property(TARGET QtAutogen APPEND PROPERTY AUTOGEN_TARGET_DEPENDS generate_moc_input)
 
 set_target_properties(QtAutogen codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE)
 

+ 10 - 0
Tests/QtAutogen/generated.cpp

@@ -0,0 +1,10 @@
+
+#include "generated.h"
+
+Generated::Generated(QObject *parent)
+  : QObject(parent)
+{
+
+}
+
+#include "moc_generated.cpp"

+ 17 - 0
Tests/QtAutogen/generated.h

@@ -0,0 +1,17 @@
+
+#ifndef GENERATED_H
+#define GENERATED_H
+
+#include <QObject>
+
+#include "myinterface.h"
+
+class Generated : public QObject, MyInterface
+{
+  Q_OBJECT
+  Q_INTERFACES(MyInterface)
+public:
+  explicit Generated(QObject *parent = 0);
+};
+
+#endif

+ 14 - 0
Tests/QtAutogen/myinterface.h.in

@@ -0,0 +1,14 @@
+
+#ifndef MYINTERFACE_H
+#define MYINTERFACE_H
+
+#include <QObject>
+
+class MyInterface
+{
+
+};
+
+Q_DECLARE_INTERFACE(MyInterface, "org.cmake.example.MyInterface")
+
+#endif