qmake的使用

常用变量

变量说明
CONFIG通用的项目配置选项
DESTDIR生成的可执行文件或者二进制文件的存放目录
HEADERS项目构建使用的头文件
SOURCES项目构建使用的源文件
QT项目中使用的qt模块
INCLUDEPATH搜索头文件的搜索目录
LIBS库目录以及依赖库
TEMPLATE项目中使用的模板,决定构建的输出是二进制,lib库或者插件
TARGET应用程序的二进制文件名
DEFINES定义预处理宏
FORMS项目中编译需要的ui文件
RESOURCES需要的.qrc文件
LEXSOURCES应用的lex源文件列表
YACCSOURCES应用的yacc源文件列表
DEPENDPATH应用的依赖搜索目录
VPATH搜索目录
DEF_FILEwindows系统上独有的。链接到应用的.def文件

变量读取

$$var

app类型

可以通过CONFIG来指定是windows,console,testcase类型的app

参数说明
windowswindow gui应用
consolewindow控制台应用
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

SUBDIRS - handling dependencies
subdirs

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值