Create dir & Copy files with qmake

不问归期 提交于 2019-11-29 07:44:23
macetw

This documentation appears to be missing the use of PRE_TARGETDEPS or POST_TARGETDEPS.

What that means is that the Makefile has the instructions to do what it needs to do, but those targets are not built into the dependency chain, so the Make tool never does them.

If the problem is about doing 2 things (instead of just one), try to put 2 commands in the same line. Like so:

QMAKE_EXTRA_TARGETS += foo
foo.target = $$OUT_PWD/newFolder
foo.commands = $(MKDIR) $$OUT_PWD/newFolder ; $(COPY_DIR) $SOURCE $$OUT_PWD/newFolder

... You might also try "&&" instead of ";", to get strong checks of return codes. You could choose to create 2 QMAKE_EXTRA_TARGETS that depend on one another.

QMAKE_EXTRA_TARGETS += foo bar
foo.target = $$OUT_PWD/newFolder
foo.commands = $(MKDIR) $$OUT_PWD/newFolder
bar.target = $$OUT_PWD/newFolder/file
bar.commands = $(COPY_DIR) $SOURCEOFFILE $$OUT_PWD/newFolder
bar.depends = foo

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!