[CMake] Mixed linking

Ray Donnelly mingw.android at gmail.com
Fri Feb 6 17:18:08 EST 2015


Hi,

Apologies that this won't tread correctly (and for directly CC'ing the
three participants); I only signed up to the mailing list after I saw
this conversation. I'm an MSYS2 developer (and I occasionally hack on
Qt build system issues). I've spent a lot of time working on our qt5
and qt5-static packages and a little time working on our cmake
packages, so I'm quite familiar with the CMake and Qt5 static issues
you are discussing, in fact it's the most recent thing I've hacked on
for these packages. My patches can be found at:

https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-qt5-static
[patches 33 .. 41 are mostly cmake related]
.. and:
https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-cmake
[qt5-static-plugin-support.patch]

Stephen Kelly wrote:
> Ghyslain Leclerc wrote:
>
> > Here are a few questions for the list (hoping someone more knowledgable
> > than me will read this and help):
> >
> > 1) Am I right when I say CMake, Qt and static linking don’t mix ?
>
> They should mix fine.

.. actually, you did submit a patch to Qt5 for this:
https://codereview.qt-project.org/#/c/33193/
.. but then you reverted it:
https://codereview.qt-project.org/#/c/37307/

I un-reverted it for MSYS2, with the logic given in my commit message.
I'll not paste it here as you can read it there, but please correct me
if I'm wrong regarding INTERFACE_LINK_LIBRARIES:
https://github.com/Alexpux/MINGW-packages/commit/fe1c58d6baf5ca98cf6697a41e8e98349a7e81d8

Norbert Pfeiler wrote:
> Currently you have to define »QT_STATIC«

You shouldn't need to do this. If you use MSYS2's
mingw-w64-{i686,x86_64}-qt5-static then that will be defined for you.

> and explicitly include your required plugins in the code to get it working

More on this below.

Norbert Pfeiler wrote:

> For Windows it’s like this:
>
> #if defined(Q_OS_WIN) && defined(QT_STATIC)
> #include <QtPlugin>
> Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
> #endif

Again, if you use MSYS2's mingw-w64-{i686,x86_64}-cmake then you
should not need to do this either, because of
https://github.com/Alexpux/MINGW-packages/blob/master/mingw-w64-cmake/qt5-static-plugin-support.patch

Stephen Kelly wrote:

> CMake 3.1 learned a new feature specifically so that this would become
> easier in the future:
>
> http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/7970
>
> qmake generates a file like the above for you and compiles it and links it
> into your application for you in the static version.
>
> With
>
> http://www.cmake.org/cmake/help/v3.1/prop_tgt/INTERFACE_SOURCES.html
>
> Qt can do the same, but someone would have to patch Qt to do so. Something
> for the future... :)

.. so I guess that overall, my patches are far from ideal (still they
achieve their goal for us!), in particular I didn't like adding code
to cmQtAutoGenerators.cxx as that seems like something that shouldn't
be hard-coded into a general purpose build system, but I'm pleased to
read that the plan is to generalise this kind of thing going forward
(I think that's the gist - clearly I'm no expert in CMake).

As a side node, I actually tried to use a Digia-provided (I think) Qt
static build for something work-related about a year ago, and because
it requires a specific version of the msvc++ runtime I don't think it
fits any useful definition of 'static'. Qt static built with MinGW-w64
does though as the msvcrt.dll we use is present on all Windows
releases all the way back to Windows XP. Maybe I used the wrong one
though, as the Qt SDK seems to be static enough.

Best regards,

Ray Donnelly.


More information about the CMake mailing list