Qt 6.11 is out! See what's new in the release
blog
qmake replace function not working
-
In order to avoid code duplication in one of my
.profiles, I have created the following qmake replace function calledcopyAndModify:defineReplace(copyAndModify) { srcFile = $$1 dstFile = $$2 QMAKE_POST_LINK += $$sprintf($$QMAKE_CHK_EXISTS, $$shell_path($${dstFile})) \ $$QMAKE_COPY $$shell_path($${srcFile}) $$shell_path($${dstFile})$$escape_expand(\n\t) QMAKE_POST_LINK += $$QMAKE_QMAKE -install sed -e 's/foo//g' \ -e 's/bar//g' \ -e 's/baz//g' $$shell_path($${dstFile}) > $$shell_path($${dstFile}.tmp)$$escape_expand(\n\t) QMAKE_POST_LINK += $$QMAKE_MOVE $$shell_path($${dstFile}.tmp) $$shell_path($${dstFile})$$escape_expand(\n\t) return() }What it basically does is:
- Copy a config file to a destination file (if it does not exist yet).
- Do some textual replacements using qmake's
sedimplementation. Because thatsedimplementation cannot do in-file replacements (-ioption) I am first redirecting output to a.tmpfile, and then move the.tmpfile to the destination file.
I call this function in the same
.profile as follows:SRC_FILE = $${PWD}/doc/config/foobar.conf DST_FILE = $${CONFIG_DIR}/foobar.conf $$copyAndModify($${SRC_FILE}, $${DST_FILE})but for some reason, the
QMAKE_POST_LINKcommands are not added to my PostBuildEvents in my Visual Studio 2019 project. It also doesn't work if I pass the arguments as follows:$$copyAndModify(SRC_FILE, DST_FILE)What am I doing wrong?