Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to make Qt Creator use variables in the builddir path, so I can easily rename project?
QtWS25 Last Chance

How to make Qt Creator use variables in the builddir path, so I can easily rename project?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
buildpathqtcreatorproject
8 Posts 2 Posters 7.1k Views
  • 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.
  • Stefan Monov76S Offline
    Stefan Monov76S Offline
    Stefan Monov76
    wrote on last edited by Stefan Monov76
    #1

    In Qt Creator, in Tools -> Options -> Build & Run -> General -> Build and Run -> Default build directory I have this value:

    ../build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}

    This works but on project creation the variables in that string get replaced with their values, which means that if I later rename the project, I need to go through all of [Debug, Profile, Release] modes and manually change the builddir's path so it reflects the new project name.

    So I want:

    • A way to use variables like %{CurrentProject:Name} in the project settings
    • (less important) A way to have Qt Creator automatically put references to such variables in the project settings on project creation, so I don't have to adjust them on project creation
    • Alternatively: Some other pain-free way to rename my project without having to update so many places

    Note: I could remove the project-name part from the builddir template, and put the builddir in "." (project dir) rather than in ".." (parent of project dir), that way it would work and there would be no name collisions (MS Visual Studio does it this way), but unfortunately qmake has a limitation (see tobias.hunger's post) that makes it sometimes break unless the project dir is at "the same level" as the builddir.

    kshegunovK 1 Reply Last reply
    0
    • Stefan Monov76S Stefan Monov76

      In Qt Creator, in Tools -> Options -> Build & Run -> General -> Build and Run -> Default build directory I have this value:

      ../build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}

      This works but on project creation the variables in that string get replaced with their values, which means that if I later rename the project, I need to go through all of [Debug, Profile, Release] modes and manually change the builddir's path so it reflects the new project name.

      So I want:

      • A way to use variables like %{CurrentProject:Name} in the project settings
      • (less important) A way to have Qt Creator automatically put references to such variables in the project settings on project creation, so I don't have to adjust them on project creation
      • Alternatively: Some other pain-free way to rename my project without having to update so many places

      Note: I could remove the project-name part from the builddir template, and put the builddir in "." (project dir) rather than in ".." (parent of project dir), that way it would work and there would be no name collisions (MS Visual Studio does it this way), but unfortunately qmake has a limitation (see tobias.hunger's post) that makes it sometimes break unless the project dir is at "the same level" as the builddir.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @Stefan-Monov76 said in How to make Qt Creator use variables in the builddir path, so I can easily rename project?:

      qmake has a limitation (see tobias.hunger's post) that makes it sometimes break unless the project dir is at "the same level" as the builddir.

      It has, but you can shadow-build in ../bin-debug and ../bin for debug and release respectively (the names are arbitrary, it's just what I use). The latter also incidentally puts the binaries at the same level as the source, so neither qmake nor Qt Creator complain. Also you could hardcode the (relative) output dir in the qmake project file - OUT_PWD is the relevant qmake variable, which should fix your problem. As for the first part of your question, I have no idea, sorry.

      Read and abide by the Qt Code of Conduct

      Stefan Monov76S 1 Reply Last reply
      0
      • kshegunovK kshegunov

        @Stefan-Monov76 said in How to make Qt Creator use variables in the builddir path, so I can easily rename project?:

        qmake has a limitation (see tobias.hunger's post) that makes it sometimes break unless the project dir is at "the same level" as the builddir.

        It has, but you can shadow-build in ../bin-debug and ../bin for debug and release respectively (the names are arbitrary, it's just what I use). The latter also incidentally puts the binaries at the same level as the source, so neither qmake nor Qt Creator complain. Also you could hardcode the (relative) output dir in the qmake project file - OUT_PWD is the relevant qmake variable, which should fix your problem. As for the first part of your question, I have no idea, sorry.

        Stefan Monov76S Offline
        Stefan Monov76S Offline
        Stefan Monov76
        wrote on last edited by
        #3

        @kshegunov said in How to make Qt Creator use variables in the builddir path, so I can easily rename project?:

        you can shadow-build in ../bin-debug and ../bin

        That would mean building several different projects (which are in the same base dir) would use the same builddir, and I don't want that. Instead, I shadow-build in ../build-myproj-Qt_opensource_x86_msvc2015_5_7_0-Debug (and similar for Release), which avoids this name conflict. This puts the builddir at the same level as the sourcedir, so no problem with that.

        Also you could hardcode the (relative) output dir in the qmake project file - OUT_PWD is the relevant qmake variable, which should fix your problem.

        I'd still have to hardcode a different output dir for the different buildmodes (Debug, Release...), and I'd have to change this hardcoded dir when I rename the project. So I don't see how this solves the problem. Could you please explain?

        kshegunovK 1 Reply Last reply
        0
        • Stefan Monov76S Stefan Monov76

          @kshegunov said in How to make Qt Creator use variables in the builddir path, so I can easily rename project?:

          you can shadow-build in ../bin-debug and ../bin

          That would mean building several different projects (which are in the same base dir) would use the same builddir, and I don't want that. Instead, I shadow-build in ../build-myproj-Qt_opensource_x86_msvc2015_5_7_0-Debug (and similar for Release), which avoids this name conflict. This puts the builddir at the same level as the sourcedir, so no problem with that.

          Also you could hardcode the (relative) output dir in the qmake project file - OUT_PWD is the relevant qmake variable, which should fix your problem.

          I'd still have to hardcode a different output dir for the different buildmodes (Debug, Release...), and I'd have to change this hardcoded dir when I rename the project. So I don't see how this solves the problem. Could you please explain?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @Stefan-Monov76 said in How to make Qt Creator use variables in the builddir path, so I can easily rename project?:

          That would mean building several different projects (which are in the same base dir) would use the same builddir, and I don't want that.

          Not necessarily, it was just an example. Something like this should also be easily achievable:

          • src
            • project1
            • project2
          • bin
            • project1
            • project2
          • bin-debug
            • project1
            • project2

          I'd still have to hardcode a different output dir for the different buildmodes (Debug, Release...), and I'd have to change this hardcoded dir when I rename the project.

          You would, but the dir can still be relative to the project file's folder. You probably will have to change it when the project is renamed, though, that much is true. It's just an alternative way of doing things, not necessarily better or solving your problem (not tested):

          MyDestinationDir = /some/base/dir
          
          CONFIG(debug, debug|release):MyDestinationDir = $$MyDestinationDir/$$TARGET/debug
          CONFIG(release, debug|release): MyDestinationDir = $$MyDestinationDir/$$TARGET/release
          
          DESTDIR = $$MyDestinationDir
          

          One would ordinarily put the above in a pri file and include it throughout the projects (must be after TARGET is defined though).
          I hope that helps.

          Kind regards.

          PS.
          You can use OBJECTS_DIR, MOC_DIR, RCC_DIR and UI_DIR to redirect any of those if it matters.

          Read and abide by the Qt Code of Conduct

          Stefan Monov76S 1 Reply Last reply
          0
          • kshegunovK kshegunov

            @Stefan-Monov76 said in How to make Qt Creator use variables in the builddir path, so I can easily rename project?:

            That would mean building several different projects (which are in the same base dir) would use the same builddir, and I don't want that.

            Not necessarily, it was just an example. Something like this should also be easily achievable:

            • src
              • project1
              • project2
            • bin
              • project1
              • project2
            • bin-debug
              • project1
              • project2

            I'd still have to hardcode a different output dir for the different buildmodes (Debug, Release...), and I'd have to change this hardcoded dir when I rename the project.

            You would, but the dir can still be relative to the project file's folder. You probably will have to change it when the project is renamed, though, that much is true. It's just an alternative way of doing things, not necessarily better or solving your problem (not tested):

            MyDestinationDir = /some/base/dir
            
            CONFIG(debug, debug|release):MyDestinationDir = $$MyDestinationDir/$$TARGET/debug
            CONFIG(release, debug|release): MyDestinationDir = $$MyDestinationDir/$$TARGET/release
            
            DESTDIR = $$MyDestinationDir
            

            One would ordinarily put the above in a pri file and include it throughout the projects (must be after TARGET is defined though).
            I hope that helps.

            Kind regards.

            PS.
            You can use OBJECTS_DIR, MOC_DIR, RCC_DIR and UI_DIR to redirect any of those if it matters.

            Stefan Monov76S Offline
            Stefan Monov76S Offline
            Stefan Monov76
            wrote on last edited by
            #5

            @kshegunov : I didn't delve a lot into your QMake code (I don't know QMake's syntax) but if you say it's not necessarily better or solving my problem, then I don't think I'll look further into it. Thanks anyway!

            kshegunovK 1 Reply Last reply
            0
            • Stefan Monov76S Stefan Monov76

              @kshegunov : I didn't delve a lot into your QMake code (I don't know QMake's syntax) but if you say it's not necessarily better or solving my problem, then I don't think I'll look further into it. Thanks anyway!

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @Stefan-Monov76 said in How to make Qt Creator use variables in the builddir path, so I can easily rename project?:

              I didn't delve a lot into your QMake code (I don't know QMake's syntax) but if you say it's not necessarily better or solving my problem, then I don't think I'll look further into it.

              I think it's what you want (that's why I posted it), but it doesn't depend on QtCreator and can't be "controlled" from there. I think there's a way to transfer variables from creator to qmake, but I haven't the time to look it up just now. The qmake code just builds the build path for your project from a fixed prefix (MyDestinationDir), the target name and the build mode. So if you have multiple projects that are including the above pri and MyDestinationDir is set to /my/build/dir, then the project structure would look like this:

              • Source base dir

                • project1
                • project2
              • /my/build/dir (this is quite independent from the source dir now)

                • project1
                  • debug
                  • release
                • project2
                  • debug
                  • release

              Kind regards.

              Read and abide by the Qt Code of Conduct

              Stefan Monov76S 1 Reply Last reply
              0
              • kshegunovK kshegunov

                @Stefan-Monov76 said in How to make Qt Creator use variables in the builddir path, so I can easily rename project?:

                I didn't delve a lot into your QMake code (I don't know QMake's syntax) but if you say it's not necessarily better or solving my problem, then I don't think I'll look further into it.

                I think it's what you want (that's why I posted it), but it doesn't depend on QtCreator and can't be "controlled" from there. I think there's a way to transfer variables from creator to qmake, but I haven't the time to look it up just now. The qmake code just builds the build path for your project from a fixed prefix (MyDestinationDir), the target name and the build mode. So if you have multiple projects that are including the above pri and MyDestinationDir is set to /my/build/dir, then the project structure would look like this:

                • Source base dir

                  • project1
                  • project2
                • /my/build/dir (this is quite independent from the source dir now)

                  • project1
                    • debug
                    • release
                  • project2
                    • debug
                    • release

                Kind regards.

                Stefan Monov76S Offline
                Stefan Monov76S Offline
                Stefan Monov76
                wrote on last edited by
                #7

                @kshegunov : Ah, and since you used the TARGET var, I won't need to edit paths when I rename the project? Nice, that's closer to what I'm looking for.

                I'd use it, but it's straying too far from the standard ways for me, and may easily conflict with something in Creator, so I'll err on the side of caution and keep using Creator's GUI for setting this stuff up.

                Thanks anyway!

                kshegunovK 1 Reply Last reply
                0
                • Stefan Monov76S Stefan Monov76

                  @kshegunov : Ah, and since you used the TARGET var, I won't need to edit paths when I rename the project? Nice, that's closer to what I'm looking for.

                  I'd use it, but it's straying too far from the standard ways for me, and may easily conflict with something in Creator, so I'll err on the side of caution and keep using Creator's GUI for setting this stuff up.

                  Thanks anyway!

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @Stefan-Monov76 said in How to make Qt Creator use variables in the builddir path, so I can easily rename project?:

                  Thanks anyway

                  You're welcome. Shadow building (option 1 from above) should work for you regardless.

                  Read and abide by the 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