欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

qmake技巧

程序员文章站 2024-01-04 13:01:46
...

qmake技巧

官方qmake 文档

https://doc.qt.io/qt-5/qmake-manual.html

传入宏

//--无值
DEFINES += PARAM
//--有值
DEFINES += PARAM=\"\\\"我的pro参数\\\"\"

宏参数传入空格或者其他特殊字符

#   "2018-10-05 10:35:00"
DEFINES += _END_TIME_ASCII=\"\\\"\u0032\u0030\u0031\u0038\u002d\u0031\u0030\u002d\u0030\u0035\u0020\u0031\u0030\u003a\u0033\u0035\u003a\u0030\u0030\\\"\"
DEFINES += LIST=\"\\\"12,34,56\\\"\"

没有记录在doc的qmake变量

https://wiki.qt.io/Undocumented_QMake
部分:

#---Undocumented_QMake
message(-----------Undocumented_QMake----------------)
message(_DATE_ $$_DATE_)
message(_FILE_ $$_FILE_)
message(_LINE_ $$_LINE_)
message(QMAKE_DIR_SEP $$QMAKE_DIR_SEP)
message(IN_PWD $$IN_PWD)
message(QMAKE_CHK_DIR_EXISTS $$QMAKE_CHK_DIR_EXISTS)
message(QMAKE_COPY      $$QMAKE_COPY)
message(QMAKE_COPY_DIR  $$QMAKE_COPY_DIR)
message(QMAKE_COPY_FILE $$QMAKE_COPY_FILE)
message(QMAKE_DEL_DIR $$QMAKE_DEL_DIR)
message(QMAKE_DEL_FILE $$QMAKE_DEL_FILE)
message(QMAKE_INSTALL_DIR $$QMAKE_INSTALL_DIR)
message(QMAKE_INSTALL_FILE $$QMAKE_INSTALL_FILE)
message(QMAKE_INSTALL_PROGRAM $$QMAKE_INSTALL_PROGRAM)
message(QMAKE_LINK $$QMAKE_LINK)
message(QMAKE_LINK_SHLIB $$QMAKE_LINK_SHLIB)
message(QMAKE_MKDIR $$QMAKE_MKDIR)
message(QMAKE_MOVE $$QMAKE_MOVE)
message(QMAKE_QMAKE $$QMAKE_QMAKE)
message(QMAKE_STRIP $$QMAKE_STRIP)
message(QMAKE_SYMBOLIC_LINK $$QMAKE_SYMBOLIC_LINK)
message(QMAKE_ARGS $$QMAKE_ARGS)
message(QMAKE_PROJECT_DEPTH $$QMAKE_PROJECT_DEPTH)

复制文件

把头文件复制到目标目录

#copy files
win32{#copy HEADERS to DESTDIR
    src_dir = $$HEADERS
    dst_dir = $$DESTDIR

    #和上面的语句之间需要留一个空行,否则会出错
    src_dir ~= s,/,\,g
    dst_dir ~= s,/,\,g
    system(xcopy $$src_dir $$dst_dir /y /s)
}else{
    system(cp -rv $$HEADERS   $$DESTDIR )
}

自动构建目标平台代码

#--auto build pc/arm
message(--------auto build pc/arm----------------)
if(contains(QMAKE_CC,arm-linux-gnueabi-gcc)){
    message(build arm)
}else{
    message(build pc)
}

主机信息

message(QMAKE_HOST \
cpu:$$QMAKE_HOST.cpu_count\
name:$$QMAKE_HOST.name\
os:$$QMAKE_HOST.os\
version:$$QMAKE_HOST.version\
arch:$$QMAKE_HOST.arch\
version_string:$$QMAKE_HOST.version_string )

文档中的qmake变量

https://doc.qt.io/qt-5/qmake-variable-reference.html
部分:

message(QMAKE_QMAKE $$QMAKE_QMAKE)
message(QMAKESPEC   $$QMAKESPEC)
message(QMAKE_CC    $$QMAKE_CC)
message(QMAKE_CFLAGS $$QMAKE_CFLAGS)
message(QMAKE_CXX   $$QMAKE_CXX)
message(QMAKE_CXXFLAGS $$QMAKE_CXXFLAGS)

message(QMAKE_LIBS_EGL $$QMAKE_LIBS_EGL)
message(QMAKE_LIBS_OPENGL $$QMAKE_LIBS_OPENGL)
message(QMAKE_LIBS_OPENGL_ES1 $$QMAKE_LIBS_OPENGL_ES1)
message(QMAKE_LIBS_OPENGL_ES2 $$QMAKE_LIBS_OPENGL_ES2)

message(QMAKE_LFLAGS $$QMAKE_LFLAGS)

message(QMAKE_RESOURCE_FLAGS $$QMAKE_RESOURCE_FLAGS)
相关标签: QT/QML

上一篇:

下一篇: