Search code examples
qtbuild-process

Unable to customise the build directory for Qt Creator/qmake


I've got problem trying to specify the build directory (the directory that is to store all the files prior to copying them to the DESTDIR path).

I've got the following values in my .pro file:

DESTDIR  = E:/Development/project/build/core/debug
OUT_PWD  = E:/Development/project/build/core/debug
OBJECTS_DIR = $$DESTDIR/.obj
MOC_DIR = $$DESTDIR/.moc
RCC_DIR = $$DESTDIR/.qrc
UI_DIR = $$DESTDIR/.ui

Now, all the files eventually end up in that location, however during build, the compiler is always using the "E:/Development/build/MinGW_32bit-Debug/src/core" folder (note the missing project path). This is annoying, because I want to use the /Project/build directory as this location (which is not tracked in my git repo).

Ideally, I'd like this path to be: E:\Development\project\build\src\core\debug.

The reason I want to do this is that the build process has the same location to include the compiled libs from (it's a subdirs project).

I've had a look in the Tools > Options > Build & Run > General settings, and the default build directory is: build/build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}

I've had a look in my project.pro.user file, and found the following line:

<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:/Development/build/MinGW_32bit-Debug</value>

However I'm unable to change this value. If I edit this line in the file directly, as soon as I open Qt Creator again, the change has reverted back.

Is this a Qt Creator thing, or is it a qmake thing? Would I better off using a different build system such as CMake?


Solution

  • The build directory is "specified" by starting qmake or cmake in the build directory. There's no point to setting it in the .pro file itself.

    Qt Creator stores the build directories for a project in the .user file. Any changes made to this file outside of Qt Creator, while the project is open in the Creator, will be lost. Creator loads the file when opening the project, or creates a new one if it doesn't exist.

    When the Creator starts the build by invoking qmake or cmake, it starts that process in the build directory. That's also how you should be building the project manually from the command line.

    Finally, it makes very little sense to override the destinations of the intermediate build results. They are somewhere within the build directory, and that's all that matters. You're not using these files directly for anything anyway.

    The customary way to build a qmake project:

    mkdir project-build
    cd project-build
    qmake ~/project-src
    make -j
    

    The build folder should not be within the source tree!

    I've recently started keeping them in $TEMP / %TEMP%: manually purging the stale builds of all sort of test projects got old after a while :)