2014-06-29 6 views
6

Ich entwickle eine App, die auf Windows, Linux und OS X mit QtCreator und Qt 5.3 aufbauen sollte. Ich möchte alle Dateien und Unterordner von einem Ordner in den Ausgabeordner kopieren. Ich habe es funktioniert für Linux und OS X, aber nicht für Windows. Hier ist der relevante Abschnitt meiner .pro Datei:qmake Befehl zum Kopieren von Dateien und Ordnern in das Ausgabeverzeichnis

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 

Der Fehler, den ich auf Windows bekomme, ist "Ungültige Anzahl von Parametern".

Antwort

10

Wenn Sie die $${PWD} Variable mit message($${PWD}) betrachten, sehen Sie / als Verzeichnisseparator, sogar in Windows. Sie haben es in einheitlichem Verzeichnis seperator zu konvertieren:

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 
+1

Wenn Sie dies jedes Mal tun wollen, müssen Sie auch/Y hinzuzufügen Befehle zu xcopy. Sonst wird es hängen. (/ Y - Unterdrückt die Aufforderung zu bestätigen, dass Sie eine vorhandene Zieldatei überschreiben möchten). – miro

2

Gebäude weg von @Murat's answer, Qt tatsächlich has built-in functions zu konvertieren den Dateipfad in dem lokalen System Präferenz.

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

Nennen Sie es mögen: $$shell_path($$clean_path(<your path>)) oder $$clean_path() wird die Teiler zurück zu Linux-Stil Teiler konvertieren. Diese

funktioniert bei mir unter 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 
Verwandte Themen