CMake MacOS X bundle with BundleUtiliies for Qt application
<p>I am a CMake beginner and have an issue with creation of an Qt application bundle for MacOS X. Let's consider a simple widget "helloworld" app in only one <code>main.cpp</code> file.</p>

<pre><code>// main.cpp
#include &lt;QApplication&gt;
#include &lt;QLabel&gt;

int main(int argc, char** argv)
{
    QApplication app(argc,argv);
    QLabel lbl("Hello");
    lbl.show();
    return app.exec();
}
</code></pre>

<p>The <code>CMakeLists.txt</code> file is also simple.</p>

<pre><code># CMakeLists.txt
cmake_minimum_required( VERSION 3.0 )
project( QtBundle )    
set( CMAKE_INCLUDE_CURRENT_DIR ON )
set( CMAKE_AUTOMOC ON )

set( SOURCES main.cpp )    
find_package( Qt5Widgets REQUIRED )

add_executable( ${PROJECT_NAME} MACOSX_BUNDLE ${SOURCES} )    
qt5_use_modules( ${PROJECT_NAME} Widgets )
</code></pre>

<p>I run <code>cmake .. -DCMAKE_PREFIX_PATH=/path/to/Qt5.5.1/</code> and it generates <code>Makefile</code> in the <code>build</code> directory. </p>

<p>Then I run <code>make</code> and have <code>QtBundle.app</code> directory as I wanted and <code>QtBundle.app/Contents/MacOS/QtBundle</code> executable, OK. </p>

<p>But when I launch it I get:</p>

<pre><code>This application failed to start because it could not find or load the Qt platform plugin "cocoa".

Reinstalling the application may fix this problem.
Abort trap: 6 
</code></pre>

<p>As far as I understand that error is occurred because application bundle doesn't have any Qt stuffs (Framework libs and plugins), so I run <code>macdeployqt</code> and it populates bundles directory with a lot of files in Framework and PlugIns folders and application is <strong>able to run and relocate to another system.</strong> </p>

<p>It partially solves the problem but <strong>I want to populate bundle with CMake and <a href="https://cmake.org/cmake/help/v3.5/module/BundleUtilities.html" rel="noreferrer">BundleUtilities</a> and without macdeployqt tool.</strong> </p>

<p>Unfortunately I didn't find any good and simple example for Qt5 deployment with BundleUtilities. </p>

<p>Could someone help me to <strong>modify my 'helloworld' example in such way that CMake automatically creates ready-to-deploy bundle?</strong> </p>

<p>Thanks in advance. </p>

<h1>Main question: how to use CMake BundleUtilities to get a relocatable application?</h1>