PDA

View Full Version : Tell QMake to add a literal string to the Makefile



gmat4321
14th December 2011, 14:39
I need to find a way to pass a string from QMake into the generated Makefile. I want to do this so I can control Parallel builds. I use Make from the command line, not QtCreator (don't ask why).

I have a top level project that I want to be not parallel. then have the the subdirs as parallel. I can easily do this now by using all the normal conventions for setting up the subdirs in the .pro file:


SUBDIRS = aproj bproj cproj

then after the make file is created I add the NOTPARALLEL: entry to it:


SUBTARGETS = \
aproj
bproj
cproj

NOTPARALLEL:

aproj/($MAKEFILE):
........


Thus the main project is serial and the subdirs build in parallel. The down side is that I have to add the NOTPARALLEL command each time I recreate the Makefile.

According to the gcc/make docs the NOTPARALLEL can be anywhere in the Makefile: "If .NOTPARALLEL is mentioned as a target, then this invocation of make will be run serially, even if the ‘-j’ option is given." So I just need to stuff it in someplace.

Any ideas?

ChrisW67
15th December 2011, 02:30
The example you have given us would serialise (i.e. .NOTPARALLEL) building of aproj, bproj, and cproj. (I have assumed the missing dots are typos)
If you are trying to ensure they build in a particular order then you should look at "CONFIG += ordered" in your PRO file.

ykozlov
24th October 2014, 20:52
I know this is an old thread but because it's one of the first things that came up on Google on this topic I wanted to provide an answer.

For SUBDIRS projects the given answer is partially correct. To prevent the subprojects building in parallel to each other at all, just use CONFIG+=ordered. To prevent only some subprojects from building in parallel, use "depends" like so:

bproj.depends = aproj
Still, sometimes you need to prevent a given subproject from building its files in parallel. For example, I have some template heavy code where compiling each file takes all the system memory. I want to make just that subproject build serially. This is where GNU Make's "NOTPARALLEL" is useful. This gets qmake to add it to the Makefile:

unix {
notparalleltarget.target = .NOTPARALLEL
QMAKE_EXTRA_TARGETS += notparalleltarget
}