Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qmake replace function not working
Qt 6.11 is out! See what's new in the release blog

qmake replace function not working

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 544 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bart_Vandewoestyne
    wrote on last edited by
    #1

    In order to avoid code duplication in one of my .pro files, I have created the following qmake replace function called copyAndModify:

    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:

    1. Copy a config file to a destination file (if it does not exist yet).
    2. Do some textual replacements using qmake's sed implementation. Because that sed implementation cannot do in-file replacements (-i option) I am first redirecting output to a .tmp file, and then move the .tmp file to the destination file.

    I call this function in the same .pro file 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_LINK 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:

    $$copyAndModify(SRC_FILE, DST_FILE)
    

    What am I doing wrong?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved