qmake 命令将文件和文件夹复制到输出目录中 [英] qmake command to copy files and folders into output directory

查看:107
本文介绍了qmake 命令将文件和文件夹复制到输出目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 QtCreator 和 Qt 5.3 开发应该在 Windows、Linux 和 OS X 上构建的应用程序.我想将文件夹中的所有文件和子文件夹复制到输出文件夹中.我让它适用于 Linux 和 OS X,但不适用于 Windows.这是我的 .pro 文件的相关部分:

I'm developing an app that should build on Windows, Linux and OS X using QtCreator and Qt 5.3. I want to copy all files and subfolders from a folder into output folder. I've got it working for Linux and OS X, but not for Windows. Here's the relevant section of my .pro file:

win32 {
    PWD_WIN = $${PWD}
    DESTDIR_WIN = $${OUT_PWD}
    copyfiles.commands = $$quote(cmd /c xcopy /S /I $${PWD_WIN}\copy_to_output $${DESTDIR_WIN})
}
macx {
    copyfiles.commands = cp -r $$PWD/copy_to_output/* $$OUT_PWD
}
linux {
    copyfiles.commands = cp -r $$PWD/copy_to_output/* $$OUT_PWD
}
QMAKE_EXTRA_TARGETS += copyfiles
POST_TARGETDEPS += copyfiles

我在 Windows 上遇到的错误是参数数量无效".

The error I'm getting on Windows is "Invalid number of parameters".

推荐答案

如果你用 message($${PWD})$${PWD} 变量>,您将看到 / 作为目录分隔符,即使在 Windows 中也是如此.您必须将其转换为本机目录分隔符:

If you look at the $${PWD} variable with message($${PWD}), you will see / as directory seperator, even in Windows. You have to convert it to native directory seperator :

PWD_WIN = $${PWD}
DESTDIR_WIN = $${OUT_PWD}
PWD_WIN ~= s,/,\\,g
DESTDIR_WIN ~= s,/,\\,g

copyfiles.commands = $$quote(cmd /c xcopy /S /I $${PWD_WIN}\\copy_to_output $${DESTDIR_WIN})

QMAKE_EXTRA_TARGETS += copyfiles
POST_TARGETDEPS += copyfiles

这篇关于qmake 命令将文件和文件夹复制到输出目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆