qmake 笔记
项目中涉及qmake的pro文件,因此读了其文档,作如下记录以备查。
操作符(Operators)
= += -= 类似c的赋值,自加(拼接),自减。多个值用空格分,多行用\
SOURCES = main.cpp mainwindow.cpp \ |
*= 添加唯一值,值不存在时添加
~= 替代值,用正则表达式
$$ 获取变量内容
$${…} 获取变量内容,其会依附到值后,且不会添加空格
$$(…) 获取环境变量内容
$(…) 用于生成makefile运行时,获取环境变量内容
$$[…] 获取qmake属性
作用域(Scopes)
当条件为真时,执行作用域内的声明
<condition> { |
条件支持逻辑反!
作用域能嵌套
:操作,相当于逻辑与。可以拼接条件,赋值
macx:CONFIG(debug, debug|release) { |
| 逻辑或
if 调整操作的优先顺序
if(win32|macos):CONFIG(debug, debug|release) { |
条件支持通配符配置
win32-* { |
else 作用域
win32:xml { |
CONFIG变量特殊对待,其列表每一个值可以作为条件。
CONFIG += opengl |
变量(Variables)
除了内置变量,支持自定义变量
替换函数(Replace Functions)
使用$$将函数返回值赋给变量
HEADERS = model.h |
自定义替换函数
defineReplace(functionName){ |
测试函数(Test Functions)
用于作用域的条件
count(options, 2) { |
常用内置变量
| Variable | Contents |
|---|---|
| CONFIG | General project configuration options. |
| DESTDIR | The directory in which the executable or binary file will be placed. |
| FORMS | A list of UI files to be processed by the user interface compiler (uic). |
| HEADERS | A list of filenames of header (.h) files used when building the project. |
| QT | A list of Qt modules used in the project. |
| RESOURCES | A list of resource (.qrc) files to be included in the final project. See the The Qt Resource System for more information about these files. |
| SOURCES | A list of source code files to be used when building the project. |
| TEMPLATE | The template to use for the project. This determines whether the output of the build process will be an application, a library, or a plugin. |
项目模版(Project Templates)
TEMPLATE 变量的作用,定义项目类型。可能取值:
| Template | qmake Output |
|---|---|
| app (default) | Makefile to build an application. |
| lib | Makefile to build a library. |
| aux | Makefile to build nothing. Use this if no compiler needs to be invoked to create the target, for instance because your project is written in an interpreted language. Note: This template type is only available for Makefile-based generators. In particular, it will not work with the vcxproj and Xcode generators. |
| subdirs | Makefile containing rules for the subdirectories specified using the SUBDIRS variable. Each subdirectory must contain its own project file. |
| vcapp | Visual Studio Project file to build an application. |
| vclib | Visual Studio Project file to build a library. |
| vcsubdirs | Visual Studio Solution file to build projects in sub-directories. |
一般配置(General Configuration)
CONFIG 可以指定release或debug,最后一个将起作用,如果要同时编译使用debug_and_release
SUBDIRS
SUBDIRS 每个值可以限定特定的属性
| Modifier | Effect |
|---|---|
| .subdir | Use the specified subdirectory instead of SUBDIRS value. |
| .file | Specify the subproject pro file explicitly. Cannot be used in conjunction with .subdir modifier. |
| .depends | This subproject depends on specified subproject(s). |
| .makefile | The makefile of subproject. Available only on platforms that use makefiles. |
| .target | Base string used for makefile targets related to this subproject. Available only on platforms that use makefiles. |
SUBDIRS += my_executable my_library |