CMake 编译 Qt 安装第三方 libqgit2 扩展
虽然非常不愿意踏上编译这条不归路, 谁叫我爱折腾跨平台呢.
之前一直在搞 Cordova, 不过现在彻底对 H5 跨平台绝望了, 这里不做过多说明了, 可能以后会单独拿出来说道说道.
该扯得蛋也扯完了, ok, 进入正题, 编译 Qt 扩展, 坑坑坑…
这里我以编译libqgit2
为例说明
下载安装相关依赖
download.qt.io 下载 qt-opensource-mac-x64-clang-5.7.0.dmg 安装包
anselmolsm/libqgit2 下载libqgit2源码
libgit2/libgit2/releases 下载 libgit2 v0.23.0源码
安装 Qt
傻瓜式安装 Pass…
Ps: 不要忘记了安装目录, 要不就要悲剧了, 不过你不可能这么蠢的对不…
编译准备
先列出几个遇到的错误, 编译最坑的莫过于各种依赖了, 而且安装方式还不一样
Building with Qt4 support
1 | -- Building with Qt4 support |
错误原因: 是找不到 Qt 库
解决方法: 需要指定 Qt 库的路径
No libgit2 found
1 | FATAL_ERROR "No libgit2 found! |
错误原因: 找不到 libgit2 库
解决方法: 有两种解决方法
- 安装
libgit2
库, 但是千万别brew install libgit2
这样安装(这个非常坑爹, 差点搞的但都碎了), 原因是这样安装的一定是最新版, 但是libqgit2
这个库不支持最新版本的libgit2
, 够囧吧(主要还是没什么人维护了, 库原地址: https://github.com/KDE/libqgit2 有能力的可以去贡献代码) - 指定
LIBGIT2_SRC_DIR
参数, 也就是指定libgit2
源代码的位置, 直接一并编译安装, 或者你先去手动编译安装一个低版本的libgit2
库同样没问题, 这里我推荐直接包含在libqgit2
中编译
Could NOT find Doxygen
1 | Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) |
这个错误不是很懂什么意思, 不过直接brew install doxygen
完事
http://stackoverflow.com/questions/29846214/could-not-find-doxygen-missing-doxygen-executable-in-mac-os-x
修改 CMakeLists.txt 文件
添加下面两行
1 | set (CMAKE_PREFIX_PATH "/Applications/Qt/5.7/clang_64") # Qt 库的路径 |
编译
上面的准备工作完成后执行下面的命令开始编译
Ps: 先切换到libqgit2
源文件根目录
1 | # Building (out of source build): |
默认安装路径: /usr/local
使用
- 创建项目Libqgit2Test
- 打开Libqgit2Test.pro
- 右键 -> Add Library… -> External library -> continue -> 选择库安装路径 -> continue
生成代码如下:
1
2
3
4
5
6win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../usr/local/lib/release/ -lqgit2
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../usr/local/lib/debug/ -lqgit2
else:unix: LIBS += -L$$PWD/../../../../../usr/local/lib/ -lqgit2
INCLUDEPATH += $$PWD/../../../../../usr/local/include
DEPENDPATH += $$PWD/../../../../../usr/local/includeclone远程仓库
1
2
3
4
5
6
7auto repository = new LibQGit2::Repository();
try {
repository->clone("http://git.famishare.cn/MakeHui/test2.git", "/Users/MakeHui/Desktop/test3");
} catch (const LibQGit2::Exception& e) {
qDebug() << e.message();
}
qDebug() << repository->listReferences();
参考资料
http://doc.qt.io/qt-5/cmake-manual.html
http://blog.claves.me/2015/04/29/cmake/
http://www.cnblogs.com/listensong/p/4316944.html
https://svn.osgeo.org/ossim/trunk/ossim_package_support/cmake/CMakeModules/FindQt5.cmake
http://stackoverflow.com/questions/15639781/how-to-find-qt5-cmake-module-on-windows
http://www.cppblog.com/Error/archive/2013/04/13/199407.aspx
http://blog.csdn.net/u010598445/article/details/46729705
http://stackoverflow.com/questions/29846214/could-not-find-doxygen-missing-doxygen-executable-in-mac-os-x
http://stackoverflow.com/questions/33728905/qt-creator-project-error-xcode-not-set-up-properly-you-may-need-to-confirm-t