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.
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
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小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。