(Apologies, I can't think of a better way of explaining except through including the following detail)
Pre-build structure:
F:\
└ Project\
└ Project.pro
└ ProjectSettings.pri
└ Source\
└ Source.pro
└ My_Library\
└ My_Library.pro
└ library.cpp
└ ...
Contents of "Project.pro":
TEMPLATE = subdirs
SUBDIRS = Source
Contents of "Source.pro":
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += My_Library
Contents of "My_Library.pro":
include(../../ProjectSettings.pri)
TEMPLATE = lib
SOURCES += library.cpp
Contents of "ProjectSettings.pri"
TARGET = $$basename(_PRO_FILE_PWD_)
Debug:buildDir = "Debug"
Release:buildDir = "Release"
DESTDIR = $$PWD/$$buildDir/bin
OBJECTS_DIR = $$PWD/$$buildDir/$$basename(_PRO_FILE_PWD_)/obj
MOC_DIR = $$PWD/$$buildDir/$$basename(_PRO_FILE_PWD_)/moc
RCC_DIR = $$PWD/$$buildDir/$$basename(_PRO_FILE_PWD_)/rcc
UI_DIR = $$PWD/$$buildDir/$$basename(_PRO_FILE_PWD_)/gui
Post-build structure:
F:\
└ Project\
└ Project.pro
└ ProjectSettings.pri
└ Source\
└ Source.pro
└ My_Library\
└ My_Library.pro
└ library.cpp
└ Debug\
└ bin\
└ libMy_Library.a
└ My_Library\
└ moc\
└ obj\
└ library.o
└ My_Library\ <------ WTF
└ moc\
└ Release\
└ bin\
└ libMy_Library.a
└ My_Library\
└ moc\
└ obj\
└ library.o
Problem
The idea is
qmake -recursive
in the Project folderIt seems to work brilliantly, except for an extra folder per 'sub-project' in the Project folder each of which contains a moc folder which I've highlighted "WTF"* above.
Questions
I don't have any source files that would cause the MOC to output moc files yet so all moc folders are empty at the moment.
* "WTF" = "What The Folder"
1. The folders are created before the Debug and Release scopes are run. qmake produces one primary make file (Makefile
) and if there is source to build: two child make files (Makefile.Debug
and Makefile.Release
). The scopes are set for the children, but not for the parent therefore qmake decides it must create the folders which don't exist.
2. It's not used for anything so far as I can tell.
3. By adding a buildDir definition that already exists (in this case Source
) qmake doesn't bother to make any extra interim folders. Furthermore, the scope test should be modified (see here and here for an explanation of why). This boils down to the following ProjectSettings.pri
:
PROJECT_NAME = $$basename(PWD)
TARGET = $$basename(_PRO_FILE_PWD_)
buildDir = Source
CONFIG( debug, debug|release ) {
buildDir = "Debug"
} else {
buildDir = "Release"
}
DESTDIR = $$PWD/$$buildDir/bin
OBJECTS_DIR = $$PWD/$$buildDir/$$basename(_PRO_FILE_PWD_)/obj
MOC_DIR = $$PWD/$$buildDir/$$basename(_PRO_FILE_PWD_)/moc
RCC_DIR = $$PWD/$$buildDir/$$basename(_PRO_FILE_PWD_)/rcc
UI_DIR = $$PWD/$$buildDir/$$basename(_PRO_FILE_PWD_)/gui
Not really sure why this works, but it seems to solve the problem.