开发者

How I can instruct a Qt Creator PRO file to output the *.o files and moc_* files in separate folder?

开发者 https://www.devze.com 2023-03-09 02:58 出处:网络
Currently QtCreator creates .o and moc_ files in the root folder of the application. How I can instruct t开发者_开发问答he project file to put them in a subfolder called \"obj\"?You can use the OBJECT

Currently QtCreator creates .o and moc_ files in the root folder of the application. How I can instruct t开发者_开发问答he project file to put them in a subfolder called "obj"?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号