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: create folder if not exist from inside makefile
Forum Updated to NodeBB v4.3 + New Features

qmake: create folder if not exist from inside makefile

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
6 Posts 2 Posters 4.1k Views 2 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.
  • D Offline
    D Offline
    deleted57
    wrote on 12 Apr 2019, 06:56 last edited by
    #1

    Hi all

    Using Qt Creator I need to generate a makefile with instruction to create a folder if not exist before start compile. I added this line to the .pro file:

    createdir.commands = $(CHK_DIR_EXISTS) $$shell_path(path/of/dir) & $(MKDIR) $$shell_path(path/of/dir)
    

    My problem is that this line work as expencted if compilation is executed on Windows (cause the label CHK_DIR_EXISTS is replaced by "if not exist") but doesn't work if compiled on Linux (in this case the label is replaced with "test -d"). The test tool return an error about an incorrect params. I tried to remove the CHK_DIR_EXISTS condition and, basically, leave the command to create folder only. This work on Linux but return error on Windows cause the mkdir command return error in case the folder already exist and this error stop the compilation.

    Someone can suggest an "universal" metod to create a folder from inside makefile? Please note I can not use the qmake command exist() cause it is executed only the fist time in the phase of makefile creation and not during each compilation.

    Thank you

    K 1 Reply Last reply 12 Apr 2019, 07:38
    0
    • D deleted57
      12 Apr 2019, 06:56

      Hi all

      Using Qt Creator I need to generate a makefile with instruction to create a folder if not exist before start compile. I added this line to the .pro file:

      createdir.commands = $(CHK_DIR_EXISTS) $$shell_path(path/of/dir) & $(MKDIR) $$shell_path(path/of/dir)
      

      My problem is that this line work as expencted if compilation is executed on Windows (cause the label CHK_DIR_EXISTS is replaced by "if not exist") but doesn't work if compiled on Linux (in this case the label is replaced with "test -d"). The test tool return an error about an incorrect params. I tried to remove the CHK_DIR_EXISTS condition and, basically, leave the command to create folder only. This work on Linux but return error on Windows cause the mkdir command return error in case the folder already exist and this error stop the compilation.

      Someone can suggest an "universal" metod to create a folder from inside makefile? Please note I can not use the qmake command exist() cause it is executed only the fist time in the phase of makefile creation and not during each compilation.

      Thank you

      K Offline
      K Offline
      koahnig
      wrote on 12 Apr 2019, 07:38 last edited by
      #2

      @Suppaman

      I do not know enough about the linux specialities. However, you could use possibly a work-around

      win32:createdir.commands = $(CHK_DIR_EXISTS) $$shell_path(path/of/dir) & $(MKDIR) $$shell_path(path/of/dir)
      linux:createdir.commands = $$shell_path(path/of/dir) & $(MKDIR) $$shell_path(path/of/dir)
      

      Check it out and I hope it helps

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

      1 Reply Last reply
      3
      • D Offline
        D Offline
        deleted57
        wrote on 12 Apr 2019, 07:43 last edited by
        #3

        Hi

        At first thank you for your reply. Unfortunately qmake tags win32: and linux: are connected to the target platform to compile for not to the OS used to compile. For make an example in case you are compiling under Linux (Qt Creator is installed on Linux) and want to crosscompile a project for Windows platform, in this case the tag win32: make sense and will be taken in consideration.

        K 1 Reply Last reply 12 Apr 2019, 09:56
        0
        • D deleted57
          12 Apr 2019, 07:43

          Hi

          At first thank you for your reply. Unfortunately qmake tags win32: and linux: are connected to the target platform to compile for not to the OS used to compile. For make an example in case you are compiling under Linux (Qt Creator is installed on Linux) and want to crosscompile a project for Windows platform, in this case the tag win32: make sense and will be taken in consideration.

          K Offline
          K Offline
          koahnig
          wrote on 12 Apr 2019, 09:56 last edited by
          #4

          @Suppaman

          You need to check out the different qmake test function then e.g. https://doc.qt.io/qt-5/qmake-test-function-reference.html#mkpath-dirpath

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

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deleted57
            wrote on 12 Apr 2019, 10:03 last edited by
            #5

            This set of function are part of qmake and are invoked only when qmake generate the makefile the first time that is an operation that happen only once during first time project configuration. If, for some reasons, the folder I'm interested in is removed using this way it will not be recreated and compilation return error. On the contrary insert this step in the makefile the folder will be recreated before each compilation start, this is the reason I need this step to be executed by the makefile.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              deleted57
              wrote on 12 Apr 2019, 14:27 last edited by
              #6

              If someone is interested found a solution:

              equals(QMAKE_HOST.os, Windows) {
              .....
              } else {
              .....
              }
              
              1 Reply Last reply
              5

              1/6

              12 Apr 2019, 06:56

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved