Copy a file to the build directory after compiling project with Qt

You probably want to use the INSTALLS keyword in QMake. It will require you to run make install after your build, but it does work cross-platform.

install_it.path = %{buildDir}
install_it.files += %{sourceDir}/settings.ini

INSTALLS += install_it

To copy %{sourceDir}/settings.ini to the build directory without requiring to call make install use:

copydata.commands = $(COPY_DIR) $$PWD/settings.ini $$OUT_PWD
first.depends = $(first) copydata
export(first.depends)
export(copydata.commands)
QMAKE_EXTRA_TARGETS += first copydata

$$PWD is the path of current .pro file. If your settings.ini file is not located in the same directory than the project file, then use something like $$PWD/more_dirs_here/settings.ini

Note: I found this solution here. I recommend to read the whole article as it explains how it works.

Tags:

Qmake