Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy QWindowsIntegrationPlugin with CMake

Tags:

c++

cmake

qt

I'm using CMake to build a Qt application. My project compiles, and thanks to 'fixup_bundle()', make install copies the required libraries next to my executable. Great!

Only problem is, when I execute it, I get the dreaded 'This application failed to start because it could not find or load the Qt platform plugin "windows".' error.

Indeed, manually copying qwindows.dll into a 'platforms' directory next to the executable fixes the issue. Now, how can I tell CMake to do that automatically?

Not much info from Qt :

Plugins are also available as IMPORTED targets in CMake. The Qt Network, Qt SQL, Qt GUI, and Qt Widgets modules have plugins associated. They provide a list of plugins in the Qt5_PLUGINS variable.

All right, I guess I have to play with Qt5::QWindowsIntegrationPlugin, which should be an imported target. That's where I'm lost.

I know (well, I think I know at least) that fixup_bundle() looks into the executable to find its dependencies. But despite the fact that I link my executable against QWindowsIntegrationPlugin, there is no trace of it. Therefore, no qwindows.dll copied into my output path by fixup_bundle().

Except the manual copy of the file, I couldn't find a nice CMake-friendly answer to this issue.

Thanks for your help.

like image 941
Mankalas Avatar asked Aug 10 '15 13:08

Mankalas


1 Answers

Just ran into the same issue. Here is how I resolved it in my CMake install script:

# QWindowsIntegrationPlugin is part of the Gui component
find_package(Qt5 COMPONENTS Gui REQUIRED)

install(
    FILES "$<TARGET_FILE:Qt5::QWindowsIntegrationPlugin>"
    DESTINATION bin/platforms
)
like image 137
Robert Avatar answered Oct 09 '22 21:10

Robert