前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Qt-qmake install相关

Qt-qmake install相关

作者头像
何其不顾四月天
发布2023-03-10 13:09:49
1.4K0
发布2023-03-10 13:09:49
举报
文章被收录于专栏:四月天的专栏四月天的专栏

Qt-qmake install相关

简介

在之前的博文中,已经说过相关 autotools,qmake转cmake,cmake-cpack,checkinstall,linuxdeployqt ,本博文将qt 安装配置做一个简单的讲解,搭配 linuxdeployqt 来说明,qmake 安装配置。

官方说明;

代码语言:javascript
复制
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.

中文说明:

代码语言:javascript
复制
在Unix上也经常使用构建工具来安装应用程序和库;例如,通过调用make install。由于这个原因,qmake有一个安装集的概念,这个对象包含关于安装项目的一部分的说明。

官方文档路径:INSTALL files

中文翻译路径:安装文件

DEMO

在官方文档中的相关样例如下

代码语言:javascript
复制
documentation.path = /usr/local/program/doc #安装路径
documentation.files = docs/* #安装文件
unix:documentation.extra = create_docs; mv master.doc toc.doc #额外命令
INSTALLS += documentation # 安装命令

笔者Demo:

默认已经将安装所需要的所有文件放置到Makefile同级目录

Pro工程文件

代码语言:javascript
复制
#-------------------------------------------------
#
# Project created by QtCreator 2021-01-04T09:37:29
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = 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.0

message($$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 += widget

SOURCES += \
        main.cpp \

HEADERS += \

    
FORMS += \


#LIBRARY options
QMAKE_CC += -g
QMAKE_CXX += -g
QMAKE_LINK += -g

message($$OUT_PWD)

INCLUDEPATH += $$QT_SYSROOT/usr/local/include/

LIBS += 

#只说明下属文档部分
DEFINES += INSTALL_PATH_DEAULT
INSTALL_PATH_DEAULT = /usr/local/App

contains(DEFINES, INSTALL_PATH){
    message(Prefix=$$INSTALL_PATH)
}else{
    DEFINES += INSTALL_PATH
    INSTALL_PATH = $$INSTALL_PATH_DEAULT
    message(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/App

exists ($$INSTALL_PATH/doc){
    documentation.path=$$INSTALL_PATH/doc
    documentation.files=$$OUT_PWD/doc/*
    INSTALLS += res runbin documentation depends plugins platforms translations
}else{
    INSTALLS += res runbin depends plugins platforms translations
}

默认工程配置相关项就不做讲解了,只讲解相关安装配置项。

配置安装路径

假设生成的目标文件为:

TARGET = App

代码语言:javascript
复制
DEFINES += INSTALL_PATH_DEAULT #定义默认安装路径
INSTALL_PATH_DEAULT = /usr/local/App #设置默认安装路径值 默认安装路径为: /usr/local/App
#如果定义了安装路径,则使用定义的安装路径,如果未定义安装路径,则采用默认安装路径
contains(DEFINES, INSTALL_PATH){
    message(Prefix=$$INSTALL_PATH)
}else{
    DEFINES += INSTALL_PATH
    INSTALL_PATH = $$INSTALL_PATH_DEAULT
    message(default=$$INSTALL_PATH)
}

未定义安装路径:

代码语言:javascript
复制
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

定义安装路径:

代码语言:javascript
复制
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工程文件同级目录。$$PWDpro文件的当前目录

代码语言:javascript
复制
res.path=$$INSTALL_PATH/res
res.files=$$PWD/res/*

依赖库

代码语言:javascript
复制
depends.path=$$INSTALL_PATH/lib
depends.files=$$OUT_PWD/lib/*

插件

代码语言:javascript
复制
plugins.path=$$INSTALL_PATH/plugins
plugins.files=$$OUT_PWD/plugins/*

平台

代码语言:javascript
复制
platforms.path=$$INSTALL_PATH/platforms
platforms.files=$$OUT_PWD/platforms/* 

translations

代码语言:javascript
复制
translations.path=$$INSTALL_PATH/translations
translations.files=$$OUT_PWD/translations/*

可执行程序

代码语言:javascript
复制
runbin.path=$$INSTALL_PATH
runbin.files=$$OUT_PWD/App

文档

代码语言:javascript
复制
documentation.path=$$INSTALL_PATH/doc
documentation.files=$$OUT_PWD/doc/*

安装

代码语言:javascript
复制
INSTALLS += res runbin depends plugins platforms translations

其他相关语法

exists

在 Demo 中,有一句这样的语法

代码语言:javascript
复制
exists ($$INSTALL_PATH/doc){ 
    documentation.path=$$INSTALL_PATH/doc
    documentation.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

平台兼容

代码语言:javascript
复制
win32{

}
unix{

}
macx{

}

上述搭配使用,可以针对不同的平台,进行不同的安装配置。

宏定义相关

可以和笔者的Demo 一样,在qmake 的 时候进行宏定义,赋值等相关,来进行配置。

extra

在上述简介中有这样的一句:

代码语言:javascript
复制
unix:documentation.extra = create_docs; mv master.doc toc.doc

释义,在 unix平台中,文档安装: 创建文档;执行 文件的命名。

如上,我们在安装对应的操作时,也可以执行对应的语法。create_touch; touch

或者 脚本执行的相关命令。根据上述猜测,可以执行 bash 语法。笔者没有测试是否执行复杂的语法或者脚本。

Demo编译

代码语言:javascript
复制
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 += 存在,准确的应该说,只有最后一个会生效。

本文参与?腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-07-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体同步曝光计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Qt-qmake install相关
    • 简介
      • DEMO
        • Pro工程文件
        • 配置安装路径
        • 资源文件
        • 依赖库
        • 插件
        • 平台
        • translations
        • 可执行程序
        • 文档
        • 安装
      • 其他相关语法
        • exists
        • 平台兼容
        • 宏定义相关
        • extra
      • Demo编译
        • 进一步猜想
          • 多级子工程安装
          • dev包的制作
        • 注意
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
        http://www.vxiaotou.com