本文主要是介绍Qt-qmake install相关,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Qt-qmake install相关
简介
在之前的博文中,已经说过相关 autotools,qmake转cmake,cmake-cpack,checkinstall,linuxdeployqt ,本博文将qt 安装配置做一个简单的讲解,搭配 linuxdeployqt 来说明,qmake 安装配置。
官方说明;
It is common on Unix to also use the build tool to install applications and libraries; for example, by invoking make install. For this reason, qmake has the concept of an install set, an object which contains instructions about the way a part of a project is to be installed.
中文说明:
在Unix上也经常使用构建工具来安装应用程序和库;例如,通过调用make install。由于这个原因,qmake有一个安装集的概念,这个对象包含关于安装项目的一部分的说明。
官方文档路径:INSTALL files
中文翻译路径:安装文件
DEMO
在官方文档中的相关样例如下
documentation.path = /usr/local/program/doc #安装路径
documentation.files = docs/* #安装文件
unix:documentation.extra = create_docs; mv master.doc toc.doc #额外命令
INSTALLS += documentation # 安装命令
笔者Demo:
默认已经将安装所需要的所有文件放置到Makefile同级目录
Pro工程文件
#-------------------------------------------------
#
# Project created by QtCreator 2021-01-04T09:37:29
#
#-------------------------------------------------QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = App
TEMPLATE = app# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += LINUX_OS_VERSION==$$QT_ARCH
DEFINES += QT_MESSAGELOGCONTEXT# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0message($$QT_ARCH)
message($$QT_VERSION)contains(QT_ARCH, x86_64){message("LINUX_OS_X86_64")DEFINES += LINUX_OS_X86_64
}else{message("LINUX_OS_ARM64")DEFINES += LINUX_OS_ARM64
}exists ($$PWD/../.git) {GIT_BRANCH = $$system(git rev-parse --abbrev-ref HEAD)GIT_TIME = $$system(git show --oneline --format=\"%ci%H\" -s HEAD)APP_VERSION = "VersionInfo: $${GIT_BRANCH} : $${GIT_TIME}"
} else {APP_VERSION = None
}
DEFINES += APP_VERSION=\"\\\"$$APP_VERSION\\\"\"
message($$APP_VERSION)INCLUDEPATH += widgetSOURCES += \main.cpp \HEADERS += \FORMS += \#LIBRARY options
QMAKE_CC += -g
QMAKE_CXX += -g
QMAKE_LINK += -gmessage($$OUT_PWD)INCLUDEPATH += $$QT_SYSROOT/usr/local/include/LIBS += #只说明下属文档部分
DEFINES += INSTALL_PATH_DEAULT
INSTALL_PATH_DEAULT = /usr/local/Appcontains(DEFINES, INSTALL_PATH){message(Prefix=$$INSTALL_PATH)
}else{DEFINES += INSTALL_PATHINSTALL_PATH = $$INSTALL_PATH_DEAULTmessage(default=$$INSTALL_PATH)
}res.path=$$INSTALL_PATH/res
res.files=$$PWD/res/*depends.path=$$INSTALL_PATH/lib
depends.files=$$OUT_PWD/lib/*plugins.path=$$INSTALL_PATH/plugins
plugins.files=$$OUT_PWD/plugins/*platforms.path=$$INSTALL_PATH/platforms
platforms.files=$$OUT_PWD/platforms/*translations.path=$$INSTALL_PATH/translations
translations.files=$$OUT_PWD/translations/*runbin.path=$$INSTALL_PATH
runbin.files=$$OUT_PWD/Appexists ($$INSTALL_PATH/doc){documentation.path=$$INSTALL_PATH/docdocumentation.files=$$OUT_PWD/doc/*INSTALLS += res runbin documentation depends plugins platforms translations
}else{INSTALLS += res runbin depends plugins platforms translations
}
默认工程配置相关项就不做讲解了,只讲解相关安装配置项。
配置安装路径
假设生成的目标文件为:
TARGET = App
DEFINES += INSTALL_PATH_DEAULT #定义默认安装路径
INSTALL_PATH_DEAULT = /usr/local/App #设置默认安装路径值 默认安装路径为: /usr/local/App
#如果定义了安装路径,则使用定义的安装路径,如果未定义安装路径,则采用默认安装路径
contains(DEFINES, INSTALL_PATH){message(Prefix=$$INSTALL_PATH)
}else{DEFINES += INSTALL_PATHINSTALL_PATH = $$INSTALL_PATH_DEAULTmessage(default=$$INSTALL_PATH)
}
未定义安装路径:
mkdir build
cd build
qmake ../App.pro
#输出如下
Info: creating stash file /code/App/App/build/.qmake.stash
Project MESSAGE: x86_64
Project MESSAGE: 5.9.5
Project MESSAGE: LINUX_OS_X86_64
Project MESSAGE: VersionInfo: cmake-pro : 2021-07-20 16:15:47 +080048baa388f1802ac2ba23618883ceeb6dd2e68e16
Project MESSAGE: /code/rdpclient/App/build
Project MESSAGE: default=/usr/local/App
定义安装路径:
qmake "DEFINES += INSTALL_PATH" "INSTALL_PATH = /opt/install" ../App.pro
#输出如下
Project MESSAGE: x86_64
Project MESSAGE: 5.9.5
Project MESSAGE: LINUX_OS_X86_64
Project MESSAGE: VersionInfo: cmake-pro : 2021-07-20 16:15:47 +080048baa388f1802ac2ba23618883ceeb6dd2e68e16
Project MESSAGE: /code/App/App/build
Project MESSAGE: Prefix=/opt/install
如上可见,INSTALL_PATH 的作用。
资源文件
资源文件夹默认在 .pro工程文件同级目录。$$PWD为pro文件的当前目录
res.path=$$INSTALL_PATH/res
res.files=$$PWD/res/*
依赖库
depends.path=$$INSTALL_PATH/lib
depends.files=$$OUT_PWD/lib/*
插件
plugins.path=$$INSTALL_PATH/plugins
plugins.files=$$OUT_PWD/plugins/*
平台
platforms.path=$$INSTALL_PATH/platforms
platforms.files=$$OUT_PWD/platforms/*
translations
translations.path=$$INSTALL_PATH/translations
translations.files=$$OUT_PWD/translations/*
可执行程序
runbin.path=$$INSTALL_PATH
runbin.files=$$OUT_PWD/App
文档
documentation.path=$$INSTALL_PATH/doc
documentation.files=$$OUT_PWD/doc/*
安装
INSTALLS += res runbin depends plugins platforms translations
其他相关语法
exists
在 Demo 中,有一句这样的语法
exists ($$INSTALL_PATH/doc){ documentation.path=$$INSTALL_PATH/docdocumentation.files=$$OUT_PWD/doc/*INSTALLS += res runbin documentation depends plugins platforms translations
}else{INSTALLS += res runbin depends plugins platforms translations
}
释义为 判断 doc 文件夹是否存在,存在 执行
documentation.path=$$INSTALL_PATH/doc documentation.files=$$OUT_PWD/doc/* INSTALLS += res runbin documentation depends plugins platforms translations
不存在执行:INSTALLS += res runbin depends plugins platforms translations
平台兼容
win32{}
unix{}
macx{}
上述搭配使用,可以针对不同的平台,进行不同的安装配置。
宏定义相关
可以和笔者的Demo 一样,在qmake 的 时候进行宏定义,赋值等相关,来进行配置。
extra
在上述简介中有这样的一句:
unix:documentation.extra = create_docs; mv master.doc toc.doc
释义,在 unix平台中,文档安装: 创建文档;执行 文件的命名。
如上,我们在安装对应的操作时,也可以执行对应的语法。create_touch; touch
或者 脚本执行的相关命令。根据上述猜测,可以执行 bash 语法。笔者没有测试是否执行复杂的语法或者脚本。
Demo编译
linuxdeployqt ./App -verbose=2 -appimage
mv plugins/platforms ./
checkinstall --pkgname=Appt --pkgversion=1.1.0 --pkgrelease=1 --pkglicense=GPL --pkggroup=root --maintainer=Troila --pakdir=../../deb_output -y
make uninstall
上述安装脚本中,需要搭配之前讲过的两篇文档;
linuxdeployqt-linux下Qt打包工具
checkinstall-简易打包工具
可形成一个成熟的Qt编译安装脚本。
进一步猜想
多级子工程安装
qmake INSTALLS的多个安装路径
在Qt多个工程目录,可以搭配使用。
dev包的制作
搭配 Adding Custom Targets ,增加 libxxx-dev的输出,形成一个dev安装包
注意
只允许有一个 INSTALL += 存在,在笔者的测试中,发现只允许INSTALL += 存在,准确的应该说,只有最后一个会生效。
这篇关于Qt-qmake install相关的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!