4

I want to copy some qml to my build directory.
In .pro, I add:

copydata.commands = $(COPY_DIR) \"$$PWD/plugins\" \"$$DESTDIR/plugins\"

But when I build the project, the copydata is error. The error message is :

xcopy /s /q /y /i "E:/myproject/src/plugins" "E:/myproject/bin/debug/plugins" Invalid number of parameters

But ,I copy the command to cmd ,it's all right.

Does anyone knows what the wrong is ?

behtgod
  • 251
  • 3
  • 15
  • 2
    Windows might get confused by those forward slashes. Try backslashes in all cases. – macetw Sep 17 '15 at 16:15
  • Also, the way you cited your example error, you don't seem to need quote marks. Try it without those quote marks. – macetw Sep 17 '15 at 16:15
  • Yes,you're right. I replaced forward slashes to backslashes manually, it works, But , in the $$PWD, always forward slashes, how can I change them? And , the quote is necessary – behtgod Sep 17 '15 at 16:32
  • I got it. I should use qmake replace functions. Thank you. – behtgod Sep 17 '15 at 16:39
  • Good find, those replace functions. I'll enter this in as an actual answer. Would love for you to mark it answered. – macetw Sep 17 '15 at 16:40
  • I like using the $$clean_path() method so that I maintain cross platform capability. – jwernerny Sep 17 '15 at 16:44

3 Answers3

6

I got it!
Thank you, macetw, you point the way.

The correct code should be:

copydata.commands = $(COPY_DIR) $$shell_path($$PWD/plugins) $$shell_path($$DESTDIR/plugins)
behtgod
  • 251
  • 3
  • 15
4

Windows might get confused by those forward slashes. Try backslashes in all cases.

macetw
  • 1,640
  • 1
  • 17
  • 26
1

Solution that works on Linux and Windows with Qt 4.8 and higher:

win32 {
    COPY_FROM_PATH=$$shell_path($$PWD/plugins)
    COPY_TO_PATH=$$shell_path($$DESTDIR/plugins)
}
else {
    COPY_FROM_PATH=$$PWD/plugins
    COPY_TO_PATH=$$DESTDIR/plugins
}

copydata.commands = $(COPY_DIR) $$COPY_FROM_PATH $$COPY_TO_PATH
first.depends = $(first) copydata

export(first.depends)
export(copydata.commands)

QMAKE_EXTRA_TARGETS += first copydata

Useful links:

Community
  • 1
  • 1
iamantony
  • 1,345
  • 17
  • 32