Qmake Copy files in target directory



  • Hi all, this is my first post in this wonderful forum.

    I am trying to figure out how to achieve a simple platform independent file copy from the source directory to the directory where the executable is built.

    In the source tree we got several XML and XSD files that are referenced by the application at run-time using a relative path (data/ folder). It would be awesome to automatically have those files copied in the build directory so that debug works "out of the box" without manual interaction.

    In our development team we operate on heterogeneous setups (Win+MSVC, Win+MinGW, Linux), but we all use QtCreator with a qmake project.

    I have searched the forum for similar questions and found solutions which used INSTALLS, but our goal is to have those file copied in the debug directory not in a - yet to be defined - installation path.

    For instance, I have tried to put the following code in my .pro file and add a make install build step, but no install rules were generated in the Makefile.
    @install_it.path = %{buildDir}
    install_it.files +=
    %{sourceDir}/data/schema.xsd
    %{sourceDir}/data/file1.xsd
    %{sourceDir}/data/file2.xml

    INSTALLS += install_it@
    @mingw32-make[1]: Nothing to be done for `install'.@

    How should I proceed? I would really like to have this solved by simply extending the .pro file.
    As a possible alternative I am considering cmake, but I don't even know if it would make things simple.

    Thanks in advance for your help,

    Mauro



  • Hi everyone,

    I know, this topic is now 6 years open and without an answer. But it is also one of the first hits, when I googled for QMake_Copy solution.

    So I'll post what I use, for who else comes across this topic.

    I use qmake to copy my translation files (*.qm) so that they are found during runtime

    the original files are part of the project folder and they are all inside the translations sub directory and I copy them into the similary named translations folder that besides the executable.

    For Windows the following works fine (should also work with linux):

    //*.pro
    TARGET      = myApp
    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(srcPath, destPath)
    copyToDestDir($$PWD/translations, ../deployment/translations)
    

    For MacOS those steps are not necessary, as all relevant data ought to be part of the app bundle. Therefore I use QMAKE_BUNDLE_DATA for this

    //*.pro
    macx {
        APP_Language.files = $$PWD/translations/qt_en.qm \
                             $$PWD/translations/qt_de.qm
        APP_Language.path = Contents/MacOS/translations
        QMAKE_BUNDLE_DATA += APP_Language
    }
    

    Hopefully this is helpful for others and maybe the OP sees the answer and changes the topic to solved :-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.