[CMake] Build flags when using Qt plugins (was: Where is QT_USE_IMPORTED_TARGETS not safe to use?)

Stephen Kelly steveire at gmail.com
Wed Jun 22 07:06:41 EDT 2011


Clinton Stimpson wrote:

>> >>#
>> >>http://mail.kde.org/pipermail/kde-windows/2007-December/001692.html
>> >>#
>> >>
>> >> http://lists.trolltech.com/pipermail/qt-interest/2009-July/009829.html
>> >> # qt is always compiled with QT_NO_DEBUG under mingw,
>> >>
>> >># so we need to compile stuff linked against it
>> >># the same or otherwise QPluginLoader rejects plugins
>> >>add_definitions(-DQT_NO_DEBUG)
>> >
>> > That is unrelated to imported targets.
>> > There is currently no mechanism in CMake to have the FindQt4.cmake
>> > module handle QT_DEBUG/QT_NO_DEBUG preprocessor defines automatically.
>> >
>> > One does not have this problem if the QT_USE_FILE is used.  Otherwise
>> > you may do what it does for your project to add the configuration
>> > dependent Qt preprocessor defines.
>>
>> Hmm, I do use the QT_USE_FILE. I recently attempted to remove that
>> add_definitions call and something failed (maybe it was plugin loading at
>> runtime - I don't remember). I'll try again now and see if I can say what
>> the problem is.
> 
> Ok.
> 

I applied this patch:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3746e4f..2630f53 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,7 +39,7 @@ if (CMAKE_COMPILER_IS_GNUCXX)
     # qt is always compiled with QT_NO_DEBUG under mingw,
     # so we need to compile stuff linked against it
     # the same or otherwise QPluginLoader rejects plugins
-    add_definitions(-DQT_NO_DEBUG)
+    #add_definitions(-DQT_NO_DEBUG)
   endif ()
 endif()

diff --git a/cmake/modules/GrantleeUse.cmake 
b/cmake/modules/GrantleeUse.cmake
index 472b45a..a3cff0b 100644
--- a/cmake/modules/GrantleeUse.cmake
+++ b/cmake/modules/GrantleeUse.cmake
@@ -60,5 +60,5 @@ if (MINGW)
   # qt is always compiled with QT_NO_DEBUG under mingw,
   # so we need to compile stuff linked against it
   # the same or otherwise QPluginLoader rejects plugins
-  add_definitions(-DQT_NO_DEBUG)
+  #add_definitions(-DQT_NO_DEBUG)
 endif ()
diff --git a/templates/lib/pluginpointer_p.h 
b/templates/lib/pluginpointer_p.h
index 11974dd..cfcd4d5 100644
--- a/templates/lib/pluginpointer_p.h
+++ b/templates/lib/pluginpointer_p.h
@@ -23,6 +23,7 @@

 #include <QtCore/QPluginLoader>
 #include <QtCore/QSharedPointer>
+#include <QtCore/QDebug>


On windows my cmake version is 2.8.4 and my Qt version is 4.6.2
 namespace Grantlee
 {
@@ -62,6 +63,7 @@ public:
     m_pluginLoader = QSharedPointer<QPluginLoader>( new
QPluginLoader( fileName ), _deleter );

     m_object = m_pluginLoader->instance();
+    qDebug() << "Object" << m_object << m_pluginLoader->errorString();
     if ( !m_object )
       return;


And all unit tests then fail with MinGW. The errorString() reported is:

QDEBUG : TestBuiltinSyntax::testInsignificantWhitespace(insignificant-
whitespace43) Object QObject(0x0)  "The plugin 
'C:/software/grantlee/qtcreator-build/grantlee/0.1/grantlee_defaulttags.dll' 
uses incompatible Qt library. (Cannot mix debug and release libraries.)"


Is this unexpected? I'm not familiar enough with windows tools to inspect 
the binaries and see what's going on. Any help appreciated.

Thanks,

Steve.




More information about the CMake mailing list