qmake *.prf文件 自定义features
qt文档详细介绍位置:Qt 5.12->qmake Manual->Advanced Usage
qmake 允许用户使用自定义的features,通过在添加变量的方式添加到qmake的CONFIG变量中。
features 是用户自定义的qmake language语法形式的 函数(function) 和 定义(definitions),以prf后缀的文件形式存放,可以放到各种自定义的路径下。
下面是QtInstallDir\Qt5.12.0\5.12.0\msvc2015_64\mkspecs\features中的cmake_functions.prf文件,其中定义了一些qmake语言写的replace函数。
#
# W A R N I N G
# -------------
#
# This file is not part of the Qt API. It exists purely as an
# implementation detail. It may change from version to version
# without notice, or even be removed.
#
# We mean it.
#
defineReplace(cmakeModuleName) {
_module = $$1
_name = $$eval(QT.$${_module}.name)
cmake_module_name = $$replace(_name, ^Qt, )
return ($$cmake_module_name)
}
defineReplace(cmakeModuleList) {
variable = $$1
out =
for(v, variable) {
out += $$cmakeModuleName($$v)
}
return ($$join(out, ";"))
}
defineReplace(cmakeTargetPath) {
SYSR = $$[QT_SYSROOT]
!isEmpty(SYSR): path = /$$relative_path($$1, $$[QT_SYSROOT])
else: path = $$1
return($$clean_path($$path))
}
defineReplace(cmakeTargetPaths) {
variable = $$1
out =
for(v, variable) {
out += \"$$cmakeTargetPath($$v)\"
}
return ($$join(out, " "))
}
defineReplace(cmakePortablePaths) {
variable = $$1
out =
for(v, variable) {
out += $$[QT_SYSROOT]$$cmakeTargetPath($$v)
}
return ($$join(out, ";"))
}
defineReplace(cmakeProcessLibs) {
variable = $$1
out =
for(v, variable) {
if(!equals(v, -framework):!contains(v, -L.*)) {
v ~= s,^-l,,
v ~= s,^-lib,,
v ~= s,.lib$,,
out += $$v
}
}
return ($$join(out, ";"))
}
defineReplace(cmakeRelativePath) {
path = $$relative_path($$1, $$2)
return($$replace(path, ([^/])$, \\1/))
}
Qt 5.12->qmake Manual->Advanced Usage内容节选:
qmake lets you create your own features that can be included in project files by adding their names to the list of values specified by the CONFIG variable. Features are collections of custom functions and definitions in .prf files that can reside in one of many standard directories. The locations of these directories are defined in a number of places, and qmake checks each of them in the following order when it looks for .prf files:
- In a directory listed in the QMAKEFEATURES environment variable that contains a list of directories delimited by the platform's path list separator (colon for Unix, semicolon for Windows).
- In a directory listed in the QMAKEFEATURES property variable that contains a list of directories delimited by the platform's path list separator.
- In a features directory residing within a mkspecs directory. mkspecs directories can be located beneath any of the directories listed in the QMAKEPATH environment variable that contains a list of directories delimited by the platform's path list separator. For example: $QMAKEPATH/mkspecs/<features>.
- In a features directory residing beneath the directory provided by the QMAKESPEC environment variable. For example: $QMAKESPEC/<features>.
- In a features directory residing in the data_install/mkspecs directory. For example: data_install/mkspecs/<features>.
- In a features directory that exists as a sibling of the directory specified by the QMAKESPEC environment variable. For example: $QMAKESPEC/../<features>.
The following features directories are searched for features files:
- features/unix, features/win32, or features/macx, depending on the platform in use
- features/
For example, consider the following assignment in a project file:
CONFIG += myfeaturesWith this addition to the CONFIG variable, qmake will search the locations listed above for the myfeatures.prf file after it has finished parsing your project file. On Unix systems, it will look for the following file:
- $QMAKEFEATURES/myfeatures.prf (for each directory listed in the QMAKEFEATURES environment variable)
- $$QMAKEFEATURES/myfeatures.prf (for each directory listed in the QMAKEFEATURES property variable)
- myfeatures.prf (in the project's root directory)
- $QMAKEPATH/mkspecs/features/unix/myfeatures.prf and $QMAKEPATH/mkspecs/features/myfeatures.prf (for each directory listed in the QMAKEPATH environment variable)
- $QMAKESPEC/features/unix/myfeatures.prf and $QMAKESPEC/features/myfeatures.prf
- data_install/mkspecs/features/unix/myfeatures.prf and data_install/mkspecs/features/myfeatures.prf
- $QMAKESPEC/../features/unix/myfeatures.prf and $QMAKESPEC/../features/myfeatures.prf
自定义的.prf文件放置的路径有严格的要求,可以通过设置环境变量QMAKEFEATURES、QMAKEPATH、QMAKESPEC,指定特定的目录(可以有多个目录),或者设置QMAKEFEATURES属性(qt环境变量、属性、变量 区分和设置)。将.prf放到上面的环境变量或属性指定的目录下的features/文件夹或者fetures/$$platform文件夹中。然后在CONFIG+=myfeature。