【发布时间】:2014-11-20 10:33:32
【问题描述】:
我正在为一个复杂的 Qt5 程序编写自动构建系统。
它的一些 C++ 源代码包含特殊标记,需要由外部实用程序处理。
所以我决定在 qmake 项目中编写一个自定义的预构建步骤,如下所示:
!build_pass {
win32 {
for( src, SOURCES ) {
system("findstr \"MY_CUSTOM_MARKER\" $$src"):system( MyExternalUtil $$src )
}
}
}
但首先system 命令总是返回成功,即我的所有来源都将被处理!
但是,official Qt documentation say they should not。
所以我的问题是:为什么这样的system 命令总是返回0?
附注我在 Windows 命令提示符下试了一下:findstr 正确设置 %errorlevel% 到 1 时找不到指定的文本。
P.P.S 这是解决方法(只需使用其他版本的system):
!build_pass {
win32 {
for( SRC_PATH, SOURCES ) {
FULL_SRC_PATH = \"$$PWD/$$SRC_PATH\"
FULL_SRC_PATH = $$replace( FULL_SRC_PATH, /, \ )
FIND_RES = $$system( findstr \"MY_CUSTOM_MARKER\" $$FULL_SRC_PATH )
!isEmpty( FIND_RES ) {
message( Processing $$SRC_PATH... )
system( MyExternalUtil $$FULL_SRC_PATH )
}
}
}
}
【问题讨论】:
标签: windows qt build qt5 qmake