Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

qmake - Copy a file to build directory after compiling project with Qt

I have seen several suggestions, but nothing really worked for me as I want. I just need to copy a file to the desired destination directory.

Say, for example from this answer:

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

INSTALLS += install_it

Variables %{buildDir} and %{sourceDir} should be defined, to make this work. Ok, there's no problem with %{sourceDir}: it is just .. But how can I get %{buildDir}?

EDIT1

Say, I have a project my_project here:

/path/to/my_project

So, release build path is this: /path/to/my_project-build-Desktop-release,

debug build path is this: /path/to/my_project-build-Desktop-debug

I have files to be copied to destination directory here: /path/to/my_project/copy_to_install_dir

So, I want all files from /path/to/my_project/copy_to_install_dir to be copied to /path/to/my_project-build-Desktop-release when I do release build. And, the same way for debug build.

I can't find variable which contain full destination path, i.e. /path/to/my_project-build-Desktop-release for debug build.

Just in case: I use Windows, but anyway I'm looking for crossplatform solution.

EDIT2

Exact solution, for future readers:

install_it.path = $$OUT_PWD
install_it.files = copy_to_install_dir/*

INSTALLS += 
    install_it
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The selected answer is correct but it requires to call make install, which in my opinion is annoying or error prone. Instead, to copy files to the build directory use:

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

Where required_files must be replaced with your correct path. $$PWD is the path of current .pro file, you might not require this.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...