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 main.cpp
file.
// main.cpp
#include <QApplication>
#include <QLabel>
int main(int argc, char** argv)
{
QApplication app(argc,argv);
QLabel lbl("Hello");
lbl.show();
return app.exec();
}
The CMakeLists.txt
file is also simple.
# 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 )
I run cmake .. -DCMAKE_PREFIX_PATH=/path/to/Qt5.5.1/
and it generates Makefile
in the build
directory.
Then I run make
and have QtBundle.app
directory as I wanted and QtBundle.app/Contents/MacOS/QtBundle
executable, OK.
But when I launch it I get:
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
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 macdeployqt
and it populates bundles directory with a lot of files in Framework and PlugIns folders and application is able to run and relocate to another system.
It partially solves the problem but I want to populate bundle with CMake and BundleUtilities and without macdeployqt tool.
Unfortunately I didn't find any good and simple example for Qt5 deployment with BundleUtilities.
Could someone help me to modify my 'helloworld' example in such way that CMake automatically creates ready-to-deploy bundle?
Thanks in advance.