Search code examples
windowsqtpathqmakevisual-studio-2010

Convert Unix path to windows in QMake Script


Is there anyway to get the windows style path to the directory containing the .pro or convert what is stored in _PRO_FILE_PWD_ to a Windows style path ?


I have an issue with the _PRO_FILE_PWD_ variable in Qmake where it returns a unix style path on windows.

e.g c:/foo/bar instead of c:\foo\bar

This is proving a problem where the path is being used as part of a post link step.

QMAKE_POST_LINK += copy /y $$[QT_INSTALL_BINS]\\QtCore4.dll  $${_PRO_FILE_PWD_}/bin/;

I use the .pro file to create a Visual Studio project and I can see that if I manually change the forward slashes to back slashes in VS that everything is copied fine without any errors.

I get the following error in Visual Studio if I don't correct the path.

PostBuildEvent:
1>  Description: copy /y C:\Qt\4.8.3\bin\QtCore4.dll E:/foo/build/win32//bin//;
1>  The syntax of the command is incorrect.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: The command "copy /y C:\Qt\4.8.3\bin\QtCore4.dll E:/foo/build/win32/bin/;
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: :VCEnd" exited with code 1.

Solution

Very simple solution thanks to Roku by adding escaped double quotes around the path using / characters.

MAKE_POST_LINK += 
    copy /y $$[QT_INSTALL_BINS]\\QtCore4.dll \"$${_PRO_FILE_PWD_}/bin/\";  

Note for addingi multiple copy commands you must seperate them with the ampersand the semicolon doesn't work.

e.g.

 MAKE_POST_LINK += 
        copy /y $$[QT_INSTALL_BINS]\\QtCore4.dll \"$${_PRO_FILE_PWD_}/bin/\" &
    MAKE_POST_LINK += 
        copy /y $$[QT_INSTALL_BINS]\\QtGui4.dll \"$${_PRO_FILE_PWD_}/bin/\";  

Solution

  • I got this working by adding escaped double quotes around the path using / characters:

    QMAKE_POST_LINK += 
        copy /y $$[QT_INSTALL_BINS]\\QtCore4.dll \"$${_PRO_FILE_PWD_}/bin/\";