I am trying to copy target binary file in multiple folders. In first step I must create those multiple folders. I have followed this example without success.
The only thing that worked was system(mkdir $$OUT_PWD/newFolder)
, but I'm trying to use
QMAKE_EXTRA_TARGETS
for $(MKDIR)
followed by $(COPY)
from this example.
Using Qt 4.8.6 with qmake 2.01a.
This is how I run qmake:
qmake Server.pro -r -spec linux-g++ CONFIG+=debug CONFIG+=declarative_debug
Update: This is my current implementation, which creates a list of directories and copies the target binary to selected directories.
# List all server directories
DIRS = server-1 \
server-2 \
server-3 \
server-4
INSTALL_PATH = $$OUT_PWD
# Shadow build detection
!equals(PWD, $$OUT_PWD) INSTALL_PATH = $$replace(INSTALL_PATH, build, install)
# Loop over all given directories and append the 'install' directory to make absolute paths
for(DIR, DIRS) ABS_DIRS += $$INSTALL_PATH/$$DIR
# Create 'copy' commands for $DIRS
for(DIR, ABS_DIRS) CP_CMD += $(COPY) $$OUT_PWD/$$TARGET $$DIR &&
# Ignore last &&
CP_CMD += true
install.commands = $(MKDIR) $$ABS_DIRS && $$CP_CMD
QMAKE_EXTRA_TARGETS += install
QMAKE_POST_LINK += install
The missing part for me was that I didn't execute make with correct arguments. After calling make install
which also includes qmake INSTALLS
files, the code executes. However this fails on clean build with given error: install: missing file operand. If I rename the install command with for example copy, I get this error: make: copy: Command not found. Any clues?
Got it working. Some side notes ... QtCreator by default creates build-project-kit-debug/release directory for building if shadow build is enabled. This code creates install-project-kit-debug/release directory on same level with listed DIRS
as sub directories. Directories are created after compile with create
command. Target binary is then copied to DIRS
directories after linking.
Thanks to macetw for POST_TARGETDEPS
which also lead me to QMAKE_POST_LINK
. qmake
and make
are ran without any extra arguments.
# Sets target destination dir - platform independent
win32 {
build_pass: CONFIG(debug, debug|release) {
DESTDIR = $$OUT_PWD/debug
}
else: build_pass {
DESTDIR = $$OUT_PWD/release
}
}
unix {
DESTDIR = $$OUT_PWD
}
# List all server directories
DIRS = server-1 \
server-2 \
server-3 \
server-4
INSTALL_PATH = $$DESTDIR
# Shadow build detection
!equals(PWD, $$DESTDIR) INSTALL_PATH = $$replace(INSTALL_PATH, build, install)
# Loop over all given directories and append the 'install' directory to make absolute paths
for(DIR, DIRS) ABS_DIRS += $$INSTALL_PATH/$$DIR
# Create 'copy' commands for $DIRS
for(DIR, ABS_DIRS) CP_CMD += $(COPY) $$DESTDIR/$$TARGET $$DIR ;
create.commands = $(MKDIR) $$ABS_DIRS
QMAKE_EXTRA_TARGETS += create
POST_TARGETDEPS += create
QMAKE_POST_LINK += $$CP_CMD