Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Copy files to output directory keeping the original path



  • I want to copy some file to the output directory after build and I wrote this in my project file:

    OTHER_FILES += \
        languages\translation_it.qm \
        languages\translation_en.qm
    
    win32 {
        DESTDIR_WIN = $${OUT_PWD}
        DESTDIR_WIN ~= s,/,\\,g
        PWD_WIN = $${PWD}
        PWD_WIN ~= s,/,\\,g
        for(FILE, OTHER_FILES){
            QMAKE_POST_LINK += $$quote(cmd /c copy /y $${PWD_WIN}\\$${FILE} $${DESTDIR_WIN}$$escape_expand(\\n\\t))
        }
    }
    

    It works, but:

    1. it copies the files only when a rebuild is issued. I'd like it copies them after each build
    2. it doesn't keep the original path. I.e. it copies the files (translation_en.qm) to the destination directory, without the path (languages/)
    3. the OUT_DIR is where the intermediate files are places, what is the real output directory, where the executables are? I.e. OUT_DIR/debug


  • @Mark81 said in Copy files to output directory keeping the original path:

    1. it copies the files only when a rebuild is issued. I'd like it copies them after each build

    If there is a successful link involved it should work.

    @Mark81 said in Copy files to output directory keeping the original path:

    1. it doesn't keep the original path. I.e. it copies the files (translation_en.qm) to the destination directory, without the path (languages/)

    That is an issue of copy command restrictions. You may want to check xcopy which is more powerful. However, IIRC it also does not provide the functionality required.

    @Mark81 said in Copy files to output directory keeping the original path:

    1. the OUT_DIR is where the intermediate files are places, what is the real output directory, where the executables are? I.e. OUT_DIR/debug

    Why not using DESTDIR?


  • Moderators

    To add to what @koahnig said,
    here's an excerpt from my current .pro file. Copies files(including specific sub dirs) just fine.

    TEMPLATE    = app
    DESTDIR     = deployment
    
    # copies the given files to the destination directory
    defineTest(copyToDestDir) {
        files = $$1
        dir = $$2
        # replace slashes in destination path for Windows
        win32:dir ~= s,/,\\,g
    
        for(file, files) {
            # replace slashes in source path for Windows
            win32:file ~= s,/,\\,g
    
            QMAKE_POST_LINK += $$QMAKE_COPY_DIR $$shell_quote($$file) $$shell_quote($$dir) $$escape_expand(\\n\\t)
        }
    
        export(QMAKE_POST_LINK)
    }
    
    copyToDestDir($$PWD/translations, deployment/translations)
    copyToDestDir($$PWD/data/data, deployment/data)
    copyToDestDir($$PWD/data/Logo, deployment/Logo)
    


  • @koahnig said in Copy files to output directory keeping the original path:

    If there is a successful link involved it should work.

    You're right, I changed nothing hence it did nothing!

    Why not using DESTDIR?

    Because I have to set it manually. But I can live with that... I just set it and it works - of course.



  • @J.Hilk said in Copy files to output directory keeping the original path:

    To add to what @koahnig said,
    here's an excerpt from my current .pro file. Copies files(including specific sub dirs) just fine.

    Thank you very much. It works for me too! Just a question: it doesn't support wildcards, does it? I.e., something like:

    copyToDestDir($$PWD/translations/*.qm, deployment/translations)


  • Moderators

    @Mark81

    I don't think so, I'm not an expert with the pro file :-), this one I cobbled together from different documentation examples and a stackoverflow thread.

    maybe someone else can give you a better answer to that.


  • Lifetime Qt Champion

    Hi,

    IIRC, you can use QMAKE_COPY_DIR) for copying the content of a folder.


Log in to reply