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

How to copy a folder from source to build directory in qmake



  • Ive been using CMake in using QT and this is my first time using qmake.
    and I want to know how to copy an entire folder from my PWD (current source file where .pro is located) to the build directory.
    like I have a folder named "resources" where it contains multiple files, and i want to copy the folder to build directory like
    source
    main.cpp
    mainwindow.cpp
    [resources]
    .... res.out1

    target (build folder)
    [resources]
    Makefile
    Makefile.Debug
    ui_mainwindow.h

    All i see when googling are copy files, but when i modify it a little to copy to a folder (non existing or new one) none works,

    Any help?


  • Lifetime Qt Champion

    Hi,

    Not a direct answer but since you are used to cmake and Qt 6 has switch its build system to cmake, why move to qmake ?


  • Moderators

    I have posted this before, but I'm personnally using this:

    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)
    }
    

    It will copy the folder content from a to b
    copyToDestDir($$PWD/a, $$Deployment_Path/release/b)


Log in to reply