Qmake - 不在 linux 中复制文件

Qmake - doesn't copy file in linux

那个代码

defineTest(deployFiles) {
    win32 {
        to = $$shell_path($)
        for(entry,1){
            from = $$shell_path($/$$entry)
            QMAKE_POST_LINK += $$quote(cmd /c copy /y $$from $$to $$escape_expand(\n\t))
            PRE_TARGETDEPS += $$from
        }
        export(QMAKE_POST_LINK)
        export(PRE_TARGETDEPS)
    } else {
        to = $$shell_path($)
        for(entry,1){
            from = $$shell_path($/$$entry)
            QMAKE_POST_LINK += $$quote(cp $$from $$to $$escape_expand(\n\t))
            PRE_TARGETDEPS += $$from
        }
        export(QMAKE_POST_LINK)
        export(PRE_TARGETDEPS)
    }
}

仅适用于 Windows OS。其中 $$from - 文件; $$to - 目录。

不幸的是我试过了:

QMAKE_POST_LINK += $$quote(xterm -e cp $$from $$to $$escape_expand(\n\t))

unix 而不是 else

如果我在 linux 块中的导出之前放置 message($$QMAKE_POST_LINK),在输出中我有这样的消息:

cp /home/user/QtProject/projects/Tools/qmldir /home/user/QtProject/qml/Tools/
cp /home/user/QtProject/projects/Tools/Tools.qml /home/user/QtProject/qml/Tools/

grep "qmldir" -C 5 <my_build_dir>/Makefile 的输出(与 grep "Tools\.qml" -C 5 <my_build_dir>/Makefile 相同)像这样:

.c.o:
    $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"

####### Build rules

$(TARGET): /home/user/QtProject/projects/Tools/qmldir /home/user/QtProject/projects/Tools/Tools.qml $(OBJECTS)  


Makefile: ../../../projects/Tools/Tools.pro /home/user/Qt/5.4/gcc_64/mkspecs/linux-g++/qmake.conf /home/user/Qt/5.4/gcc_64/mkspecs/features/spec_pre.prf \
        /home/user/Qt/5.4/gcc_64/mkspecs/common/shell-unix.conf \
        /home/user/Qt/5.4/gcc_64/mkspecs/common/unix.conf \

不起作用的项目是TEMPLATE类型"aux",在没有编译器和linker参与时使用。因此 link 命令是空的。

好像只有在有link命令的情况下才会写入QMAKE_POST_LINK

来自 app_sandbox.pro 的 Makefile(模板 = app):

####### Build rules

$(TARGET):  $(OBJECTS)  
    @test -d ../../bin/ || mkdir -p ../../bin/
    $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)

Makefile: ../../projects/app_sandbox/app_sandbox.pro ../../../Qt/5.4/gcc_64/mkspecs/linux-g++/qmake.conf ../../../Qt/5.4/gcc_64/mkspecs/features/spec_pre.prf \

来自 Controls.pro 的 Makefile(模板 = aux):

####### Build rules

$(TARGET): /home/simon/nobackup/app_sandbox/projects/Design/Controls/qmldir /home/simon/nobackup/app_sandbox/projects/Design/Controls/TreeView.qml $(OBJECTS)  


Makefile: ../../../projects/Design/Controls/Controls.pro ../../../../Qt/5.4/gcc_64/mkspecs/linux-g++/qmake.conf ../../../../Qt/5.4/gcc_64/mkspecs/features/spec_pre.prf \

如你所见,两者都为目标指定了依赖项(在$(TARGET):之后),但是秒Makefile中没有link命令。