How to make Qt Creator use variables in the builddir path, so I can easily rename project?
-
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. - A way to use variables like
-
@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. -
@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?
-
@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 afterTARGET
is defined though).
I hope that helps.Kind regards.
PS.
You can useOBJECTS_DIR
,MOC_DIR
,RCC_DIR
andUI_DIR
to redirect any of those if it matters. - src
-
@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!
-
@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 abovepri
andMyDestinationDir
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
- project1
Kind regards.
-
-
@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!
-
@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.