关于 QMAKE_POST_LINK和QMAKE_PRE_LINK使用的说明

qt的pro配置文件中也可添加各种编译前后的操作及配置,主要通过 QMAKE_POST_LINK和QMAKE_PRE_LINK;

QMAKE_POST_LINK表示编译后执行内容

QMAKE_PRE_LINK表示编译前执行内容

他们支持的函数以及写法,可以在QtCreator的帮助中搜索qmake Function 查看详情说明(QT的帮助文档是我见过最详细的使用文档);

比如copy文件如下:

win32:CONFIG(release, debug|release){
    SrcIncludeFile = $$PWD/*.h
    SrcIncludeFile = $$replace(SrcIncludeFile, /, \\);
    OutputIncludeDir = $$PWD/../../../BSCommon/include/
    OutputIncludeDir = $$replace(OutputIncludeDir, /, \\);
    OutputFile = $$PWD/$${DESTDIR}/$${TARGET}.dll
    OutputFile = $$replace(OutputFile, /, \\);
    OutputDir = $$PWD/../../../BSCommon/bin/release/
    OutputDir = $$replace(OutputDir, /, \\);
    QMAKE_POST_LINK += copy /Y $$SrcIncludeFile $$OutputIncludeDir && copy /Y $$OutputFile $$OutputDir
}else:win32:CONFIG(debug, debug|release){
    SrcIncludeFile = $$PWD/*.h
    SrcIncludeFile = $$replace(SrcIncludeFile, /, \\);
    OutputIncludeDir = $$PWD/../../../BSCommon/include/
    OutputIncludeDir = $$replace(OutputIncludeDir, /, \\);
    OutputFile = $$PWD/$${DESTDIR}/$${TARGET}.dll
    OutputFile = $$replace(OutputFile, /, \\);
    OutputDir = $$PWD/../../../BSCommon/bin/debug/
    OutputDir = $$replace(OutputDir, /, \\);
    QMAKE_POST_LINK += copy /Y $$SrcIncludeFile $$OutputIncludeDir && copy /Y $$OutputFile $$OutputDir
}

注意, 注意,注意:

在windows系统下面,由于命令行中大部分命令不支持“/”,所以把“/”替换成“\”。

多条命令语句之间可以用&&隔开,自动连续执行;

定义的宏变量,在非首位置使用时,需要带{}, 如$$PWD/$${DESTDIR}/$${TARGET}.dll中的DESTDIR和TARGET

 

你可能感兴趣的:(Qt)