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

Install files after build



  • Hi,
    I have subdirs project in Qt 5.7 that consists of:

    mainProject (build directory is build/mainProject)
    module1 (build directory is build/module1)

    I need module1 binary to be installed in build/module1/debug/module1 (for debug build). I also need some resource files (music and images) to be copied to build/module1/debug/module1/resources. Module1 doesn't work properly without them.

    I then need to copy (install) whole build/module1/debug/module1/ folder (which contains everything needed to run module1) to build/mainProject/debug/module1 folder. MainProject loads module1 and module1 must be copied in the same folder as mainProject binary.

    I tried to accomplish this by specifying new target containing my data and then appending that target to INSTALLS but this is not ideal as my resource files are big (hundreds of MB) and I guess INSTALLS just copies all data everytime the project is built. I want to optimize this and to copy files only when destination file doesn't exist or when it is older. Otherwise my build times will be long everytime.

    I also tried to use QMAKE_EXTRA_TARGETS with operating system's copy command (robocopy for Windows), for e.g. copying module1 binary to build/module1/debug/module1/

    copyinstall.target = .copyinstall
    copyinstall.commands += -robocopy $$OUT_PWD/debug $$OUT_PWD/debug/module1 *.dll /XO $$escape_expand(\n\t)

    QMAKE_EXTRA_TARGETS += copyinstall
    PRE_TARGETDEPS += .copyinstall

    But the problem with this is it copies the file before it is built. I always get one build old binary file in build/module1/debug/module1/.

    Can you please advise anything on this topic?


  • Lifetime Qt Champion

    Hi
    I took another way with the resources.
    I define

    DEFINES += PROJECT_LOCATION=$$shell_quote(\"$$PWD\")
    

    in .pro file
    and in the code i have the compiled in path for the project folder.
    I then check if i can load the resources, right next to the app and if not
    i use PROJECT_LOCATION to load them directly from project folder.
    Though i would just mention it as an alternative to copying stuff around.



  • @mrjj Thanks. This is good idea.

    I also think about adding new build step after make install which will run e.g. bat file on Windows that will install (copy) all neccesary files to proper locations. This is not multiplatform way to install files but I can probably live with that.


  • Lifetime Qt Champion

    @MartinD
    Just as a note, you can make the copying with bat/sh file cross platform but not worth the fuss if you just need it to develop on Windows. (IMO)



  • Hi,
    Multi-link Technology will help you.
    It is designed for your purpose, link library, deploy library, deploy config/resource, deploy language..., it can also deploy app self.
    Gitee-Link



  • I came across another thing when I build my project for Android on Win10.

    I copy resource files to assets folder of the Android build. I noticed, that this folder is deleted every build. It means my big resource files have to be copied everytime when I build my project. How can I prevent assets fodler to be deleted.


Log in to reply