Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qmake Copy files in target directory
Forum Updated to NodeBB v4.3 + New Features

Qmake Copy files in target directory

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 4 Posters 9.1k 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.
  • N Offline
    N Offline
    Nazardo
    wrote on last edited by
    #1

    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

    "It is easier to change the specification to fit the program than vice versa" -- Alan Perlis

    1 Reply Last reply
    0
    • J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

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


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Princein
        wrote on last edited by
        #3

        It's not work for on windows, I don't know why

        here is my .pro file:

        ROOT_DIRECTORY = $$PWD
        LIB_DIRECTORY = $${ROOT_DIRECTORY}/lib
        BUILD_DIRECTORY = $${ROOT_DIRECTORY}/lib
        TESTS_DIRECTORY = $${BUILD_DIRECTORY}/tests
        EXAMPLES_DIRECTORY = $${BUILD_DIRECTORY}/examples
        EXEC_DIRECTORY = $${BUILD_DIRECTORY}

        #$${LIB_DIRECTORY}
        DESTDIR = $${EXEC_DIRECTORY}
        OBJECTS_DIR = $${BUILD_DIRECTORY}
        MOC_DIR = $${BUILD_DIRECTORY}
        RCC_DIR = $${BUILD_DIRECTORY}

        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/Files/, $$DESTDIR/)

        jsulmJ 1 Reply Last reply
        0
        • P Princein

          It's not work for on windows, I don't know why

          here is my .pro file:

          ROOT_DIRECTORY = $$PWD
          LIB_DIRECTORY = $${ROOT_DIRECTORY}/lib
          BUILD_DIRECTORY = $${ROOT_DIRECTORY}/lib
          TESTS_DIRECTORY = $${BUILD_DIRECTORY}/tests
          EXAMPLES_DIRECTORY = $${BUILD_DIRECTORY}/examples
          EXEC_DIRECTORY = $${BUILD_DIRECTORY}

          #$${LIB_DIRECTORY}
          DESTDIR = $${EXEC_DIRECTORY}
          OBJECTS_DIR = $${BUILD_DIRECTORY}
          MOC_DIR = $${BUILD_DIRECTORY}
          RCC_DIR = $${BUILD_DIRECTORY}

          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/Files/, $$DESTDIR/)

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Princein You should not duplicate your posts.
          You asked same question here: https://forum.qt.io/topic/98338/how-copy-the-file-which-in-my-project-directory-to-the-exe-file-directory-in-windows/11

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          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