How to specify different Debug/Release output directories in QMake .pro file
I have a Qt project and I would like to output compilation files outside the source tree.
I currently have the following directory structure:
/
|_/build
|_/mylib
|_/include
|_/src
|_/resources
Depending on the configuration (debug/release), I will like to output the resulting files inside the build directory under build/debug or build/release directories.
How can I do that using a .pro file?
Solution 1:
For my Qt project, I use this scheme in *.pro file:
HEADERS += src/dialogs.h
SOURCES += src/main.cpp \
src/dialogs.cpp
Release:DESTDIR = release
Release:OBJECTS_DIR = release/.obj
Release:MOC_DIR = release/.moc
Release:RCC_DIR = release/.rcc
Release:UI_DIR = release/.ui
Debug:DESTDIR = debug
Debug:OBJECTS_DIR = debug/.obj
Debug:MOC_DIR = debug/.moc
Debug:RCC_DIR = debug/.rcc
Debug:UI_DIR = debug/.ui
It`s simple, but nice! :)
Solution 2:
To change the directory for target dll/exe, use this in your pro file:
CONFIG(debug, debug|release) {
DESTDIR = build/debug
} else {
DESTDIR = build/release
}
You might also want to change directories for other build targets like object files and moc files (check qmake variable reference for details or qmake CONFIG() function reference).