<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[qmake replace function not working]]></title><description><![CDATA[<p dir="auto">In order to avoid code duplication in one of my <code>.pro</code> files, I have created the following qmake replace function called <code>copyAndModify</code>:</p>
<pre><code>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}) &gt; $$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()
}
</code></pre>
<p dir="auto">What it basically does is:</p>
<ol>
<li>Copy a config file to a destination file (if it does not exist yet).</li>
<li>Do some textual replacements using qmake's <code>sed</code> implementation.  Because that <code>sed</code> implementation cannot do in-file replacements (<code>-i</code> option) I am first redirecting output to a <code>.tmp</code> file, and then move the <code>.tmp</code> file to the destination file.</li>
</ol>
<p dir="auto">I call this function in the same <code>.pro</code> file as follows:</p>
<pre><code>SRC_FILE = $${PWD}/doc/config/foobar.conf
DST_FILE = $${CONFIG_DIR}/foobar.conf
$$copyAndModify($${SRC_FILE}, $${DST_FILE})
</code></pre>
<p dir="auto">but for some reason, the <code>QMAKE_POST_LINK</code> commands are not added to my PostBuildEvents in my Visual Studio 2019 project.  It also doesn't work if I pass the arguments as follows:</p>
<pre><code>$$copyAndModify(SRC_FILE, DST_FILE)
</code></pre>
<p dir="auto">What am I doing wrong?</p>
]]></description><link>https://forum.qt.io/topic/132440/qmake-replace-function-not-working</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 20:41:08 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/132440.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 01 Dec 2021 13:27:41 GMT</pubDate><ttl>60</ttl></channel></rss>