当前位置: 首页 > news >正文

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:

  1. 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).
  2. In a directory listed in the QMAKEFEATURES property variable that contains a list of directories delimited by the platform's path list separator.
  3. 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>.
  4. In a features directory residing beneath the directory provided by the QMAKESPEC environment variable. For example: $QMAKESPEC/<features>.
  5. In a features directory residing in the data_install/mkspecs directory. For example: data_install/mkspecs/<features>.
  6. 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:

  1. features/unix, features/win32, or features/macx, depending on the platform in use
  2. features/

For example, consider the following assignment in a project file:

  CONFIG += myfeatures

With 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:

  1. $QMAKEFEATURES/myfeatures.prf (for each directory listed in the QMAKEFEATURES environment variable)
  2. $$QMAKEFEATURES/myfeatures.prf (for each directory listed in the QMAKEFEATURES property variable)
  3. myfeatures.prf (in the project's root directory)
  4. $QMAKEPATH/mkspecs/features/unix/myfeatures.prf and $QMAKEPATH/mkspecs/features/myfeatures.prf (for each directory listed in the QMAKEPATH environment variable)
  5. $QMAKESPEC/features/unix/myfeatures.prf and $QMAKESPEC/features/myfeatures.prf
  6. data_install/mkspecs/features/unix/myfeatures.prf and data_install/mkspecs/features/myfeatures.prf
  7. $QMAKESPEC/../features/unix/myfeatures.prf and $QMAKESPEC/../features/myfeatures.prf

Note: The .prf files must have names in lower case.

 自定义的.prf文件放置的路径有严格的要求,可以通过设置环境变量QMAKEFEATURES、QMAKEPATH、QMAKESPEC,指定特定的目录(可以有多个目录),或者设置QMAKEFEATURES属性(qt环境变量、属性、变量 区分和设置)。将.prf放到上面的环境变量或属性指定的目录下的features/文件夹或者fetures/$$platform文件夹中。然后在CONFIG+=myfeature。

相关文章:

  • 深度学习目标检测入门论文合集讲解
  • c++11 日期和时间工具(std::chrono::duration)(二)
  • DataStructure_树的基本性质(m叉树和二叉树)
  • Flask 学习-76.Flask-RESTX 处理异常@api.errorhandler
  • Java Boolean类中booleanValue()方法具有什么功能呢?
  • c# 与stm32之间结构体的收发
  • java集合专题Map接口及HashMap/Hashtable/Properties使用方法底层结构及源码分析
  • Vue(六)——vuex
  • JavaScript 学习-47.export 和 import 的使用
  • Kafka 生产者
  • Spring核心IOC的核心类解析
  • 【数据挖掘】恒生金融有限公司2023届秋招数据ETL工程师笔试题解析
  • 软件测试分类
  • (附源码)spring boot儿童教育管理系统 毕业设计 281442
  • var、let、const的区别
  • python3.6+scrapy+mysql 爬虫实战
  • ➹使用webpack配置多页面应用(MPA)
  • 8年软件测试工程师感悟——写给还在迷茫中的朋友
  • android 一些 utils
  • ES6 学习笔记(一)let,const和解构赋值
  • JavaScript/HTML5图表开发工具JavaScript Charts v3.19.6发布【附下载】
  • JAVA多线程机制解析-volatilesynchronized
  • PV统计优化设计
  • python大佬养成计划----difflib模块
  • React 快速上手 - 07 前端路由 react-router
  • redis学习笔记(三):列表、集合、有序集合
  • Spring Boot快速入门(一):Hello Spring Boot
  • Swoft 源码剖析 - 代码自动更新机制
  • Terraform入门 - 1. 安装Terraform
  • ⭐ Unity 开发bug —— 打包后shader失效或者bug (我这里用Shader做两张图片的合并发现了问题)
  • vue 个人积累(使用工具,组件)
  • 讲清楚之javascript作用域
  • 开发了一款写作软件(OSX,Windows),附带Electron开发指南
  • 如何借助 NoSQL 提高 JPA 应用性能
  • 一个普通的 5 年iOS开发者的自我总结,以及5年开发经历和感想!
  • ​力扣解法汇总1802. 有界数组中指定下标处的最大值
  • #HarmonyOS:Web组件的使用
  • #pragma once
  • #pragma 指令
  • $.ajax,axios,fetch三种ajax请求的区别
  • $redis-setphp_redis Set命令,php操作Redis Set函数介绍
  • (1)虚拟机的安装与使用,linux系统安装
  • (3)STL算法之搜索
  • (pytorch进阶之路)扩散概率模型
  • (第61天)多租户架构(CDB/PDB)
  • (一)基于IDEA的JAVA基础10
  • (转载)Linux网络编程入门
  • .“空心村”成因分析及解决对策122344
  • .chm格式文件如何阅读
  • .L0CK3D来袭:如何保护您的数据免受致命攻击
  • .NET Core/Framework 创建委托以大幅度提高反射调用的性能
  • .NET Framework 4.6.2改进了WPF和安全性
  • .net反编译工具
  • @基于大模型的旅游路线推荐方案
  • []Telit UC864E 拨号上网