我是一名 CMake 初学者,在为 MacOS X 创建 Qt 应用程序包时遇到问题。让我们考虑一个简单的小部件“helloworld”应用程序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
文件也很简单。
# 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/
它产生Makefile
in the build
目录。
然后我跑make
并有QtBundle.app
我想要的目录和QtBundle.app/Contents/MacOS/QtBundle
可执行,OK。
但是当我启动它时我得到:
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
据我了解,发生错误是因为应用程序包没有任何 Qt 内容(框架库和插件),所以我运行macdeployqt
它使用 Framework 和 PlugIns 文件夹中的大量文件填充包目录,并且应用程序是能够运行并重新定位到另一个系统。
它部分解决了问题,但是我想用 CMake 填充包并捆绑实用程序 https://cmake.org/cmake/help/v3.5/module/BundleUtilities.html并且没有 macdeployqt 工具。
不幸的是,我没有找到任何使用 BundleUtilities 部署 Qt5 的好的简单示例。
有人可以帮我吗修改我的“helloworld”示例,以便 CMake 自动创建准备部署包?
提前致谢。
主要问题:如何使用 CMake BundleUtilities 获取可重定位应用程序?