Disable "The build directory needs to be at the same level as the source directory" warning in Qt Creator

11.8k Views Asked by At

I have a Qt project located in the folder /Users/donaldduck/OneDrive/Documents/myproject, and I want to have the build directory as a subfolder of the source directory, at /Users/donaldduck/OneDrive/Documents/myproject/build-myproject. The problem is that Qt Creator gives me a warning saying "The build directory needs to be at the same level as the source directory":

enter image description here

Other than this warning, the project compiles just fine. I don't even get any problems that the build directory is a subfolder of the source directory. I searched on the web to see why I get this warning, and I found that it's probably because not having the build directory at the same level as the source directory could cause problems with relative paths. But I don't have any relative paths in my program, I have all of the files in a QRC resource.

So this error is just annoying, and I would like to disable it. I've searched the web for a solution, but haven't found anything.

Also, I only get this warning on my Windows computer and on my Mac virtual machine. I have a similar folder structure (the build directory is a subfolder of the source directory) on my Linux virtual machine, but none of them give any warning. Also, before I updated Qt on Windows, I didn't get that warning, but since I updated it I've been getting this warning on Windows also.

How can I disable this warning?

2

There are 2 best solutions below

0
On

Disabling not possible but the solution is to change build directory.

This warning does show if the source- and the build directory do not contain the same number of / (or \ on windows) in their absolute path names.

Assuming your source directory is "c:\dev\source\project", then "..\build-directory" is fine, but e.g. "..\build\directory" is not. "c:\dev\build\project\debug" is not ok, but "c:\dev\build\project-debug" is. "./debug" and "debug" are not ok as build directories either.

Is what you can observe as well? Or are all paths starting with "..\" triggering this warning?

Qmake will fail to build projects that are not following the "same distance from root" rule in some rare corner cases and will produce really cryptic output when it does. So we need to warn about a setup like this.

you can use your default directory like this: ../%{CurrentBuild:Name}

Screenshot: image

I use this directory: ../Build/Windows/%{CurrentBuild:Name} and I don't care about the warning!

Reference: https://bugreports.qt.io/browse/QTCREATORBUG-16616

0
On

I know this post is old but since the versions of Qt have evolved a bit since then, I allow myself to post this answer to best help those who would be confronted with this problem on Qt Creator 9.0.1 :)

I set up this architecture (in my documents) to separate my sources "Projets_Qt" from my builds "Projets_Qt_Builds".
enter image description here

Then under Qt Creator I went to the "Edit" menu then "Preferences" and "Build & Run"
In the "General" tab I filled in "Project Directory" the folder of my sources "C:\Users\juan\Documents\Projets_Qt"
enter image description here


In the "Default Build Properties" tab I filled in "Default build directory" the folder of my builds "../../Projets_Qt_Builds/%{JS: Util.asciify("build-%{Proj... ...". It's a relative path built from the sources actually
enter image description here


Think about it :
If you perform this operation while projects have already been created, do not forget to modify the project in question.
Once your project is open, use the "Projects" menu in the right icon bar, then in the desired kit modify "Build Directory"
enter image description here

Hope this information can help :)