如何使用qmake递归复制文件

时间:2011-05-11 10:10:40

标签: qmake

在我的源代码树中,我有一堆资源,我想用make install将它们复制到我定义的目标路径。由于资源树有许多子目录,我希望qmake以递归方式查找所有文件。

我试过了:

   resources.path = /target/path
   resources.files += `find /path/to/resources`
   INSTALLS += resources

    resources.path = /target/path
    resources.files += /path/to/resources/*
    resources.files += /path/to/resources/*/*
    resources.files += /path/to/resources/*/*/*
    resources.files += /path/to/resources/*/*/*/*
    INSTALLS += resources

两者都没有我希望的结果。

2 个答案:

答案 0 :(得分:4)

我这样做了:

res.path = $$OUT_PWD/targetfolder
res.files = sourcefolder

INSTALLS += res

这会将"wherever this qmake script is"/sourcefolder复制到buildfolder/"same sub folder on build dir"/targetfolder

所以你会targetfolder/sourcefolder/"all other subfolders and files..."

示例:

#(My .pro file's dir) $$PWD = /mysources/
#(My Build dir)       $$OUT_PWD = /project_build/


extras.path = $$OUT_PWD
extras.files += extras
src.path = $$OUT_PWD
src.files += src

INSTALLS += extras src

/mysources/extras复制到/project_build/extras/mysources/src复制到/project_build/src

答案 1 :(得分:2)

看起来目录是使用'cp -r -f'安装的,所以这就是诀窍:

resources.path = /target/path
resources.files += /path/to/resources/dir1
resources.files += /path/to/resources/dir2
resources.files += /path/to/resources/dir3 
resources.files += /path/to/resources/dirn # and so on...
resources.files += /path/to/resources/*    # don't forget the files in the root
INSTALLS += resources