常用变量
变量 | 说明 |
---|---|
CONFIG | 通用的项目配置选项 |
DESTDIR | 生成的可执行文件或者二进制文件的存放目录 |
HEADERS | 项目构建使用的头文件 |
SOURCES | 项目构建使用的源文件 |
QT | 项目中使用的qt模块 |
INCLUDEPATH | 搜索头文件的搜索目录 |
LIBS | 库目录以及依赖库 |
TEMPLATE | 项目中使用的模板,决定构建的输出是二进制,lib库或者插件 |
TARGET | 应用程序的二进制文件名 |
DEFINES | 定义预处理宏 |
FORMS | 项目中编译需要的ui文件 |
RESOURCES | 需要的.qrc文件 |
LEXSOURCES | 应用的lex源文件列表 |
YACCSOURCES | 应用的yacc源文件列表 |
DEPENDPATH | 应用的依赖搜索目录 |
VPATH | 搜索目录 |
DEF_FILE | windows系统上独有的。链接到应用的.def文件 |
变量读取
$$var
app类型
可以通过CONFIG来指定是windows,console,testcase类型的app
参数 | 说明 |
---|---|
windows | window gui应用 |
console | window控制台应用 |
testcase | 自动测试,测试时,可以使用TESTRUNNER和TESTARGS变量 |
lib库类型
可以通过CONFIG来指定是dll,staticlib,plugin类型
参数 | 说明 |
---|---|
dll | 动态库 |
staticlib | 静态库 |
plugin | 插件 |
VERSION:用于指定版本号
双模式
CONFIG += debug_and_release
CONFIG(debug, debug|release) {
TARGET = debug_binary
} else {
TARGET = release_binary
}
subdirs
修改SUBDIRS的默认行为
修改项 | 说明 |
---|---|
.subdir | 指定目录来代替SUBDIRS中的子工程目录值 |
.file | 指定子工程的pro文件,不能与subdir同时使用 |
.depend | 指定子工程依赖的其他子工程 |
.makefile | 指定子工程的Makefile, 仅在使用Makefile的平台上使用 |
.target | 指定子工程相关的Makefile目标的名称 ,仅在使用Makefile的平台上使用 |
目录结构为
subdir.pro内容为
TEMPLATE = subdirs
SUBDIRS += \
app \
lib
app.depends = lib
lib.pro内容为
QT -= gui
TEMPLATE = lib
DEFINES += LIB_LIBRARY
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked 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
# You can also make your code fail to compile if it uses 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
SOURCES += \
lib.cpp
HEADERS += \
lib_global.h \
lib.h
# Default rules for deployment.
unix {
target.path = /usr/lib
}
!isEmpty(target.path): INSTALLS += target
app.pro内容为
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked 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
INCLUDEPATH += ../lib/
LIBS += -L../lib/Debug -llib
# You can also make your code fail to compile if it uses 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
SOURCES += \
main.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target