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. Copy files to output directory keeping the original path

Copy files to output directory keeping the original path

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
7 Posts 4 Posters 2.3k Views 3 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    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
    K 1 Reply Last reply
    0
    • M Mark81

      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
      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @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?

      Vote the answer(s) that helped you to solve your issue(s)

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

        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)
        

        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.

        M 1 Reply Last reply
        3
        • K koahnig

          @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?

          M Offline
          M Offline
          Mark81
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            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)
            
            M Offline
            M Offline
            Mark81
            wrote on last edited by Mark81
            #5

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

            J.HilkJ 1 Reply Last reply
            0
            • M Mark81

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

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @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.


              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
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

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

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - 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