1

I'm using a qtcreator 4.0.3 and I try to create a directory struct to all builds, like this:

~/Build/project01 ~/Build/project02 ... ~/Build/projectNN

I'm using this .pro file:

:><------- Cutting ------------
#
# BUILDDIR Where the executable file was create
#
BUILDDIR = $$HOME_PATH/Builds/$$APP_NAME
#
# All Directory of temporary files
#
OBJECTS_DIR =   $$BUILDDIR/obj
MOC_DIR =       $$BUILDDIR/moc
RCC_DIR =       $$BUILDDIR/rcc
UI_DIR =        $$BUILDDIR/ui
DESTDIR =       $$BUILDDIR/bin
#
# If the dirs not exists, I'll create it
#

THis instructions are ignored
Any directory was created.
!exists( $$DESTDIR ) {
    message("Creating $$DESTDIR struct")
    mkpath( $$DESTDIR )
}
!exists( $$OBJECTS_DIR ) {
    message("Creating $$OBJECTS_DIR")
    mkpath( $$OBJECTS_DIR )
}
!exists( $$MOC_DIR ) {
    message("Creating $$MOC_DIR")
    mkpath( $$MOC_DIR )
}
!exists( $$RCC_DIR ) {
    message("Creating $$RCC_DIR")
    mkpath( $$RCC_DIR )
}
!exists( $$UI_DIR ) {
    message("Creating $$UI_DIR")
    mkpath( $$UI_DIR )
}
:><------- Cutting ------------

But this not work. Always qtcreator use a default directory struct configured in Tools->Options->Build and Run->Default build Directory.

Simple it's ignore this instructions ... Am I doing something wrong??

  • Ahh, yet another [XY problem](http://meta.stackexchange.com/q/66377/232821). Why do you think you need any of this? Why do you care what's inside the build directory? Most likely you're trying to refer to libraries or other targets built by subprojects and you're having problems there. Please explain how is your project structured, and what are the dependencies, and what exactly is the overarching problem you're trying to solve. See [e.g. this answer](http://stackoverflow.com/a/39150917/1329652) for a complete demonstration of a cross-platform dll+executable qmake project. – Kuba hasn't forgotten Monica Aug 29 '16 at 19:12

1 Answers1

0

This is an anti-pattern, and it generally won't work because no one using qmake projects expects them to behave that way: Qt Creator doesn't, other people don't, etc.

For any given project, you set the build directory by executing qmake in the build directory. E.g., supposed you have ~/src/myproject/myproject.pro that you wish to build:

mkdir -p ~/build/myproject
cd ~/build/myproject
qmake ~/src/myproject
gmake -j8

To build multiple projects in subfolders, you should have a top-level subdirs project that refers to them. E.g.

+--- myproject
    +--- myproject.pro
    +--- lib1
    |   +--- lib1.pro
    |   ...
    +--- lib2
    |   +--- lib2.pro
    |   ...
    +--- app1
    .   +--- app1.pro
    .   ...
    etc.

The source directory structure will be replicated in the build folder. You generally shouldn't otherwise care what goes where in the build folder, except when referencing to targets built by subprojects, e.g. if app1 depends on lib2 you will need to add the build product as a dependency. This answer shows exactly how to do that.

Community
  • 1
  • 1
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313