Deploying Qt applications with DeployQt4
CMake 2.8.7 has been released and includes the DeployQt4 module I created.
DeployQt4 will take an executable and any specified Qt plugins and install and setup all the linked dependencies.
DeployQt4 does this by using e.g.
depends.exe to find the linked libraries, installing a
qt.conf file (if needed) to ensure the correct Qt is used and install any specified Qt plugins to the default Qt application plugin path. On OSX it will also use
install_name_tool to make sure your application is linked directly to the libraries inside its bundle.
For example an OSX application bundle before DeployQt4 might look like:
and afterwards like:
The most commonly used DeployQt4 function is
INSTALL_QT4_EXECUTABLE function. For example:
If you wanted to do this in a CMake script rather than at install time (i.e. for an already compiled executable) you could instead call:
Other DeployQt4 options include manually specifying libraries or non-Qt plugins to install their linked dependencies, additional directories to check for linked dependencies (the Qt directories are added by default), override the default plugin installation directory, override whether a
qt.conf file is installed and the use of CMake
You can see an example of using DeployQt4 (combined with CPack to generate installers) in the CMakeLists.txt file for my Fabula project.
For more information read the DeployQt4 section of the official CMake documentation, read the DeployQt4 source code or post a question in the comments.
If you want the same functionality for non-Qt projects I suggest you investigate the BundleUtilities module in CMake. Despite the confusing name this installs linked dependencies on Windows, Mac and Linux. DeployQt4 extends this functionality to improve the API and add some Qt-specific deployment help.
If you want the same functionality for Mac-only non-CMake projects I suggest you investigate the Mac deployment tool (macdeployqt) that is bundled with Qt. It lacks the DeployQt4 added features of automatic installation of any linked dependencies, CMake/CPack integration and support for Windows and Linux but will install the Qt libraries correctly.