Qt-qmake install相关

网友投稿 940 2022-05-29

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.

1

中文说明:

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

1

官方文档路径:INSTALL files

中文翻译路径:安装文件

DEMO

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

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

1

2

3

4

笔者Demo:

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

Pro工程文件

#------------------------------------------------- # # 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 }

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

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

配置安装路径

假设生成的目标文件为:

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_PATH INSTALL_PATH = $$INSTALL_PATH_DEAULT message(default=$$INSTALL_PATH) }

1

2

3

4

5

6

7

8

9

10

未定义安装路径:

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

1

2

3

4

5

6

7

8

9

10

11

定义安装路径:

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

1

2

3

4

5

6

7

8

如上可见,INSTALL_PATH 的作用。

资源文件

资源文件夹默认在 .pro工程文件同级目录。$$PWD为pro文件的当前目录

res.path=$$INSTALL_PATH/res res.files=$$PWD/res/*

1

2

依赖库

depends.path=$$INSTALL_PATH/lib depends.files=$$OUT_PWD/lib/*

1

2

插件

plugins.path=$$INSTALL_PATH/plugins plugins.files=$$OUT_PWD/plugins/*

1

2

平台

platforms.path=$$INSTALL_PATH/platforms platforms.files=$$OUT_PWD/platforms/*

1

2

translations

Qt-qmake install相关

translations.path=$$INSTALL_PATH/translations translations.files=$$OUT_PWD/translations/*

1

2

可执行程序

runbin.path=$$INSTALL_PATH runbin.files=$$OUT_PWD/App

1

2

文档

documentation.path=$$INSTALL_PATH/doc documentation.files=$$OUT_PWD/doc/*

1

2

安装

INSTALLS += res runbin depends plugins platforms translations

1

其他相关语法

exists

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

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 }

1

2

3

4

5

6

7

释义为 判断 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{ }

1

2

3

4

5

6

7

8

9

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

宏定义相关

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

extra

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

unix:documentation.extra = create_docs; mv master.doc toc.doc

1

释义,在 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

1

2

3

4

上述安装脚本中,需要搭配之前讲过的两篇文档;

linuxdeployqt-linux下Qt打包工具

checkinstall-简易打包工具

可形成一个成熟的Qt编译安装脚本。

进一步猜想

多级子工程安装

qmake INSTALLS的多个安装路径

在Qt多个工程目录,可以搭配使用。

dev包的制作

搭配 Adding Custom Targets ,增加 libxxx-dev的输出,形成一个dev安装包

注意

只允许有一个 INSTALL += 存在,在笔者的测试中,发现只允许INSTALL += 存在,准确的应该说,只有最后一个会生效。

Qt

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:ES学习笔记之-ClusterState的学习
下一篇:Java---XML的解析(1)-DOM解析
相关文章