在 qmake 中,有没有办法告诉额外的目标何时过期?
对于以下配置,我可以调用任何一个已定义的额外目标,例如
make copy_zip
,并且依赖的目标命令按预期顺序运行,但它们每次都会运行。在 qmake 文档中,它没有提到如何指定过时的测试。
TARGET = demo
SOURCES = main.cpp
add_resource.commands = mkdir -p $${OUT_PWD}/$${TARGET}.app/Contents/Resources/ $$escape_expand(\n\t)
add_resource.commands += cp $$PWD/resource.dat $${OUT_PWD}/$${TARGET}.app/Contents/Resources/
add_resource.depends += first
create_zip.commands = zip -r $${OUT_PWD}/$${TARGET}.zip $${OUT_PWD}/$${TARGET}.app
create_zip.depends += add_resource
copy_zip.commands = cp $${OUT_PWD}/$${TARGET}.zip $${OUT_PWD}/$${TARGET}.zip.dat
copy_zip.depends = create_zip
QMAKE_EXTRA_TARGETS += add_resource create_zip copy_zip
如果这对于额外的目标来说是不可能的,那么还有其他方法吗?
我就是这样做的(在 MacOS 上)。
QMake .pro 文件:
# main.cpp
# #include <iostream>
# int main(int argc, char* argv[])
# {
# (void)argv;
# std::cout << "argnum " << argc << std::endl;
# return 0;
# }
TARGET = demo
SOURCES = main.cpp
# Build this target if the main executable has been changed
ADD_RESOURCE_FILES = $${OUT_PWD}/$${TARGET}.app/Contents/MacOS/$${TARGET}
# The .input field must be a qmake variable
add_resource.input = ADD_RESOURCE_FILES
# This is a flag file to trigger the out-of-date mechanism
add_resource.output = $$OUT_PWD/.add_resource
# Add commands here to execute the desired task. Must have "$$escape_expand(\n\t)"
# at the end of each line.
add_resource.commands = mkdir -p $${OUT_PWD}/$${TARGET}.app/Contents/Resources/ $$escape_expand(\n\t)
add_resource.commands += cp $$PWD/resource.dat $${OUT_PWD}/$${TARGET}.app/Contents/Resources/ $$escape_expand(\n\t)
# Update the flag file
add_resource.commands += touch $$OUT_PWD/.add_resource
# Do not add this target to the linker
add_resource.CONFIG += no_link
# Add to qmake's compiler list
QMAKE_EXTRA_COMPILERS += add_resource
# Create flag file target and its dependencies
.add_resource.output = $$OUT_PWD/.add_resource
.add_resource.depends = ADD_RESOURCE_FILES
# Build this target if the flag file for the previous step has been changed
CREATE_ZIP_FILES = $${OUT_PWD}/.add_resource
create_zip.input = CREATE_ZIP_FILES
create_zip.output = $${OUT_PWD}/.create_zip
create_zip.commands = zip -r $${OUT_PWD}/$${TARGET}.zip $${OUT_PWD}/$${TARGET}.app $$escape_expand(\n\t)
create_zip.commands += touch $$OUT_PWD/.create_zip
create_zip.CONFIG += no_link
QMAKE_EXTRA_COMPILERS += create_zip
.create_zip.output = $$OUT_PWD/.create_zip
.create_zip.depends = CREATE_ZIP_FILES
COPY_ZIP_FILES = $$OUT_PWD/.create_zip
copy_zip.input = COPY_ZIP_FILES
copy_zip.output = $$OUT_PWD/.copy_zip
copy_zip.commands = cp $${OUT_PWD}/$${TARGET}.zip $${OUT_PWD}/$${TARGET}.zip.dat $$escape_expand(\n\t)
copy_zip.commands += touch $$OUT_PWD/.copy_zip
copy_zip.CONFIG += no_link
QMAKE_EXTRA_COMPILERS += copy_zip
.copy_zip.output = $$OUT_PWD/.copy_zip
.copy_zip.depends = COPY_ZIP_FILES