Sfoglia il codice sorgente

Ensure that the build interface includes have been added.

This is needed in the case that Automoc is used, as that calls
GetIncludeDirectories, which may cache the resulting include dirs
too early in the generate step.

Also, because the automoc step is so early, we can't cache the
include directories at that point. At that point the build interface
of all dependencies are not populated yet, so we'd be caching the
includes before appending the build interface. Only start caching
when we're definitely generating the buildsystem. At that point, the
includes should be stable.

We still need to invoke AppendBuildInterfaceIncludes
in the GlobalGenerator because the build interface includes affect
mostly the dependencies of targets (such as the automoc targets),
rather than the targets themselves, so the build interface needs
to be appended for all targets before generation is done.
Stephen Kelly 13 anni fa
parent
commit
4de71786e8

+ 3 - 1
Source/cmTarget.cxx

@@ -2767,6 +2767,7 @@ std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
                                               this->GetName(),
                                               "INCLUDE_DIRECTORIES", 0, 0);
 
+  this->AppendBuildInterfaceIncludes();
 
   std::vector<std::string> debugProperties;
   const char *debugProp =
@@ -2808,7 +2809,8 @@ std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
                                                 this,
                                                 &dagChecker),
                                       entryIncludes);
-      if (!(*it)->ge->GetHadContextSensitiveCondition())
+      if (this->Makefile->IsGeneratingBuildSystem()
+          && !(*it)->ge->GetHadContextSensitiveCondition())
         {
         cacheIncludes = true;
         }

+ 8 - 0
Tests/QtAutomoc/Adir/CMakeLists.txt

@@ -0,0 +1,8 @@
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_BUILD_INTERFACE_INCLUDES ON)
+
+add_library(libA SHARED libA.cpp)
+target_link_libraries(libA LINK_PUBLIC Qt4::QtCore)
+generate_export_header(libA)

+ 13 - 0
Tests/QtAutomoc/Adir/libA.cpp

@@ -0,0 +1,13 @@
+
+#include "libA.h"
+
+LibA::LibA(QObject *parent)
+  : QObject(parent)
+{
+
+}
+
+int LibA::foo()
+{
+  return 0;
+}

+ 18 - 0
Tests/QtAutomoc/Adir/libA.h

@@ -0,0 +1,18 @@
+
+#ifndef LIBA_H
+#define LIBA_H
+
+#include "liba_export.h"
+
+#include <QObject>
+
+class LIBA_EXPORT LibA : public QObject
+{
+  Q_OBJECT
+public:
+  explicit LibA(QObject *parent = 0);
+
+  int foo();
+};
+
+#endif

+ 10 - 0
Tests/QtAutomoc/Bdir/CMakeLists.txt

@@ -0,0 +1,10 @@
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_BUILD_INTERFACE_INCLUDES ON)
+
+add_library(libB SHARED libB.cpp)
+generate_export_header(libB)
+
+# set_property(TARGET libB APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
+target_link_libraries(libB LINK_PUBLIC libA)

+ 13 - 0
Tests/QtAutomoc/Bdir/libB.cpp

@@ -0,0 +1,13 @@
+
+#include "libB.h"
+
+LibB::LibB(QObject *parent)
+  : QObject(parent)
+{
+
+}
+
+int LibB::foo()
+{
+  return a.foo();
+}

+ 21 - 0
Tests/QtAutomoc/Bdir/libB.h

@@ -0,0 +1,21 @@
+
+#ifndef LIBB_H
+#define LIBB_H
+
+#include "libb_export.h"
+
+#include <QObject>
+#include "libA.h"
+
+class LIBB_EXPORT LibB : public QObject
+{
+  Q_OBJECT
+public:
+  explicit LibB(QObject *parent = 0);
+
+  int foo();
+private:
+  LibA a;
+};
+
+#endif

+ 15 - 1
Tests/QtAutomoc/CMakeLists.txt

@@ -23,4 +23,18 @@ add_executable(foo main.cpp calwidget.cpp foo.cpp blub.cpp bar.cpp abc.cpp
 
 set_target_properties(foo codeeditorLib privateSlot PROPERTIES AUTOMOC TRUE)
 
-target_link_libraries(foo codeeditorLib ${QT_LIBRARIES} )
+include(GenerateExportHeader)
+# The order is relevant here. B depends on A, and B headers depend on A
+# headers both subdirectories use CMAKE_BUILD_INTERFACE_INCLUDES and we
+# test that CMAKE_AUTOMOC successfully reads the include directories
+# for the build interface from those targets. There has previously been
+# a bug where caching of the include directories happened before
+# extracting the includes to pass to moc.
+add_subdirectory(Bdir)
+add_subdirectory(Adir)
+add_library(libC SHARED libC.cpp)
+set_target_properties(libC PROPERTIES AUTOMOC TRUE)
+generate_export_header(libC)
+target_link_libraries(libC LINK_PUBLIC libB)
+
+target_link_libraries(foo codeeditorLib ${QT_LIBRARIES} libC)

+ 13 - 0
Tests/QtAutomoc/libC.cpp

@@ -0,0 +1,13 @@
+
+#include "libC.h"
+
+LibC::LibC(QObject *parent)
+  : QObject(parent)
+{
+
+}
+
+int LibC::foo()
+{
+  return b.foo();
+}

+ 22 - 0
Tests/QtAutomoc/libC.h

@@ -0,0 +1,22 @@
+
+#ifndef LIBC_H
+#define LIBC_H
+
+#include "libc_export.h"
+
+#include <QObject>
+#include "libB.h"
+
+class LIBC_EXPORT LibC : public QObject
+{
+  Q_OBJECT
+public:
+  explicit LibC(QObject *parent = 0);
+
+
+  int foo();
+private:
+  LibB b;
+};
+
+#endif

+ 4 - 0
Tests/QtAutomoc/main.cpp

@@ -48,6 +48,7 @@
 #include "abc.h"
 #include "xyz.h"
 #include "yaf.h"
+#include "libC.h"
 
 int main(int argv, char **args)
 {
@@ -78,5 +79,8 @@ int main(int argv, char **args)
   Yaf yaf;
   yaf.doYaf();
 
+  LibC lc;
+  lc.foo();
+
   return app.exec();
 }