Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qmake command to copy files and folders into output directory

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

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

like image 401
SurvivalMachine Avatar asked Jun 29 '14 09:06

SurvivalMachine


2 Answers

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
like image 111
Murat Şeker Avatar answered Sep 22 '22 18:09

Murat Şeker


Building off of @Murat's answer, Qt actually has built-in functions to convert the filepath to the local system's preference.

$$shell_path( <your path> ) //Converts to OS path divider preference.
$$clean_path( <your path> ) //Removes duplicate dividers.

Call it like: $$shell_path($$clean_path( <your path> )), or $$clean_path() will convert the dividers back to Linux-style dividers.

This works for me on Windows:

#For our copy command, we neeed to fix the filepaths to use Windows-style path dividers.
SHADER_SOURCE_PATH = $$shell_path($$clean_path("$${SOURCE_ROOT}\\Engine\\Shaders\\"))
SHADER_DESTINATION = $$shell_path($$clean_path("$${PROJECT_BIN}\\Shaders\\"))

#Create a command, using the 'cmd' command line and Window's 'xcopy', to copy our shaders folder
#into the Game/Bin/Shaders/ directory.
CopyShaders.commands = $$quote(cmd /c xcopy /Y /S /I $${SHADER_SOURCE_PATH} $${SHADER_DESTINATION})

#Add the command to Qt.
QMAKE_EXTRA_TARGETS += CopyShaders
POST_TARGETDEPS += CopyShaders
like image 30
Jamin Grey Avatar answered Sep 23 '22 18:09

Jamin Grey