0

I'm currently struggling to get a sub folder of my project to copy to the out directory. I had thought i had it all set up correctly but i guess i'm missing a step. When I run the make i get a "No rule to make target 'copyfiles'" message.

I know I could just make a new build step with a OS specific method, but i was hoping to avoid it cause I would like to build and run on a different OS eventually.

Edit: Yes this question has been asked before. However the solutions given in those questions have not worked for me. They throw errors or simply do nothing.

CONFIG(release, debug|release): DESTDIR = $$OUT_PWD/release
CONFIG(debug, debug|release): DESTDIR = $$OUT_PWD/debug

copytarget.path    = $$DESTDIR/etc
copytarget.files  += $$files(etc/*)

## === os specific dir separator ===
win32 {
    copytarget.files ~= s,/,\\,g
    copytarget.path ~= s,/,\\,g
}

message("found files for copytarget: "$$copytarget.files)
message("found files destination: "$$copytarget.path)

## === copy compiler for makefile ===
DirSep = /
win32: DirSep = \\

for(f,copytarget.files) tmp += $$PWD$$DirSep$${f} ## make absolute paths
copycompiler.input        = tmp

isEmpty(DESTDIR):DESTDIR=.
copycompiler.output       = $$DESTDIR$$DirSep${QMAKE_FILE_BASE}${QMAKE_FILE_EXT}
copycompiler.commands     = $(COPY_FILE) ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
copycompiler.CONFIG       = no_link no_clean
## other CONFIG options are: depends explicit_dependencies target_predeps

copycompiler.variable_out = QMAKE_DISTCLEAN
QMAKE_EXTRA_COMPILERS += copycompiler

## == makefile copy target ===
copyfiles.recurse_target = compiler_copycompiler_make_all
copyfiles.depends        = $$copyfiles.recurse_target
copyfiles.CONFIG        += recursive

MAKE_EXTRA_TARGETS += copyfiles
POST_TARGETDEPS     += copyfiles ## copy files after source compilation

INSTALLS += copytarget
Pyromanci
  • 527
  • 9
  • 21
  • 1
    I use [this answer](https://stackoverflow.com/a/10058744/20712) which defines a copy function when I need to copy a file to the destination. – Ross Rogers Apr 25 '18 at 20:59
  • 1
    Possible duplicate of [QMake - how to copy a file to the output](https://stackoverflow.com/questions/3984104/qmake-how-to-copy-a-file-to-the-output) – eyllanesc Apr 25 '18 at 21:24
  • @ eyllanesc Yes it's the same question, but it's a duplicate because the selected solutions in the other questions do not seem to work for me. they either fail to copy the files or just throw errors. @Ross Rogers Yours gives me a "The system cannot find the path specified." My other_files is called out like: OTHER_FILES += etc/Server.ini So the command that end s up running is copy /y etc\Server.ini E:\H2\build-H2-Desktop_Qt_5_10_0_MinGW_32bit-Debug\Server\debug – Pyromanci Apr 26 '18 at 12:38
  • @Pyromanci, I wasn't able to use that answer stock either. I had to change the `QMAKE_POST_LINK` line to `QMAKE_POST_LINK += $$QMAKE_COPY $$quote($$FILE) $$quote($$DDIR)$$escape_expand(\\n\\t\\n\\t)` I don't remember the errors, but I had to fiddle with it too. That edited version works on Linux and Windows for me. You can see the comment below the original answer as well. – Ross Rogers Apr 26 '18 at 15:23

0 Answers0