jpo38
jpo38

Reputation: 21514

How can I set -j mingw option in my QtCreator's .pro project file

I'm building a huge C++/Qt project for Android using QtCreator. I have scripts generating .pro files and I'd like to specify within the .pro file that I wish to have the build multi-threaded.

I know I can go to project options and add -j%NUMBER_OF_PROCESSORS% option to Make: enter image description here

However, as I want to have this option set to all our projects and for every developper, I'd like to have this option be set from the .pro file.

I tried:

Does anyone know how to set this option from .pro file?

Upvotes: 0

Views: 1030

Answers (3)

jpo38
jpo38

Reputation: 21514

Actually, he best is to recommend every developer that wants to spped-up compilation to set MAKEFLAGS environment variable. It can decide to set it to -j2 or -j4 or -j%NUMBER_OF_PROCESSORS% (if it wants a fast compilation even if it overloads the computer).

This is then used by make and applies to every project compiled with QtCreator. The fact that the option is used is absolutely not visible in QtCreator (nor in the options page, nor in the log), however, you can see in Windows task manager that several instances of g++ are ran in parallel.

Upvotes: 0

Emir Cesovic
Emir Cesovic

Reputation: 39

Project's build and run settings are saved in .pro.user file, AFAIK. You could modify .pro.user with your script, find a line that looks something like this: "< value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">[EMPTY, OR SOME OTHER MAKE ARGUMENTS]< /value>"(might be slightly different depending on version and platform) and change whatever is in the place of [EMPTY, OR SOME OTHER MAKE ARGUMENTS] with -j%NUMBER_OF_PROCESSORS%. However, you would need to preserve most of the other settings in .pro.user file for each particular user meaning that you would need your script to be run on each host, and in a case any of the users changes make arguments in Qt Creator's build settings. Please note that i'm not saying that it is a good idea modifying .pro.user manually, but it is a way of doing what you wanted.

Upvotes: 0

rubenvb
rubenvb

Reputation: 76519

There is no way for the simple reason that it doesn't belong in the project file. What if a developer on your team doesn't want to use all his cores because he's doing something else and he wants a bit more CPU juice at the same time? What if someone has 2 cores less than the number you chose? What if someone has more cores than the number you chose?

In short: don't. If you want optimal cpu core usage, use something like Ninja, which does so automatically, without the need of a specific number.

Note: Ninja won't work with qmake. Try CMake if it's at all possible. Even though the scripting language is terrible, it offers a lot of possibilities and flexibility in return.

Upvotes: 1

Related Questions