Qt 编译前自动执行和编译后自动执行脚本
引用:https://blog.csdn.net/wkr2005/article/details/93711321
qt的pro配置文件中也可添加各种编译前后的操作及配置,主要通过 QMAKE_POST_LINK和QMAKE_PRE_LINK;
QMAKE_POST_LINK表示编译后执行内容
QMAKE_PRE_LINK表示编译前执行内容
举例如下:
#------------------------------------------------- # # Project created by QtCreator 2020-11-13T10:30:08 # #------------------------------------------------- QT -= gui TARGET = ComuPCIe TEMPLATE = lib DEFINES += COMUPCIE_LIBRARY # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 DESTDIR += ../bin SOURCES += \ comupcie.cpp HEADERS += \ comupcie.h unix { target.path = /usr/lib INSTALLS += target } win32 { binDstPath = C:/radsim/bin libDstPath = C:/radsim/lib headerDstPath = "C:\\radsim\\include\\" libSrcName = $$DESTDIR/*.lib binSrcName = $$DESTDIR/*.dll headerSrcName = $$PWD/comupcie.h exists($$headerSrcName){ message($$headerSrcName) message($$headerDstPath) message($$replace(headerSrcName, /, \\)) } QMAKE_POST_LINK += copy /Y $$replace(headerSrcName, /, \\) $$headerDstPath }
就是说, QMAKE_POST_LINK 后面可以追加要执行的命令,这些命令必须可以再命令行运行,当然,这就运行你写脚本了。
补充:
在windows系统下面,由于命令行中大部分命令不支持“/”,所以把“/”替换成“\”。
多条命令语句之间可以用&&隔开,自动连续执行;
定义的宏变量,在非首位置使用时,需要带{}, 如
<span style="display: inline-block; position: relative; width: 3.125em; height: 0px; font-size: 120%;"><span style="position: absolute; clip: rect(1.385em, 1003.07em, 2.698em, -1000em); top: -2.292em; left: 0em;"><span id="MathJax-Span-2" class="mrow"><span id="MathJax-Span-3" class="mi" style="font-family: MathJax_Math; font-style: italic;">P<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.109em;"><span id="MathJax-Span-4" class="mi" style="font-family: MathJax_Math; font-style: italic;">W<span style="display: inline-block; overflow: hidden; height: 1px; width: 0.104em;"><span id="MathJax-Span-5" class="mi" style="font-family: MathJax_Math; font-style: italic;">D<span id="MathJax-Span-6" class="texatom"><span id="MathJax-Span-7" class="mrow"><span id="MathJax-Span-8" class="mo" style="font-family: MathJax_Main;">/
PWD/{DESTDIR}/$${TARGET}.dll中的DESTDIR和TARGET。