Reputation:
I have a list of files in my Qmake project. And I want them copied in build directory at build time.
My qmake file is below
OTHER_FILES += \
input1 \
input2 \
input3 \
I'm using Linux. I've read a few stack overflow questions and googled about my problem but cannot find the exact solution.
Upvotes: 1
Views: 509
Reputation: 146
I have a requirement of copying openssl 1.1 dlls (libcrypto-1_1-x64.dll & libssl-1_1-x64.dll) into the build directory in order to have network communication. I am using Qt 5.13.0 on a windows 11 64 Bit machine with gcc 7.3.0 compiler. My project structure is,
Project Root | D:\Qt\MyProject |
---|---|
Project file | D:\Qt\MyProject\MyProject.pro |
Debug Build | D:\Qt\MyProject\debug |
Release Build | D:\Qt\MyProject\release |
Files to copy | D:\Qt\MyProject\library |
I tried multiple solutions from SO but only the following snippet worked for me.
win32 {
CONFIG( debug, debug|release ) {
DEST_DIR = debug # debug
}
else {
DEST_DIR = release # release
}
}
TARGET_DIR = $${OUT_PWD}/$${DEST_DIR}
# List of files to be copied to target directory
FILELIST = "library/libcrypto-1_1-x64.dll" # ssl 1.1.x (qt>=5.12.4)
FILELIST += "library/libssl-1_1-x64.dll"
win32:TARGET_DIR ~= s,/,\\,g
for(FILE, FILELIST) {
win32:FILE ~= s,/,\\,g
$$basename(FILE).depends = $$shell_quote($$FILE)
$$basename(FILE).target = $${TARGET_DIR}/$$basename(FILE)
$$basename(FILE).commands = $(COPY_FILE) $$shell_quote($$FILE) $$shell_quote($${TARGET_DIR})
QMAKE_EXTRA_TARGETS += $$basename(FILE)
PRE_TARGETDEPS += $${TARGET_DIR}/$$basename(FILE)
}
In the above case, for the debug build, QMake generates two rules in the Makefile,
D:/Qt/MyProject/debug/libcrypto-1_1-x64.dll: library/libcrypto-1_1-x64.dll
$(COPY_FILE) library\libcrypto-1_1-x64.dll D:\Qt\MyProject\debug
D:/Qt/MyProject/debug/libssl-1_1-x64.dll: library/libssl-1_1-x64.dll
$(COPY_FILE) library\libssl-1_1-x64.dll D:\Qt\MyProject\debug
This ensures that the files are getting copied only if the files in the library directory is updated.
References :
Upvotes: 0
Reputation: 10455
Can be done using for()
loop. You may need to adjust the BUILD_DIR
variable. The "other" files are takes from the current directory.
OTHER_FILES += \
input1 \
input2 \
input3 \
BUILD_DIR = build
for(file, OTHER_FILES) {
eval($${file}.depends = $$file)
eval($${file}.target = $$BUILD_DIR/$$file)
eval($${file}.commands = cp $$file $$BUILD_DIR/)
QMAKE_EXTRA_TARGETS += $${file}
PRE_TARGETDEPS += $$BUILD_DIR/$$file
}
Upvotes: 3