8

In a Qt 4 project, I build a Windows installer using Inno Setup. The required libraries (qsqlite.dll, qjpeg4.dll, etc.) are included in the script with CMake variables such as QT_QSQLITE_PLUGIN_RELEASE or QT_QJPEG_PLUGIN_RELEASE.

ex: setup.iss.in :

[Files]
Source: "myapp.exe"; DestDir: {app}
Source: "${QT_QSQLITE_PLUGIN_RELEASE}"; DestDir: {app}/sqldrivers
Source: "${QT_QJPEG_PLUGIN_RELEASE}"; DestDir: {app}/imageformats

Now the project should migrate to Qt5. Everything works fine, but I can't find pre-defined variables to get Qt5 equivalent for these plugins paths. Of course, I could hardcode them, but I am looking for a way to define it in a clean and independent way.

Antwane
  • 20,760
  • 7
  • 51
  • 84
  • Not sure of an answer, but you could examine all variables using the technique described in [this answer](http://stackoverflow.com/a/9328525/424459) – Fraser Jan 06 '13 at 22:33
  • Yeah, I used exactly this macro to find variables mentionned below with Qt4. But using the same, I can't find the Qt5 equivalent. All cmake stuff has been rewrited for the new version of the framework, and some informations are stored as target properties. But I didn't find any way to debug properties on Qt5 targets. – Antwane Jan 07 '13 at 19:46

3 Answers3

14

Qt5 no longer relies on a CMake module file to find the Qt5 installation, but provides its own CMake config file, which sets up the Qt5 libraries as imported CMake targets. To obtain the actual path to the Qt module library file, query the LOCATION property of the module's CMake target or its config specific variant LOCATION_<Config> version, e.g.:

find_package(Qt5Core)
get_target_property(QtCore_location_Release Qt5::Core LOCATION_Release)

find_package(Qt5Widgets)
get_target_property(QtWidgets_location_Release Qt5::Widgets LOCATION_Release)

This strategy probably also applies to Qt plugins, provided you know the plugin's CMake target name (I haven't verified that).

Also see the Qt5 CMake manual.

sakra
  • 62,199
  • 16
  • 168
  • 151
  • You'r right, but I didn't find the right target property set in Qt5XXXConfig[Version].cmake files, and I didn't find macro which do the same trick as [this one](http://stackoverflow.com/a/9328525/424459) but for properties. – Antwane Feb 25 '13 at 19:06
  • Broken link to Qt5 CMake Manual – Joakim Jun 15 '15 at 15:37
  • I arrived at this answer during a search for a different problem. Long story short: Appending "_Release" (and in my case, "_Debug") to the LOCATION arg of get_target_property() did exactly what I needed. I needed to control which build of the Qt libs I was copying to a particular location, and this did the trick. – Jacob Robbins Oct 05 '20 at 14:32
4

As of Qt 5.2, plugins are available as IMPORTED targets too:

http://doc.qt.io/qt-5/cmake-manual.html#imported-targets

https://codereview.qt-project.org/#change,63100

Read the LOCATION property from IMPORTED targets, not a configuration-specific LOCATION_ property. CMake will handle the configuration part.

Antwane
  • 20,760
  • 7
  • 51
  • 84
steveire
  • 10,694
  • 1
  • 37
  • 48
0

Building on steveire's answer, this is how you would get the absolute paths to the QSqlite and QJpeg plugins:

find_package(Qt5Gui)
find_package(Qt5Sql)

get_target_property(qsqlite_loc Qt5::QSQLiteDriverPlugin LOCATION_Release)
message("QSqlite DLL: ${qsqlite_loc}")

get_target_property(qjpeg_loc Qt5::QJpegPlugin LOCATION_Release)
message("QJpeg DLL: ${qjpeg_loc}")
axelstudios
  • 336
  • 3
  • 7
  • Your answer is not correct. Read LOCATION not LOCATION_Release. – steveire Mar 11 '14 at 18:48
  • I started with LOCATION but changed it because the original question was only looking for release plugins. You could certainly just let CMake handle the configuration. – axelstudios Mar 12 '14 at 01:54
  • I just started working with Qt and CMake one hour ago and I can't believe how streamlined the whole process is. Not super documented but this is where stackoverflow comes for the rescue. – ruhig brauner Aug 21 '18 at 20:07