How reference Qt Creator current build directory from Qt project file?

Ed of the Mountain picture Ed of the Mountain · Sep 18, 2013 · Viewed 14.3k times · Source

Does Qt Creator set a qmake variable containing the build directory that can be referenced from the Qt project file?

The Qt Creator Default build directory:

../build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}

My goal is to copy the dll's import lib from the build output using QMAKE_POST_LINK to make it easier for my client project to link with. QMAKE_POST_LINK works if I hard code the path of the import lib.

For example:

QMAKE_POST_LINK = copy C:\projects\ICP\sw\icpts\sandbox\configurable-system-test-io\build-lib-configurable-system-test-io-Desktop_Qt_5_1_0_MSVC2012_32bit_eb09a8-Debug\debug\*.lib  ..\my-lib

Solution: Solution provided by fbucek to use $$OUT_DIR solved my problem. Thank You!

  • Under Windows, you must use $$shell_path($$OUT_PWD) in the QMAKE_POST_LINK to convert Unix '/' path characters to Windows '\' path characters.
  • To add multiple commands to QMAKE_POST_LINK, enclose in $$quote() with appended $$escape_expand(\n).

Example of Multiple QMAKE_POST_LINK commands:

QMAKE_POST_LINK += $$quote(copy /Y $$shell_path($$OUT_PWD)\debug\*.dll  ..\lib$$escape_expand(\\n))
QMAKE_POST_LINK += $$quote(copy /Y $$shell_path($$OUT_PWD)\debug\*.lib  ..\lib$$escape_expand(\\n))
QMAKE_POST_LINK += $$quote(copy /Y $$shell_path($$OUT_PWD)\debug\*.pdb  ..\lib$$escape_expand(\\n))

Thanks again for $$OUT_PWD !

-Ed

  • Qt Creator 2.7.2
  • Qt 5.1
  • Microsoft VS 2012
  • Windows 7

Answer

fbucek picture fbucek · Sep 18, 2013

Yes it does

Put this in pro file, run qmake and check if it shows what you want

message($$OUT_PWD)

Qmake Variable Reference OUT_PWD

Then you can use it like this: ( I hope - not tested )

QMAKE_POST_LINK = copy $$OUT_PWD\debug\*.lib  ..\my-lib