Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

qmake

I have a file "settings.ini" which needs to reside next to the Qt executable.

I can add a custom build step for this in Qt Creator which calls something like this:

copy %{sourceDir}/settings.ini %{buildDir}/settings.ini

This works great so far, but I'd like to include this in the *.pro file so I can put this up in our SVN too.

How can I do this using qmake/.pro-files only?

like image 477
Strayer Avatar asked Oct 17 '11 14:10

Strayer


2 Answers

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.

like image 199
Paglian Avatar answered Sep 30 '22 10:09

Paglian


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
like image 24
jwernerny Avatar answered Sep 30 '22 11:09

jwernerny