8

Currently QtCreator creates .o and moc_ files in the root folder of the application. How I can instruct the project file to put them in a subfolder called "obj"?

Gad D Lord
  • 6,620
  • 12
  • 60
  • 106

2 Answers2

9

You can use the OBJECTS_DIR and MOC_DIR variables for this. e.g. Qt itself does something like this while building:

OBJECTS_DIR = .obj
MOC_DIR     = .moc

In this case I think the .obj, .moc directories are relative to the directory containing the Makefile.

rohanpm
  • 4,264
  • 17
  • 16
3

To keep your main (source) folder clean of binary and generated files you can put the following lines in your "myapp.pro" file:

DESTDIR = ../../bin
UI_DIR = .

CONFIG(debug, debug|release) {
        TARGET = myappd
        OBJECTS_DIR = ../../build/myapp/debug
        MOC_DIR = ../../build/myapp/debug
}

CONFIG(release, debug|release) { 
        TARGET = myapp
        OBJECTS_DIR = ../../build/myapp/release
        MOC_DIR = ../../build/myapp/release
}

The above settings imply the following directory structure:

myprojects/source/myapp/   => containing myapp.pro + all other project files hpp, cpp etc.
myprojects/bin/  => containing myapp.exe & myappd.exe application files
myprojects/build/myapp/release  => object files + moc files (release)
myprojects/build/myapp/debug   => object files + moc files (debug)

The last 3 directories will be automatically created if they do not exist.

The advantages of this schema is:

a. You can move your project (myapp directory) to another parent directory and it will continue to build OK due to the relative specification of bin & build directories

b. You can add more sub-projects under myprojects/source/

c. You can backup (e.g. ZIP) all of myprojects/source/ directory without including any binary or generated files

Fivos Vilanakis
  • 1,490
  • 12
  • 13